Skip to content

Commit 24e1def

Browse files
authored
ci: use workflow_call to chain CI validation before release (#1236)
1 parent 703fa22 commit 24e1def

3 files changed

Lines changed: 12 additions & 21 deletions

File tree

.github/workflows/check-ci-validation.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
name: CI Validation
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- next
4+
workflow_call:
85
pull_request:
96
types:
107
- opened

.github/workflows/publish-package-release.yml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
name: Package Release
22

33
on:
4-
workflow_run:
5-
workflows:
6-
- CI Validation
4+
push:
75
branches:
86
- main
97
- next
10-
types:
11-
- completed
128

139
env:
1410
GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
@@ -33,12 +29,17 @@ concurrency:
3329
cancel-in-progress: false
3430

3531
jobs:
32+
ci-validation:
33+
name: CI Validation
34+
uses: ./.github/workflows/check-ci-validation.yml
35+
secrets: inherit
36+
3637
release-and-publish:
3738
name: Release & Publish
3839
runs-on: ubuntu-latest
3940
timeout-minutes: 60
4041

41-
if: github.event.workflow_run.conclusion == 'success'
42+
needs: ci-validation
4243

4344
steps:
4445
- name: Checkout repository
@@ -47,10 +48,6 @@ jobs:
4748
token: ${{ secrets.GH_REPO_TOKEN }}
4849
fetch-depth: 0
4950

50-
- name: Checkout target branch
51-
run: |
52-
git checkout ${{ github.event.workflow_run.head_branch }}
53-
5451
- name: Prepare Node.js environment
5552
uses: actions/setup-node@v6
5653
with:
@@ -80,11 +77,8 @@ jobs:
8077
# Packages registry, providing a predictable release workflow for both registries.
8178
- name: Publish package to public npm registry
8279
id: semantic-release
83-
# `GITHUB_REF` is overridden at the shell level because in `workflow_run` events
84-
# it always points to the default branch, not the branch that triggered the run.
85-
# The step-level `env:` block cannot override `GITHUB_*` variables in Actions.
8680
run: |
87-
GITHUB_REF=${{ github.event.workflow_run.head_branch }} npx semantic-release
81+
npx semantic-release
8882
env:
8983
GITHUB_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
9084
GIT_AUTHOR_EMAIL: [email protected]
@@ -110,7 +104,7 @@ jobs:
110104
if: ${{ steps.semantic-release.outputs.package-published == 'true' }}
111105
id: dist-tag
112106
run: |
113-
if [[ "${{ github.event.workflow_run.head_branch }}" == "next" ]]; then
107+
if [[ "${{ github.ref_name }}" == "next" ]]; then
114108
echo "tag=next" >> $GITHUB_OUTPUT
115109
else
116110
echo "tag=latest" >> $GITHUB_OUTPUT

release.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
},
1818
],
1919
// Only update CHANGELOG.md and commit back on stable releases (main branch)
20-
...(process.env.GITHUB_REF === 'next'
20+
...(process.env.GITHUB_REF_NAME === 'next'
2121
? []
2222
: [
2323
'@semantic-release/changelog',
@@ -30,7 +30,7 @@ module.exports = {
3030
]),
3131
'@semantic-release/npm',
3232
// Only commit artifacts back on stable releases (main branch)
33-
...(process.env.GITHUB_REF === 'next' ? [] : ['@semantic-release/git']),
33+
...(process.env.GITHUB_REF_NAME === 'next' ? [] : ['@semantic-release/git']),
3434
'@semantic-release/github',
3535
[
3636
'@semantic-release/exec',

0 commit comments

Comments
 (0)