Skip to content

Commit f3ff9d8

Browse files
authored
fix: Preserve existing Node version on macOS and Windows runners (#279) (#280)
The action now saves and restores the original Node version when running on macOS and Windows runners, preventing it from permanently changing the Node version for subsequent workflow steps. This ensures the action doesn't interfere with other steps that may require a specific Node version. Fixes: #279
1 parent cd0b4df commit f3ff9d8

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

.github/workflows/build.yml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
if: github.ref == 'refs/heads/master'
6565
with:
6666
github-token: ${{ steps.token.outputs.token }}
67-
message: "chore: Set docker tag for master [skip ci]"
67+
message: 'chore: Set docker tag for master [skip ci]'
6868

6969
docker-build:
7070
name: Build & publish Docker images
@@ -222,3 +222,48 @@ jobs:
222222
with:
223223
environment: production
224224
working_directory: ./test
225+
226+
test-node-version-preserved:
227+
needs: docker-build
228+
strategy:
229+
matrix:
230+
os: [ubuntu-latest, windows-latest, macos-latest]
231+
node-version: ['20.x', '22.x']
232+
runs-on: ${{ matrix.os }}
233+
name: Test Node version preserved on ${{ matrix.os }} with Node ${{ matrix.node-version }}
234+
steps:
235+
- uses: actions/checkout@v4
236+
with:
237+
fetch-depth: 0
238+
239+
- name: Setup Node
240+
uses: actions/setup-node@v4
241+
with:
242+
node-version: ${{ matrix.node-version }}
243+
244+
- name: Print Node Version (Before)
245+
id: node_before
246+
shell: bash
247+
run: |
248+
VERSION=$(node --version)
249+
echo "Node version before: $VERSION"
250+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
251+
252+
- name: Mock creating a Sentry release
253+
uses: ./
254+
env:
255+
MOCK: true
256+
with:
257+
environment: production
258+
259+
- name: Print Node Version (After)
260+
shell: bash
261+
run: |
262+
VERSION_AFTER=$(node --version)
263+
echo "Node version after: $VERSION_AFTER"
264+
echo "Expected: ${{ steps.node_before.outputs.VERSION }}"
265+
if [ "$VERSION_AFTER" != "${{ steps.node_before.outputs.VERSION }}" ]; then
266+
echo "ERROR: Node version changed from ${{ steps.node_before.outputs.VERSION }} to $VERSION_AFTER"
267+
exit 1
268+
fi
269+
echo "SUCCESS: Node version preserved"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 3.1.2
4+
5+
- fix: Preserve existing Node version on macOS and Windows runners (#280) by @andreiborza
6+
37
## 3.1.1
48

59
- fix: Only pass `urlPrefix` to sentry-cli if it's not empty (#275) by @andreiborza

action.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ runs:
148148
INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }}
149149
INPUT_DISABLE_TELEMETRY: ${{ inputs.disable_telemetry }}
150150
INPUT_DISABLE_SAFE_DIRECTORY: ${{ inputs.disable_safe_directory }}
151-
uses: docker://ghcr.io/getsentry/action-release-image:master
151+
uses: docker://ghcr.io/getsentry/action-release-image:ab-restore-node-version
152152

153153
# For actions running on macos or windows runners, we use a composite
154154
# action approach which allows us to install the arch specific sentry-cli
@@ -160,6 +160,16 @@ runs:
160160
run: |
161161
git config --global --add safe.directory "$GITHUB_WORKSPACE"
162162
163+
# Save the current Node version before changing it
164+
- name: Save current Node version
165+
if: runner.os == 'macOS' || runner.os == 'Windows'
166+
id: node_version
167+
shell: bash
168+
run: |
169+
if command -v node &> /dev/null; then
170+
echo "NODE_VERSION=$(node --version | sed 's/v//')" >> $GITHUB_OUTPUT
171+
fi
172+
163173
- name: Setup node
164174
if: runner.os == 'macOS' || runner.os == 'Windows'
165175
uses: actions/setup-node@v4
@@ -204,6 +214,13 @@ runs:
204214
run: npm run start
205215
working-directory: ${{ github.action_path }}
206216

217+
# Restore the original Node version
218+
- name: Restore original Node version
219+
if: (runner.os == 'macOS' || runner.os == 'Windows') && steps.node_version.outputs.NODE_VERSION != ''
220+
uses: actions/setup-node@v4
221+
with:
222+
node-version: ${{ steps.node_version.outputs.NODE_VERSION }}
223+
207224
branding:
208225
icon: 'triangle'
209226
color: 'purple'

0 commit comments

Comments
 (0)