-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
161 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: 'Run Commands in Parallel' | ||
description: "Based on https://github.com/nrwl/ci" | ||
|
||
inputs: | ||
parallel-commands: | ||
required: false | ||
type: string | ||
parallel-commands-on-agents: | ||
required: false | ||
type: string | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
# An unfortunate side-effect of the way reusable workflows work is that by the time they are pulled into the "caller" | ||
# repo, they are effectively completely embedded in that context. This means that we cannot reference any files which | ||
# are local to this repo which defines the workflow, and we therefore need to work around this by embedding the contents | ||
# of the shell utilities for executing commands into the workflow directly. | ||
- name: Create command utils | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const { writeFileSync } = require('fs'); | ||
const runCommandsInParallelScript = ` | ||
# Extract the provided commands from the stringified JSON array. | ||
IFS=$'\n' read -d '' -a userCommands < <((jq -c -r '.[]') <<<"$1") | ||
# Invoke the provided commands in parallel and collect their exit codes. | ||
pids=() | ||
for userCommand in "\${userCommands[@]}"; do | ||
eval "$userCommand" & pids+=($!) | ||
done | ||
# If any one of the invoked commands exited with a non-zero exit code, exit the whole thing with code 1. | ||
for pid in \${pids[*]}; do | ||
if ! wait $pid; then | ||
exit 1 | ||
fi | ||
done | ||
# All the invoked commands must have exited with code zero. | ||
exit 0 | ||
`; | ||
writeFileSync('./.github/workflows/run-commands-in-parallel.sh', runCommandsInParallelScript); | ||
- name: Prepare command utils | ||
shell: bash | ||
# We need to escape the workspace path to be consistent cross-platform: https://github.com/actions/runner/issues/1066 | ||
run: chmod +x ${GITHUB_WORKSPACE//\\//}/.github/workflows/run-commands-in-parallel.sh | ||
|
||
- name: Process parallel commands configuration | ||
uses: actions/github-script@v6 | ||
id: parallel_commands_config | ||
env: | ||
PARALLEL_COMMANDS: ${{ inputs.parallel-commands }} | ||
PARALLEL_COMMANDS_ON_AGENTS: ${{ inputs.parallel-commands-on-agents }} | ||
with: | ||
# For the ones configured for main, explicitly set NX_CLOUD_DISTRIBUTED_EXECUTION to false, taking into account commands chained with && | ||
# within the strings. In order to properly escape single quotes we need to do some manual replacing and escaping so that the commands | ||
# are forwarded onto the run-commands-in-parallel.sh script appropriately. | ||
script: | | ||
const parallelCommandsOnMainStr = process.env.PARALLEL_COMMANDS || ''; | ||
const parallelCommandsOnAgentsStr = process.env.PARALLEL_COMMANDS_ON_AGENTS || ''; | ||
const parallelCommandsOnMain = parallelCommandsOnMainStr | ||
.split('\n') | ||
.map(command => command.trim()) | ||
.filter(command => command.length > 0) | ||
.map(s => s.replace(/'/g, '%27')); | ||
const parallelCommandsOnAgents = parallelCommandsOnAgentsStr | ||
.split('\n') | ||
.map(command => command.trim()) | ||
.filter(command => command.length > 0) | ||
.map(s => s.replace(/'/g, '%27')); | ||
const formattedArrayOfCommands = [ | ||
...parallelCommandsOnMain.map(s => s | ||
.split(' && ') | ||
.map(s => `NX_CLOUD_DISTRIBUTED_EXECUTION=false ${s}`) | ||
.join(' && ') | ||
), | ||
...parallelCommandsOnAgents, | ||
]; | ||
const stringifiedEncodedArrayOfCommands = JSON.stringify(formattedArrayOfCommands) | ||
.replace(/%27/g, "'\\''"); | ||
return stringifiedEncodedArrayOfCommands | ||
result-encoding: string | ||
|
||
- name: Run any configured parallel commands on main and agent jobs | ||
shell: bash | ||
# We need to escape the workspace path to be consistent cross-platform: https://github.com/actions/runner/issues/1066 | ||
run: ${GITHUB_WORKSPACE//\\//}/.github/workflows/run-commands-in-parallel.sh '${{ steps.parallel_commands_config.outputs.result }}' | ||
env: | ||
NX_CLOUD_DISTRIBUTED_EXECUTION: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: 'Setup' | ||
description: 'Run basic setup' | ||
|
||
inputs: | ||
affected: | ||
required: false | ||
default: false | ||
type: boolean | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Cache Dependencies | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
node_modules | ||
tools/src/**/*.js | ||
key: dependencies-${{ runner.os }}-${{ hashFiles('yarn.lock', 'tools/src/**/*.ts') }} | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: '.nvmrc' | ||
- name: Install | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
shell: bash | ||
run: yarn | ||
- name: Derive appropriate SHAs for base and head for `nx affected` commands | ||
if: ${{ inputs.affected == 'true' }} | ||
uses: nrwl/nx-set-shas@v3 | ||
with: | ||
main-branch-name: 'master' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,45 @@ | ||
name: Check | ||
on: | ||
pull_request: | ||
env: | ||
NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT: 4 | ||
NX_CLOUD_DISTRIBUTED_EXECUTION: false | ||
|
||
jobs: | ||
install: | ||
name: Install Dependencies | ||
controller: | ||
name: Controller | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Cache Dependencies | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
node_modules | ||
tools/src/**/*.js | ||
key: dependencies-${{ runner.os }}-${{ hashFiles('yarn.lock', 'tools/src/**/*.ts') }} | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: '.nvmrc' | ||
- name: Execute | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: yarn | ||
- name: Set Variables | ||
id: variables | ||
run: yarn script set-pr-variables | ||
- name: Set e2e | ||
id: set-e2e | ||
run: yarn script set-affected --target e2e --base ${{ steps.variables.outputs.base }} | ||
- name: Set lint | ||
id: set-lint | ||
run: yarn script set-affected --target lint --base ${{ steps.variables.outputs.base }} | ||
- name: Set test | ||
id: set-test | ||
run: yarn script set-affected --target test --base ${{ steps.variables.outputs.base }} | ||
outputs: | ||
e2e-array: ${{ steps.set-e2e.outputs.array }} | ||
lint-comma: ${{ steps.set-lint.outputs.comma-separated }} | ||
test-comma: ${{ steps.set-test.outputs.comma-separated }} | ||
- name: Setup | ||
uses: ./.github/actions/setup | ||
with: | ||
affected: true | ||
- run: npx nx-cloud start-ci-run | ||
- name: Run Commands | ||
uses: ./.github/actions/run-commands-in-parallel | ||
with: | ||
parallel-commands-on-agents: | | ||
npx nx affected --target=e2e --parallel=1 | ||
npx nx affected --target=lint --parallel=3 --silent | ||
npx nx affected --target=test --parallel=3 --quiet | ||
- run: npx nx-cloud stop-all-agents | ||
if: ${{ always() }} | ||
|
||
lint: | ||
name: Lint | ||
needs: install | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: '.nvmrc' | ||
- name: Load Dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
node_modules | ||
tools/src/**/*.js | ||
key: dependencies-${{ runner.os }}-${{ hashFiles('yarn.lock', 'tools/src/**/*.ts') }} | ||
- name: Execute | ||
if: ${{ needs.install.outputs.lint-comma }} | ||
run: npm run nx -- run-many --projects ${{ needs.install.outputs.lint-comma }} --target lint --parallel -- --quiet | ||
|
||
test: | ||
name: Test | ||
needs: install | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: '.nvmrc' | ||
- name: Load Dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
node_modules | ||
tools/src/**/*.js | ||
key: dependencies-${{ runner.os }}-${{ hashFiles('yarn.lock', 'tools/src/**/*.ts') }} | ||
- name: Execute | ||
if: ${{ needs.install.outputs.test-comma }} | ||
run: yarn nx run-many --projects ${{ needs.install.outputs.test-comma }} --target test --parallel | ||
|
||
e2e: | ||
name: E2E | ||
needs: [install] | ||
agents: | ||
name: Agent | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 60 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
project: ${{ fromJson(needs.install.outputs.e2e-array) }} | ||
agent: [1, 2, 3, 4] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: '.nvmrc' | ||
- name: Load Dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
node_modules | ||
tools/src/**/*.js | ||
key: dependencies-${{ runner.os }}-${{ hashFiles('yarn.lock', 'tools/src/**/*.ts') }} | ||
- name: Execute | ||
run: yarn nx run ${{ matrix.project }}:e2e | ||
|
||
e2e-done: | ||
name: E2E | ||
needs: [install, e2e] | ||
if: ${{ always() }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check status | ||
if: ${{ needs.e2e.result != 'success' && !contains(needs.install.outputs.e2e-array, '[]') }} | ||
run: exit 1 | ||
- name: Setup | ||
uses: ./.github/actions/setup | ||
- name: Start Nx Agent ${{ matrix.agent }} | ||
run: npx nx-cloud start-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters