Skip to content

Commit 3564903

Browse files
authored
ci: add dry-run execution of semantic-release for validation purposes (#321)
1 parent 4afeca3 commit 3564903

3 files changed

Lines changed: 71 additions & 3 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Release - Dry Run
2+
3+
on:
4+
pull_request:
5+
branches: [ main, '+.x', beta, alpha ]
6+
7+
permissions: {}
8+
9+
jobs:
10+
release-dryrun:
11+
name: Release - Dry Run
12+
runs-on: ubuntu-24.04
13+
timeout-minutes: 15
14+
15+
permissions:
16+
contents: write # Necessary for semantic-release to verify Git push permissions, even during a dry run.
17+
18+
steps:
19+
- name: Harden runner
20+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
21+
with:
22+
disable-sudo-and-containers: true
23+
egress-policy: block
24+
allowed-endpoints: >
25+
github.com:443
26+
*.github.com:443
27+
*.githubusercontent.com:443
28+
api.nuget.org:443
29+
registry.npmjs.org:443
30+
31+
- name: Checkout repository
32+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33+
with:
34+
fetch-depth: 0 # Required by semantic-release
35+
# Use the pull request head ref (source branch) to ensure the dry run simulates a release for the current PR.
36+
# LIMITATION: will probably not work with pull requests from forks forbidding read accesses.
37+
ref: ${{ github.head_ref }}
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
41+
with:
42+
node-version: lts/jod
43+
cache: npm
44+
cache-dependency-path: .github/release/package-lock.json
45+
46+
- name: Install semantic-release
47+
working-directory: .github/release/
48+
run: npm clean-install --engine-strict
49+
50+
- name: Simulate new feature
51+
run: |
52+
git config --local user.name 'github-actions[bot]'
53+
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
54+
git commit --no-verify --allow-empty -m 'feat: simulate new feature'
55+
56+
- name: Release
57+
env:
58+
GITHUB_TOKEN: ${{ github.token }}
59+
working-directory: .github/release/
60+
# Perform a dry run without publishing anything.
61+
#
62+
# Unset the `GITHUB_ACTIONS` environment variable to trick semantic-release into thinking it's not running in a CI environment,
63+
# as `--no-ci` alone is insufficient.
64+
#
65+
# Use `--branches '${{ github.head_ref }}'` to consider the PR head ref (source branch) as a release one for the dry run.
66+
run: |
67+
unset GITHUB_ACTIONS
68+
npx --no-install semantic-release --dry-run --no-ci --branches '${{ github.head_ref }}'

.github/workflows/release-maintenance.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ permissions: {}
2929

3030
jobs:
3131
validate:
32-
name: Validate
32+
name: Release - Validate
3333
uses: ./.github/workflows/ci.yml
3434

3535
# Only runs on the default branch (i.e., main).
@@ -44,7 +44,7 @@ jobs:
4444
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
4545

4646
perform:
47-
name: Perform
47+
name: Release - Perform
4848
runs-on: ubuntu-24.04
4949
timeout-minutes: 15
5050

.github/workflows/release-on-change.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ permissions: {}
2929

3030
jobs:
3131
perform:
32-
name: Perform
32+
name: Release - Perform
3333
runs-on: ubuntu-24.04
3434
timeout-minutes: 15
3535

0 commit comments

Comments
 (0)