-
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (99 loc) · 3.77 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: CI
on:
push:
branches:
- main
pull_request:
env:
NX_CLOUD_DISTRIBUTED_EXECUTION: true # this enables DTE
NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT: 3 # expected number of agents
NX_BRANCH: ${{ github.event.number || github.ref_name }}
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # this is needed if our pipeline publishes to npm
jobs:
main:
name: Nx Cloud - Main Job
runs-on: ubuntu-latest
environment:
name: Development
steps:
- uses: actions/checkout@v3
name: Checkout [Pull Request]
if: ${{ github.event_name == 'pull_request' }}
with:
# By default, PRs will be checked-out based on the Merge Commit, but we want the actual branch HEAD.
ref: ${{ github.event.pull_request.head.sha }}
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
fetch-depth: 0
- uses: actions/checkout@v3
name: Checkout [Default Branch]
if: ${{ github.event_name != 'pull_request' }}
with:
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
fetch-depth: 0
# Set node/npm/yarn versions using volta
- uses: volta-cli/action@v4
with:
package-json-path: '${{ github.workspace }}/package.json'
- name: Use the package manager cache if available
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-
- name: Install dependencies
run: npm ci
- name: Initialize the Nx Cloud distributed CI run
run: npx nx-cloud start-ci-run
- 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 npx nx-cloud record -- npx nx format:check & pids+=($!)
# list of commands to be run on agents
npx nx affected -t lint --parallel=3 &
pids+=($!)
npx nx affected -t test --parallel=3 &
pids+=($!)
npx nx affected -t build --parallel=3 --name="${{vars.NAME}}" --devtool="${{vars.DEV_TOOL}}" --variant="${{vars.VARIANT}}" --oauth="${{secrets.OAUTH_CLIENT_ID}}" &
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
- name: Stop all running agents for this CI run
# It's important that we always run this step, otherwise in the case of any failures in preceding non-Nx steps, the agents will keep running and waste billable minutes
if: ${{ always() }}
run: npx nx-cloud stop-all-agents
agents:
name: Agent ${{ matrix.agent }}
runs-on: ubuntu-latest
environment:
name: Development
strategy:
matrix:
agent: [1, 2, 3]
steps:
- name: Checkout
uses: actions/checkout@v3
# Set node/npm/yarn versions using volta
- uses: volta-cli/action@v4
with:
package-json-path: '${{ github.workspace }}/package.json'
- name: Use the package manager cache if available
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-
- name: Install dependencies
run: npm ci
- name: Start Nx Agent ${{ matrix.agent }}
run: npx nx-cloud start-agent
env:
NX_AGENT_NAME: ${{ matrix.agent }}