-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ Feat: Add nx distributed cloud execution
- Loading branch information
Will Cory
authored and
Will Cory
committed
Nov 19, 2023
1 parent
17b6ccf
commit b5622aa
Showing
3 changed files
with
150 additions
and
7 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
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,149 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
env: | ||
NX_CLOUD_DISTRIBUTED_EXECUTION: true | ||
NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT: 3 | ||
NX_BRANCH: ${{ github.event.number || github.ref_name }} | ||
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
jobs: | ||
main: | ||
name: Nx Cloud - Main Job | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
name: Checkout [Pull Request] | ||
if: ${{ github.event_name == 'pull_request' }} | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
fetch-depth: 0 | ||
|
||
- uses: actions/checkout@v4 | ||
name: Checkout [Default Branch] | ||
if: ${{ github.event_name != 'pull_request' }} | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: ".nvmrc" | ||
registry-url: https://registry.npmjs.org | ||
|
||
- name: Set up Bun | ||
uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: 1.0.9 | ||
|
||
- uses: pnpm/action-setup@v2 | ||
name: Install pnpm | ||
with: | ||
version: 8.10.2 | ||
run_install: false | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Get pnpm store directory | ||
shell: bash | ||
run: | | ||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | ||
- uses: actions/cache@v3 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ env.STORE_PATH }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store- | ||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
shell: bash | ||
|
||
- name: Check out the default branch | ||
run: git branch --track main origin/main | ||
|
||
- name: Initialize the Nx Cloud distributed CI run and stop agents when the build tasks are done | ||
run: bunx nx-cloud start-ci-run --stop-agents-after=build | ||
|
||
- name: Run commands in parallel | ||
run: | | ||
pids=() | ||
# list of commands to be run on main has env flag NX_CLOUD_DISTRIBUTED_EXECUTION set to false | ||
NX_CLOUD_DISTRIBUTED_EXECUTION=false bunx nx-cloud record -- bunx concurrently 'pnpm i' 'bun lint' 'bun sort-package-json' & pids+=($!) | ||
# list of commands to be run on agents | ||
bunx nx affected -t generate:docs,build:types,typecheck,test:coverage,build:dist --parallel=3 & | ||
pids+=($!) | ||
# run all commands in parallel and bail if one of them fails | ||
for pid in ${pids[*]}; do | ||
if ! wait $pid; then | ||
exit 1 | ||
fi | ||
done | ||
exit 0 | ||
agents: | ||
name: Agent ${{ matrix.agent }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
# Add more agents here as your repository expands | ||
agent: [1, 2, 3] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: ".nvmrc" | ||
registry-url: https://registry.npmjs.org | ||
|
||
- name: Set up Bun | ||
uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: 1.0.9 | ||
|
||
- uses: pnpm/action-setup@v2 | ||
name: Install pnpm | ||
with: | ||
version: 8.10.2 | ||
run_install: false | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Get pnpm store directory | ||
shell: bash | ||
run: | | ||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | ||
- uses: actions/cache@v3 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ env.STORE_PATH }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store- | ||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
shell: bash | ||
|
||
- name: Start Nx Agent ${{ matrix.agent }} | ||
run: bunx nx-cloud start-agent | ||
env: | ||
NX_AGENT_NAME: ${{ matrix.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