Skip to content

Commit bf45cbf

Browse files
committed
ci: Better affected check
Also enabled global yarn cache, and streamlines some jobs to avoid unnecessary cache restoration.
1 parent 988d8e7 commit bf45cbf

File tree

2 files changed

+65
-137
lines changed

2 files changed

+65
-137
lines changed

.github/workflows/build.yml

Lines changed: 63 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
# We need to check out not only the fake merge commit between the PR and the base branch which GH creates, but
7575
# also its parents, so that we can pull the commit message from the head commit of the PR
7676
fetch-depth: 2
77+
7778
- name: Get metadata
7879
id: get_metadata
7980
# We need to try a number of different options for finding the head commit, because each kind of trigger event
@@ -83,101 +84,28 @@ jobs:
8384
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV
8485
echo "COMMIT_MESSAGE=$(git log -n 1 --pretty=format:%s $COMMIT_SHA)" >> $GITHUB_ENV
8586
87+
# Most changed packages are determined in job_build via Nx
88+
# However, for profiling-node we only want to run certain things when in this specific package
89+
# something changed, not in any of the dependencies (which include core, utils, ...)
8690
- name: Determine changed packages
8791
uses: dorny/[email protected]
8892
id: changed
8993
with:
9094
filters: |
91-
workflow: &workflow
92-
- '.github/**'
93-
shared: &shared
94-
- *workflow
95-
- '*.{js,ts,json,yml,lock}'
96-
- 'CHANGELOG.md'
97-
- 'jest/**'
98-
- 'scripts/**'
99-
- 'packages/core/**'
100-
- 'packages/rollup-utils/**'
101-
- 'packages/utils/**'
102-
- 'packages/types/**'
103-
- 'dev-packages/test-utils/**'
104-
browser: &browser
105-
- *shared
106-
- 'packages/browser/**'
107-
- 'packages/browser-utils/**'
108-
- 'packages/replay-internal/**'
109-
- 'packages/replay-worker/**'
110-
- 'packages/replay-canvas/**'
111-
- 'packages/feedback/**'
112-
- 'packages/wasm/**'
113-
node: &node
114-
- *shared
115-
- 'packages/node/**'
116-
- 'packages/opentelemetry/**'
117-
browser_integration:
118-
- *shared
119-
- *browser
120-
- 'dev-packages/browser-integration-tests/**'
121-
ember:
122-
- *shared
123-
- *browser
124-
- 'packages/ember/**'
125-
node_integration:
126-
- *shared
127-
- *node
128-
- 'dev-packages/node-integration-tests/**'
129-
- 'packages/nestjs/**'
130-
nextjs:
131-
- *shared
132-
- *browser
133-
- *node
134-
- 'packages/nextjs/**'
135-
- 'packages/react/**'
136-
- 'packages/vercel-edge/**'
137-
remix:
138-
- *shared
139-
- *browser
140-
- *node
141-
- 'packages/remix/**'
142-
- 'packages/react/**'
14395
profiling_node:
144-
- *shared
145-
- 'packages/node/**'
146-
- 'packages/profiling-node/**'
147-
- 'dev-packages/e2e-tests/test-applications/node-profiling/**'
148-
profiling_node_bindings:
14996
- 'packages/profiling-node/**'
15097
- 'dev-packages/e2e-tests/test-applications/node-profiling/**'
151-
deno:
152-
- *shared
153-
- 'packages/deno/**'
154-
bun:
155-
- *shared
156-
- 'packages/bun/**'
157-
any_code:
158-
- '!**/*.md'
15998
16099
- name: Get PR labels
161100
id: pr-labels
162101
uses: mydea/pr-labels-action@fn/bump-node20
163102

164103
outputs:
165104
commit_label: '${{ env.COMMIT_SHA }}: ${{ env.COMMIT_MESSAGE }}'
166-
changed_nextjs: ${{ steps.changed.outputs.nextjs }}
167-
changed_ember: ${{ steps.changed.outputs.ember }}
168-
changed_remix: ${{ steps.changed.outputs.remix }}
169-
changed_node: ${{ steps.changed.outputs.node }}
170-
changed_node_integration: ${{ steps.changed.outputs.node_integration }}
171-
changed_profiling_node: ${{ steps.changed.outputs.profiling_node }}
172-
changed_profiling_node_bindings: ${{ steps.changed.outputs.profiling_node_bindings }}
173-
changed_deno: ${{ steps.changed.outputs.deno }}
174-
changed_bun: ${{ steps.changed.outputs.bun }}
175-
changed_browser: ${{ steps.changed.outputs.browser }}
176-
changed_browser_integration: ${{ steps.changed.outputs.browser_integration }}
177-
changed_any_code: ${{ steps.changed.outputs.any_code }}
178105
# Note: These next three have to be checked as strings ('true'/'false')!
179106
is_develop: ${{ github.ref == 'refs/heads/develop' }}
180107
is_release: ${{ startsWith(github.ref, 'refs/heads/release/') }}
108+
changed_profiling_node: ${{ steps.changed.outputs.profiling_node == 'true' }}
181109
# When merging into master, or from master
182110
is_gitflow_sync: ${{ github.head_ref == 'master' || github.ref == 'refs/heads/master' }}
183111
has_gitflow_label:
@@ -186,22 +114,31 @@ jobs:
186114
${{ github.event_name == 'schedule' || (github.event_name == 'pull_request' &&
187115
contains(steps.pr-labels.outputs.labels, ' ci-skip-cache ')) }}
188116

