-
-
Notifications
You must be signed in to change notification settings - Fork 208
246 lines (202 loc) · 10.4 KB
/
ci.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main, 'next-major-release/**']
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true
env:
NX_CLOUD_DISTRIBUTED_EXECUTION: true
NX_VERBOSE_LOGGING: false
jobs:
create_nx_run_group:
name: Create NX_RUN_GROUP
runs-on: ubuntu-latest
outputs:
nx_run_group: ${{ steps.set_nx_run_group.outputs.nx_run_group }}
steps:
- name: Set NX_RUN_GROUP based on $GITHUB_RUN_ID and a uuid
id: set_nx_run_group
run: |
NX_RUN_GROUP="$GITHUB_RUN_ID--$(uuidgen)"
echo "::set-output name=nx_run_group::$NX_RUN_GROUP"
primary:
name: Primary
needs: [create_nx_run_group]
runs-on: ubuntu-latest
steps:
- name: Set NX_RUN_GROUP based on the output of the create_nx_run_group job
run: echo "NX_RUN_GROUP=${{ needs.create_nx_run_group.outputs.nx_run_group }}" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v3
- name: Install node and npm based on the volta config in our package.json
uses: volta-cli/action@v3
- name: Get yarn cache directory path and node version for cache key and NX_CLOUD_ENV_NAME
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn cache dir)"
echo "::set-output name=node_version::$(node --version)"
# Added the - at the end to function as a separator to improve readability in the PR comment from the Nx cloud app
echo "NX_CLOUD_ENV_NAME=Node $(node --version) -" >> $GITHUB_ENV
- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-
- name: Install dependencies (skipping postinstall)
# We use --ignore-scripts to skip automatic postinstall and give us more control over distributing build tasks
run: |
yarn --ignore-engines --frozen-lockfile --prefer-offline --ignore-scripts
yarn check-clean-workspace-after-install
- name: Check code formatting (not distributable)
run: NX_CLOUD_DISTRIBUTED_EXECUTION=false yarn format-check
- name: Run parallel distributed tasks for build, typecheck, check-rule-docs, lint and test targets
uses: jameshenry/parallel-bash-commands@v1
with:
# Note that the typecheck target *also* typechecks tests and tools,
# whereas the build only checks src files
cmd1: yarn typecheck
cmd2: yarn build
cmd3: yarn check-rule-docs
cmd4: yarn lint
cmd5: yarn test --codeCoverage
- name: Run distributed integration tests with independent local registries
run: npx nx run-many --target=integration-test --all --withRegistry
- name: Publish code coverage report
uses: codecov/codecov-action@v3
with:
files: coverage/packages/**/lcov.info
flags: unittest
name: codecov
- 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: Nx Distributed CI Agents
needs: [create_nx_run_group]
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
matrix:
agent: [1, 2, 3, 4, 5, 6]
steps:
- name: Set NX_RUN_GROUP based on the output of the create_nx_run_group job
run: echo "NX_RUN_GROUP=${{ needs.create_nx_run_group.outputs.nx_run_group }}" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Install node and npm based on the volta config in our package.json
uses: volta-cli/action@v3
- name: Get yarn cache directory path and node version for cache key
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn cache dir)"
echo "::set-output name=node_version::$(node --version)"
- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-
- name: Install dependencies (skipping postinstall)
# We use --ignore-scripts to skip automatic postinstall and give us more control to distribute tasks
run: yarn --ignore-engines --frozen-lockfile --prefer-offline --ignore-scripts
- name: Start Nx Agent ${{ matrix.agent }}
run: npx nx-cloud start-agent
unit_tests_on_other_node_versions:
name: Unit tests on other supported Node versions
needs: [create_nx_run_group]
runs-on: ubuntu-latest
strategy:
matrix:
# Additionally supported node versions taken from:
# https://gist.github.com/LayZeeDK/c822cc812f75bb07b7c55d07ba2719b3
node: ['^14.15.5']
steps:
- name: Set NX_RUN_GROUP based on the output of the create_nx_run_group job
run: echo "NX_RUN_GROUP=${{ needs.create_nx_run_group.outputs.nx_run_group }}" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v3
- uses: volta-cli/action@v3
with:
# The Node.js version to configure
node-version: ${{ matrix.node }}
- name: Get yarn cache directory path and node version for cache key and NX_CLOUD_ENV_NAME
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn cache dir)"
echo "::set-output name=node_version::$(node --version)"
# Added the - at the end to function as a separator to improve readability in the PR comment from the Nx cloud app
# NOTE: We are intentionally not using matrix.node here because that does not contain the full semver value
echo "NX_CLOUD_ENV_NAME=Node $(node --version) -" >> $GITHUB_ENV
- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-
- name: Install dependencies (skipping postinstall)
# We use --ignore-scripts to skip automatic postinstall and give us more control to distribute tasks
run: yarn --ignore-engines --frozen-lockfile --prefer-offline --ignore-scripts
- name: Run build targets on Node ${{ matrix.node }} (not distributable)
env:
# We cannot distribute these because the agents are set up to run the primary node version, not this alternative we are testing
NX_CLOUD_DISTRIBUTED_EXECUTION: false
run: yarn build
- name: Run test targets on Node ${{ matrix.node }} (not distributable)
env:
# We cannot distribute these because the agents are set up to run the primary node version, not this alternative we are testing
NX_CLOUD_DISTRIBUTED_EXECUTION: false
run: yarn test
publish_canary_version:
name: Publish the latest code as a canary version
runs-on: ubuntu-latest
needs: [create_nx_run_group, primary, unit_tests_on_other_node_versions]
if: github.ref == 'refs/heads/main'
steps:
- name: Set NX_RUN_GROUP based on the output of the create_nx_run_group job
run: echo "NX_RUN_GROUP=${{ needs.create_nx_run_group.outputs.nx_run_group }}" >> $GITHUB_ENV
- uses: actions/checkout@v3
# Fetch all history for all tags and branches in this job because lerna needs it
- run: git fetch --prune --unshallow
- name: Install node and npm based on the volta config in our package.json
uses: volta-cli/action@v3
- name: Get yarn cache directory path and node version for cache key
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn cache dir)"
echo "::set-output name=node_version::$(node --version)"
- name: Apply version resolved by volta to standard Node action make authenticated npm publish easier
uses: actions/setup-node@v3
with:
node-version: ${{ steps.yarn-cache-dir-path.outputs.node_version }}
registry-url: https://registry.npmjs.org/
- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-
- name: Install dependencies (skipping postinstall)
# We use --ignore-scripts to skip automatic postinstall and give us more control to distribute tasks
run: yarn --ignore-engines --frozen-lockfile --prefer-offline --ignore-scripts
- name: Run build ahead of publishing
# We cannot distribute this because the agents have already been stopped by this point
# but it should not matter because this should be a full cloud cache hit
run: NX_CLOUD_DISTRIBUTED_EXECUTION=false yarn build
- name: Publish all packages to npm
run: npx lerna publish --loglevel=verbose --canary --exact --force-publish --yes
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}