Skip to content

Commit fa0522d

Browse files
szokeasaurusrexrunningcode
authored andcommitted
ci(release): npm install in test_node.yml on release (#2768)
`npm ci` will fail here, as the new versions of the optional dependencies are not published yet. Additionally, add a script to bump the optional dependencies in the package-lock.json after a release is created. Otherwise, `npm ci` will continue to fail after the release, until someone updates the package-lock.json manually.
1 parent 702f95d commit fa0522d

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

.craft.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
minVersion: 0.23.1
22
changelogPolicy: auto
3+
postReleaseCommand: bash scripts/post-release.sh
34
targets:
45
- name: gcs
56
bucket: sentry-sdk-assets

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
test_node:
2929
name: Test Node
3030
uses: ./.github/workflows/test_node.yml
31+
with:
32+
triggered-by-release: ${{ github.event_name == 'push' && startsWith(github.ref_name, 'release/') }}
3133

3234
test_swift:
3335
name: Test Swift

.github/workflows/test_node.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: Test Node
22

33
on:
44
workflow_call:
5+
inputs:
6+
triggered-by-release:
7+
type: boolean
8+
description: Whether the workflow was triggered by a release
9+
default: false
510
outputs:
611
matrix-result:
712
description: 'Matrix job result'
@@ -19,10 +24,16 @@ jobs:
1924
with:
2025
node-version-file: package.json
2126

22-
# We need to skip the fallback download because downloading will fail on release branches because the new version isn't available yet.
23-
# We have to use npm here because yarn fails on the non-existing existing optionalDependency version:
24-
# https://github.com/yarnpkg/berry/issues/2425#issuecomment-1627807326
25-
- run: SENTRYCLI_SKIP_DOWNLOAD=1 npm ci
27+
- name: Install dependencies via npm ci
28+
if: ${{ !inputs.triggered-by-release }}
29+
run: npm ci
30+
31+
# For pushes to the release branch, we need to install the dependencies via `npm install`
32+
# because the `package-lock.json` is not updated with the new versions of the optional
33+
# dependencies yet. We also must skip the fallback download via --ignore-scripts.
34+
- name: Install dependencies via npm install (for pushes to release branch)
35+
if: ${{ inputs.triggered-by-release }}
36+
run: npm install --omit=optional --ignore-scripts
2637

2738
- run: npm run check:types
2839

@@ -43,10 +54,16 @@ jobs:
4354
with:
4455
node-version: ${{ matrix.node-version }}
4556

46-
# We need to skip the fallback download because downloading will fail on release branches because the new version isn't available yet.
47-
# We have to use npm here because yarn fails on the non-existing existing optionalDependency version:
48-
# https://github.com/yarnpkg/berry/issues/2425#issuecomment-1627807326
49-
- run: SENTRYCLI_SKIP_DOWNLOAD=1 npm ci
57+
- name: Install dependencies via npm ci
58+
if: ${{ !inputs.triggered-by-release }}
59+
run: npm ci
60+
61+
# For pushes to the release branch, we need to install the dependencies via `npm install`
62+
# because the `package-lock.json` is not updated with the new versions of the optional
63+
# dependencies yet. We also must skip the fallback download via --ignore-scripts.
64+
- name: Install dependencies via npm install (for pushes to release branch)
65+
if: ${{ inputs.triggered-by-release }}
66+
run: npm install --omit=optional --ignore-scripts
5067

5168
# older node versions need an older nft
5269
- run: SENTRYCLI_SKIP_DOWNLOAD=1 npm install @vercel/nft@0.22.1

scripts/post-release.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# This script is run by Craft after a release is created.
4+
# We currently use it to bump the platform-specific optional dependencies to their new versions
5+
# in the package-lock.json, immediately after a release is created. This is needed for CI to
6+
# pass after the release is created.c
7+
8+
set -eux
9+
OLD_VERSION="${1}"
10+
NEW_VERSION="${2}"
11+
12+
git checkout master
13+
14+
# We need to update the package-lock.json to include the new version of the optional dependencies.
15+
npm install --package-lock-only
16+
17+
git add package-lock.json
18+
19+
# Only commit if there are changes
20+
git diff --staged --quiet || git commit -m "build(npm): 🤖 Bump optional dependencies to ${NEW_VERSION}"
21+
git pull --rebase
22+
git push

0 commit comments

Comments
 (0)