189-
job_install_deps:
190-
name: Install Dependencies
117+
job_build:
118+
name: Build
191119
needs: job_get_metadata
192120
runs-on: ubuntu-20.04
193121
timeout-minutes: 15
194122
if: |
195123
(needs.job_get_metadata.outputs.is_gitflow_sync == 'false' && needs.job_get_metadata.outputs.has_gitflow_label == 'false')
196124
steps:
125+
- name: Check out base commit (${{ github.event.pull_request.base.sha }})
126+
uses: actions/checkout@v4
127+
if: github.event_name == 'pull_request'
128+
with:
129+
ref: ${{ github.event.pull_request.base.sha }}
130+
197131
- name: 'Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})'
198132
uses: actions/checkout@v4
199133
with:
200134
ref: ${{ env.HEAD_COMMIT }}
135+
201136
- name: Set up Node
202137
uses: actions/setup-node@v4
203138
with:
204139
node-version-file: 'package.json'
140+
cache: 'yarn'
141+
205142
# we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
206143
# so no need to reinstall them
207144
- name: Compute dependency cache key
@@ -218,46 +155,14 @@ jobs:
218155
- name: Install dependencies
219156
if: steps.cache_dependencies.outputs.cache-hit != 'true'
220157
run: yarn install --ignore-engines --frozen-lockfile
221-
outputs:
222-
dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
223158

224-
job_check_branches:
225-
name: Check PR branches
226-
needs: job_get_metadata
227-
runs-on: ubuntu-20.04
228-
if: github.event_name == 'pull_request'
229-
permissions:
230-
pull-requests: write
231-
steps:
232-
- name: PR is opened against master
233-
uses: mshick/add-pr-comment@dd126dd8c253650d181ad9538d8b4fa218fc31e8
234-
if: ${{ github.base_ref == 'master' && !startsWith(github.head_ref, 'prepare-release/') }}
235-
with:
236-
message: |
237-
⚠️ This PR is opened against **master**. You probably want to open it against **develop**.
238-
239-
job_build:
240-
name: Build
241-
needs: [job_get_metadata, job_install_deps]
242-
runs-on: ubuntu-20.04-large-js
243-
timeout-minutes: 30
244-
if: |
245-
(needs.job_get_metadata.outputs.changed_any_code == 'true' || github.event_name != 'pull_request')
246-
steps:
247-
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
248-
uses: actions/checkout@v4
249-
with:
250-
ref: ${{ env.HEAD_COMMIT }}
251-
- name: Set up Node
252-
uses: actions/setup-node@v4
253-
with:
254-
node-version-file: 'package.json'
255-
- name: Check dependency cache
256-
uses: actions/cache/restore@v4
159+
- name: Check for Affected Nx Projects
160+
uses: dkhunt27/[email protected]
161+
id: checkForAffected
162+
if: github.event_name == 'pull_request'
257163
with:
258-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
259-
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
260-
fail-on-cache-miss: true
164+
base: ${{ github.event.pull_request.base.sha }}
165+
head: ${{ env.HEAD_COMMIT }}
261166

