@@ -20,27 +20,23 @@ permissions:
20
20
id-token : write
21
21
22
22
jobs :
23
- release :
24
- name : Release
23
+ check_release :
24
+ name : Check for release tag
25
25
runs-on : ubuntu-latest
26
- environment : npm
26
+ outputs :
27
+ proceed : ${{ github.event_name == 'workflow_dispatch' && 'true' || steps.check_tag.outputs.proceed }}
28
+ release_tag : ${{ github.event_name == 'workflow_dispatch' && inputs.tag || steps.check_tag.outputs.release_tag }}
27
29
steps :
28
30
- name : Checkout
31
+ if : github.event_name != 'workflow_dispatch'
29
32
uses : actions/checkout@v4
30
33
with :
31
- ref : ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
32
34
fetch-depth : 0
33
35
34
36
- name : Check if release tag exists for this commit
37
+ if : github.event_name != 'workflow_dispatch'
35
38
id : check_tag
36
39
run : |
37
- # For manual dispatch, we already know we should proceed
38
- if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
39
- echo "proceed=true" >> $GITHUB_OUTPUT
40
- echo "release_tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
41
- exit 0
42
- fi
43
-
44
40
# For push to main branch, check if a release tag points to this commit
45
41
TAGS=$(git tag --points-at ${{ github.sha }} | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$' || true)
46
42
64
60
echo "proceed=true" >> $GITHUB_OUTPUT
65
61
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
66
62
63
+ release :
64
+ name : Release
65
+ runs-on : ubuntu-latest
66
+ needs : check_release
67
+ if : needs.check_release.outputs.proceed == 'true'
68
+ environment : npm
69
+ steps :
70
+ - name : Checkout
71
+ uses : actions/checkout@v4
72
+ with :
73
+ ref : ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
74
+ fetch-depth : 0
75
+
67
76
- name : Verify tag matches package.json version
68
- if : steps.check_tag.outputs.proceed == 'true'
69
77
run : |
70
78
jq --raw-output --exit-status --arg tag "$RELEASE_TAG" '
71
79
if (.version == ($tag | ltrimstr("v"))) then
@@ -74,10 +82,10 @@ jobs:
74
82
"Package version (\(.version)) does not match tag version (\($tag | ltrimstr("v")))" | halt_error(1)
75
83
end' package.json
76
84
env :
77
- RELEASE_TAG : ${{ steps.check_tag .outputs.release_tag }}
85
+ RELEASE_TAG : ${{ needs.check_release .outputs.release_tag }}
78
86
79
87
- name : Check CI status
80
- if : ${{ steps.check_tag.outputs.proceed == 'true' && !inputs.skip_ci_check }}
88
+ if : ${{ github.event_name != 'workflow_dispatch' || !inputs.skip_ci_check }}
81
89
run : |
82
90
# Check if CI has completed successfully for this commit
83
91
gh run list --commit ${{ github.sha }} --status success --json workflowName | jq --raw-output --exit-status '
@@ -90,26 +98,23 @@ jobs:
90
98
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
91
99
92
100
- name : Setup Node.js
93
- if : steps.check_tag.outputs.proceed == 'true'
94
101
uses : actions/setup-node@v4
95
102
with :
96
103
node-version-file : package.json
97
104
cache : npm
98
105
registry-url : https://registry.npmjs.org
99
106
100
107
- name : Publish to npm with provenance
101
- if : steps.check_tag.outputs.proceed == 'true'
102
108
run : npm publish --provenance
103
109
env :
104
110
NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
105
111
106
112
- name : Create GitHub Release
107
- if : steps.check_tag.outputs.proceed == 'true'
108
113
run : |
109
114
gh release create "$RELEASE_TAG" \
110
115
--title "$RELEASE_TAG" \
111
116
--draft \
112
117
--generate-notes
113
118
env :
114
- RELEASE_TAG : ${{ steps.check_tag .outputs.release_tag }}
119
+ RELEASE_TAG : ${{ needs.check_release .outputs.release_tag }}
115
120
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments