GitHub Action: Run Many
Relevant source files
The following files were used as context for generating this wiki page:
GitHub Action: Run Many executes multiple Nx targets across a workspace based on project tags. You use this action to manage complex CI/CD workflows, specifically for deploying specific projects or disabling those not ready for production. It works in conjunction with GitHub Action: Plan to facilitate distributed task execution.
Sources: actions/run-many/README.md:1-5, actions/run-many/CHANGELOG.md:82-90
Architecture and Workflow
The action functions by wrapping the standard npx nx run-many command. It takes a list of projects and a target, then constructs a command line with appropriate flags for parallelization, configuration, and output styling.
Execution Logic
The system follows a specific flow to ensure all dependencies and primary tasks run correctly.
The action identifies relevant projects and executes them in sequence: pre-targets, main target, and post-targets.
Sources: actions/run-many/src/utils/run-target.ts:13-75, actions/run-many/CHANGELOG.md:92-94
Core Execution Logic (runTarget)
The runTarget function handles the construction and execution of the Nx command. It automatically adjusts flags based on the target type.
- Build Target: If no configuration is provided, the action appends the
--prodflag. - Deploy Target: If no parallel limit is set, it defaults to
--parallel=2. - Test Target: If no parallel limit is set, it defaults to
--parallel=4. - Output Style: Commands log using
--output-style=streamto ensure better readability in GitHub Action logs.
Sources: actions/run-many/src/utils/run-target.ts:39-60, actions/run-many/CHANGELOG.md:82-83
Command Construction
The action assembles the following command parts:
npx nx run-many--target=[target]--projects=[comma-separated list]--configuration=[config](optional)--verbose(if debug mode or verbose flag is active)- Additional arguments from
getRestArgs()
Sources: actions/run-many/src/utils/run-target.ts:28-37
GitHub Job Summary Generation
After target execution, the action generates a visual summary for the GitHub UI. It parses the command output to identify failed tasks and creates a table.
The summary generation process identifies failed projects by scanning for the "Failed tasks" indicator in the Nx output.
Sources: actions/run-many/src/utils/generate-summary.ts:4-37
Summary Features
- Status Emojis: Uses
:x:for failed projects and:white_check_mark:for successful projects. - Project List: Tables provide a clear mapping of which project in the matrix failed or succeeded.
Sources: actions/run-many/src/utils/generate-summary.ts:25-30
Configuration Options
The action relies on several inputs, often provided via a matrix from a preceding plan step.
| Input | Type | Description |
|---|---|---|
target | string | The Nx target to execute (e.g., build, test, deploy). |
index | number | The current job index for distributed runs. |
count | number | Total number of jobs in the distribution. |
tag | string | Project tags to filter by. |
parallel | string | Maximum number of parallel processes. |
preTargets | string | Targets to run before the main target. |
postTargets | string | Targets to run after the main target. |
configuration | string | Specific Nx configuration to use. |
Sources: actions/run-many/README.md:54-61, actions/run-many/src/utils/run-target.ts:18-24
Implementation Details
The action is compiled using @vercel/ncc into a single distribution file.
- Package Name:
@nx-extend/actions-run-many - Entry Point:
dist/index.js - Binary:
nx-run-many - Runtime: Node 20 (as of version 3.5.0)
Sources: actions/run-many/package.json:2-15, actions/run-many/project.json:8-12, actions/run-many/CHANGELOG.md:47-49
GitHub Action: Run Many provides a robust mechanism for executing Nx tasks in a distributed CI environment. By automating parallelization defaults and providing visual summaries, it reduces the complexity of managing large monorepo pipelines.