262167
- name: Check build cache
263168
uses: actions/cache@v4
@@ -286,10 +191,31 @@ jobs:
286191
env:
287192
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
288193
run: yarn build
194+
289195
outputs:
290-
# this needs to be passed on, because the `needs` context only looks at direct ancestors (so steps which depend on
291-
# `job_build` can't see `job_install_deps` and what it returned)
292-
dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
196+
dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
197+
changed_node_integration: ${{ contains(steps.checkForAffected.outputs.affected, '@sentry-internal/node-integration-tests') }}
198+
changed_remix: ${{ contains(steps.checkForAffected.outputs.affected, '@sentry/remix') }}
199+
changed_node: ${{ contains(steps.checkForAffected.outputs.affected, '@sentry/node') }}
200+
changed_deno: ${{ contains(steps.checkForAffected.outputs.affected, '@sentry/deno') }}
201+
changed_bun: ${{ contains(steps.checkForAffected.outputs.affected, '@sentry/bun') }}
202+
changed_browser_integration: ${{ contains(steps.checkForAffected.outputs.affected, '@sentry-internal/browser-integration-tests') }}
203+
# If you are looking for changed_profiling_node, this is defined in job_get_metadata
204+
205+
job_check_branches:
206+
name: Check PR branches
207+
needs: job_get_metadata
208+
runs-on: ubuntu-20.04
209+
if: github.event_name == 'pull_request'
210+
permissions:
211+
pull-requests: write
212+
steps:
213+
- name: PR is opened against master
214+
uses: mshick/add-pr-comment@dd126dd8c253650d181ad9538d8b4fa218fc31e8
215+
if: ${{ github.base_ref == 'master' && !startsWith(github.head_ref, 'prepare-release/') }}
216+
with:
217+
message: |
218+
⚠️ This PR is opened against **master**. You probably want to open it against **develop**.
293219
294220
job_size_check:
295221
name: Size Check
@@ -346,7 +272,7 @@ jobs:
346272

347273
job_check_format:
348274
name: Check file formatting
349-
needs: [job_get_metadata, job_install_deps]
275+
needs: [job_get_metadata, job_build]
350276
timeout-minutes: 10
351277
runs-on: ubuntu-20.04
352278
steps:
@@ -362,7 +288,7 @@ jobs:
362288
uses: actions/cache/restore@v4
363289
with:
364290
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
365-
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
291+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
366292
fail-on-cache-miss: true
367293
- name: Check file formatting
368294
run: yarn lint:prettier && yarn lint:biome
@@ -437,6 +363,7 @@ jobs:
437363
steps:
438364
- name: Check out base commit (${{ github.event.pull_request.base.sha }})
439365
uses: actions/checkout@v4
366+
if: github.event_name == 'pull_request'
440367
with:
441368
ref: ${{ github.event.pull_request.base.sha }}
442369

@@ -469,7 +396,7 @@ jobs:
469396
job_bun_unit_tests:
470397
name: Bun Unit Tests
471398
needs: [job_get_metadata, job_build]
472-
if: needs.job_get_metadata.outputs.changed_bun == 'true' || github.event_name != 'pull_request'
399+
if: needs.job_build.outputs.changed_bun == 'true' || github.event_name != 'pull_request'
473400
timeout-minutes: 10
474401
runs-on: ubuntu-20.04
475402
strategy:
@@ -496,7 +423,7 @@ jobs:
496423
job_deno_unit_tests:
497424
name: Deno Unit Tests
498425
needs: [job_get_metadata, job_build]
499-
if: needs.job_get_metadata.outputs.changed_deno == 'true' || github.event_name != 'pull_request'
426+
if: needs.job_build.outputs.changed_deno == 'true' || github.event_name != 'pull_request'
500427
timeout-minutes: 10
501428
runs-on: ubuntu-20.04
502429
strategy:
@@ -536,6 +463,7 @@ jobs:
536463
steps:
537464
- name: Check out base commit (${{ github.event.pull_request.base.sha }})
538465
uses: actions/checkout@v4
466+
if: github.event_name == 'pull_request'
539467
with:
540468
ref: ${{ github.event.pull_request.base.sha }}
541469
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
@@ -571,7 +499,7 @@ jobs:
571499
job_profiling_node_unit_tests:
572500
name: Node Profiling Unit Tests
573501
needs: [job_get_metadata, job_build]
574-
if: needs.job_get_metadata.outputs.changed_node == 'true' || needs.job_get_metadata.outputs.changed_profiling_node == 'true' || github.event_name != 'pull_request'
502+
if: needs.job_build.outputs.changed_node == 'true' || needs.job_get_metadata.outputs.changed_profiling_node == 'true' || github.event_name != 'pull_request'
575503
runs-on: ubuntu-latest
576504
timeout-minutes: 10
577505
steps:
@@ -599,7 +527,7 @@ jobs:
599527
job_browser_playwright_tests:
600528
name: Playwright (${{ matrix.bundle }}${{ matrix.shard && format(' {0}/{1}', matrix.shard, matrix.shards) || ''}}) Tests
601529
needs: [job_get_metadata, job_build]
602-
if: needs.job_get_metadata.outputs.changed_browser_integration == 'true' || github.event_name != 'pull_request'
530+
if: needs.job_build.outputs.changed_browser_integration == 'true' || github.event_name != 'pull_request'
603531
runs-on: ubuntu-20.04-large-js
604532
timeout-minutes: 25
605533
strategy:
@@ -690,11 +618,10 @@ jobs:
690618
name: playwright-traces
691619
path: dev-packages/browser-integration-tests/test-results
692620

693-
694621
job_browser_loader_tests:
695622
name: Playwright Loader (${{ matrix.bundle }}) Tests
696623
needs: [job_get_metadata, job_build]
697-
if: needs.job_get_metadata.outputs.changed_browser_integration == 'true' || github.event_name != 'pull_request'
624+
if: needs.job_build.outputs.changed_browser_integration == 'true' || github.event_name != 'pull_request'
698625
runs-on: ubuntu-20.04
699626
timeout-minutes: 15
700627
strategy:
@@ -780,13 +707,12 @@ jobs:
780707
exit 1
781708
fi
782709
783-
784710
job_node_integration_tests:
785711
name:
786712
Node (${{ matrix.node }})${{ (matrix.typescript && format(' (TS {0})', matrix.typescript)) || '' }} Integration
787713
Tests
788714
needs: [job_get_metadata, job_build]
789-
if: needs.job_get_metadata.outputs.changed_node_integration == 'true' || github.event_name != 'pull_request'
715+
if: needs.job_build.outputs.changed_node_integration == 'true' || github.event_name != 'pull_request'
790716
runs-on: ubuntu-20.04
791717
timeout-minutes: 15
792718
strategy:
@@ -828,7 +754,7 @@ jobs:
828754
job_remix_integration_tests:
829755
name: Remix v${{ matrix.remix }} (Node ${{ matrix.node }}) Tests
830756
needs: [job_get_metadata, job_build]
831-
if: needs.job_get_metadata.outputs.changed_remix == 'true' || github.event_name != 'pull_request'
757+
if: needs.job_build.outputs.changed_remix == 'true' || github.event_name != 'pull_request'
832758
runs-on: ubuntu-20.04
833759
timeout-minutes: 10
834760
strategy:
@@ -896,7 +822,7 @@ jobs:
896822
# Rebuild profiling by compiling TS and pull the precompiled binary artifacts
897823
- name: Build Profiling Node
898824
if: |
899-
(needs.job_get_metadata.outputs.changed_profiling_node_bindings == 'true') ||
825+
(needs.job_get_metadata.outputs.changed_profiling_node == 'true') ||
900826
(needs.job_get_metadata.outputs.is_release == 'true') ||
901827
(github.event_name != 'pull_request')
902828
run: yarn lerna run build:lib --scope @sentry/profiling-node
@@ -905,7 +831,7 @@ jobs:
905831
# @TODO: v4 breaks convenient merging of same name artifacts
906832
# https://github.com/actions/upload-artifact/issues/478
907833
if: |
908-
(needs.job_get_metadata.outputs.changed_profiling_node_bindings == 'true') ||
834+
(needs.job_get_metadata.outputs.changed_profiling_node == 'true') ||
909835
(needs.job_get_metadata.outputs.is_release == 'true') ||
910836
(github.event_name != 'pull_request')
911837
uses: actions/download-artifact@v3
@@ -1192,7 +1118,7 @@ jobs:
11921118
always() && needs.job_e2e_prepare.result == 'success' &&
11931119
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
11941120
(
1195-
(needs.job_get_metadata.outputs.changed_profiling_node_bindings == 'true') ||
1121+
(needs.job_get_metadata.outputs.changed_profiling_node == 'true') ||
11961122
(needs.job_get_metadata.outputs.is_release == 'true') ||
11971123
(github.event_name != 'pull_request')
11981124
)
@@ -1342,11 +1268,11 @@ jobs:
13421268

13431269
job_compile_bindings_profiling_node:
13441270
name: Compile & Test Profiling Bindings (v${{ matrix.node }}) ${{ matrix.target_platform || matrix.os }}, ${{ matrix.node || matrix.container }}, ${{ matrix.arch || matrix.container }}, ${{ contains(matrix.container, 'alpine') && 'musl' || 'glibc' }}
1345-
needs: [job_get_metadata, job_install_deps, job_build]
1271+
needs: [job_get_metadata, job_build]
13461272
# Compiling bindings can be very slow (especially on windows), so only run precompile
13471273
# Skip precompile unless we are on a release branch as precompile slows down CI times.
13481274
if: |
1349-
(needs.job_get_metadata.outputs.changed_profiling_node_bindings == 'true') ||
1275+
(needs.job_get_metadata.outputs.changed_profiling_node == 'true') ||
13501276
(needs.job_get_metadata.outputs.is_release == 'true') ||
13511277
(github.event_name != 'pull_request')
13521278
runs-on: ${{ matrix.os }}
@@ -1475,7 +1401,7 @@ jobs:
14751401
id: restore-dependencies
14761402
with:
14771403
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
1478-
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
1404+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
14791405
enableCrossOsArchive: true
14801406

14811407
- name: Restore build cache

0 commit comments

Comments
 (0)