Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions .github/workflows/nx-distributed-tasks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Nx Distributed Tasks

on: push
on:
push:
branches:
- master
pull_request:

env:
BUILD_ARTIFACTS: dist-artifacts
Expand All @@ -11,6 +15,17 @@ env:

jobs:

vars:
runs-on: ubuntu-latest
outputs:
GITHUB_HEAD_REF: ${{ steps.GITHUB_HEAD_REF.outputs.value }}
GITHUB_BASE_REF: ${{ steps.GITHUB_BASE_REF.outputs.value }}
steps:
- id: GITHUB_HEAD_REF
run: echo "::set-output name=value::$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}})"
- id: GITHUB_BASE_REF
run: echo "::set-output name=value::$(echo ${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}})"

install-deps:
runs-on: ubuntu-latest
steps:
Expand All @@ -27,21 +42,23 @@ jobs:

format:
runs-on: ubuntu-latest
needs: install-deps
needs: [vars, install-deps]
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ env.DEPENDENCIES_CACHE }}-${{ hashFiles('yarn.lock') }}
- run: git fetch --no-tags --prune --depth=5 origin master
- run: echo "GITHUB_BASE_SHA=$([[ "$GITHUB_REF" == "refs/origin/master" ]] && echo "origin/master~1" || echo "origin/master")" >> $GITHUB_ENV
- run: node --max-old-space-size=8000 ./node_modules/@nrwl/cli/bin/nx.js format:check --base=$GITHUB_BASE_SHA
- run: git fetch --no-tags --prune origin ${{ needs.vars.outputs.GITHUB_BASE_REF }} ${{ needs.vars.outputs.GITHUB_HEAD_REF }}
- name: Compute Nx arguments
run: echo "NX_ARGUMENTS=--base=origin/${{ needs.vars.outputs.GITHUB_BASE_REF }}" >> $GITHUB_ENV
if: needs.vars.outputs.GITHUB_HEAD_REF != needs.vars.outputs.GITHUB_BASE_REF
- run: node --max-old-space-size=8000 ./node_modules/@nrwl/cli/bin/nx.js format:check $NX_ARGUMENTS

distributed-task:
runs-on: ubuntu-latest
needs: install-deps
needs: [vars, install-deps]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -71,18 +88,18 @@ jobs:
with:
path: ${{ env.CYPRESS_CACHE_FOLDER }}
key: ${{ env.CYPRESS_CACHE }}
- run: git fetch --no-tags --prune --depth=5 origin master
- run: git fetch --no-tags --prune origin ${{ needs.vars.outputs.GITHUB_BASE_REF }} ${{ needs.vars.outputs.GITHUB_HEAD_REF }}
- name: Compute Nx arguments
if: matrix.target == 'build' || matrix.target == 'e2e'
run: echo "NX_ARGUMENTS=--prod" >> $GITHUB_ENV
- name: nx run-many:${{ matrix.target }}
if: matrix.target != 'e2e'
run: node ./tools/scripts/run-many.js ${{ matrix.target }} ${{ matrix.index }} ${{ env.count }} $GITHUB_REF $NX_ARGUMENTS
run: node ./tools/scripts/run-many.js ${{ matrix.target }} ${{ matrix.index }} ${{ env.count }} ${{ needs.vars.outputs.GITHUB_HEAD_REF }} ${{ needs.vars.outputs.GITHUB_BASE_REF }} $NX_ARGUMENTS
- name: nx run-many:e2e
if: matrix.target == 'e2e'
uses: cypress-io/github-action@v2
with:
command: node ./tools/scripts/run-many.js ${{ matrix.target }} ${{ matrix.index }} ${{ env.count }} $GITHUB_REF $NX_ARGUMENTS
command: node ./tools/scripts/run-many.js ${{ matrix.target }} ${{ matrix.index }} ${{ env.count }} ${{ needs.vars.outputs.GITHUB_HEAD_REF }} ${{ needs.vars.outputs.GITHUB_BASE_REF }} $NX_ARGUMENTS
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
Expand Down
10 changes: 7 additions & 3 deletions tools/scripts/run-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ const execSync = require('child_process').execSync;
const target = process.argv[2];
const jobIndex = Number(process.argv[3]);
const jobCount = Number(process.argv[4]);
const isMaster = process.argv[5] === 'refs/heads/master';
const baseSha = isMaster ? 'origin/master~1' : 'origin/master';
const headRef = process.argv[5];
const baseRef = process.argv[6];
const nxArgs =
headRef !== baseRef
? ` --head=origin/${headRef} --base=origin/${baseRef}`
: '--all';

const affected = execSync(
`npx nx print-affected --base=${baseSha} --target=${target}`
`npx nx print-affected --target=${target} ${nxArgs}`
).toString('utf-8');
const array = JSON.parse(affected)
.tasks.map((t) => t.target.project)
Expand Down