1
- # Release Branch
1
+ # Release Chore
2
2
#
3
- # Execute version bump, changelog, and pull request operations on release branch creation .
3
+ # Execute branch, version bump, changelog, and pull request operations on release chore commit .
4
4
#
5
5
# References:
6
6
#
7
- # - https://cli.github.com/manual/gh_auth_status
8
7
# - https://cli.github.com/manual/gh_pr_create
9
8
# - https://docs.github.com/actions/learn-github-actions/contexts
10
9
# - https://docs.github.com/actions/learn-github-actions/expressions
11
- # - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#create
10
+ # - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#push
12
11
# - https://docs.github.com/actions/using-workflows/using-github-cli-in-workflows
13
12
# - https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions
14
- # - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#create
13
+ # - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#push
15
14
# - https://github.com/actions/checkout
16
15
# - https://github.com/actions/create-github-app-token
16
+ # - https://github.com/flex-development/gh-commit
17
17
# - https://github.com/hmarr/debug-action
18
18
# - https://github.com/kaisugi/action-regex-match
19
- # - https://github.com/tohgarashi/verified-commit
20
19
# - https://regex101.com/r/OwpOr2
20
+ # - https://regex101.com/r/VIIVGd
21
21
22
22
---
23
- name : release-branch
24
- on : create
23
+ name : release-chore
24
+ on :
25
+ push :
26
+ branches :
27
+ - main
25
28
concurrency :
26
29
cancel-in-progress : true
27
30
group : ${{ github.workflow }}-${{ github.ref }}
28
31
jobs :
29
32
preflight :
30
- if : |
31
- github.ref_type == 'branch' &&
32
- startsWith(github.ref_name, 'release/') &&
33
- contains(vars.MAINTAINERS, github.actor)
33
+ if : startsWith(github.event.head_commit.message, 'release(chore):')
34
34
runs-on : ubuntu-latest
35
35
outputs :
36
+ branch : ${{ steps.branch.outputs.result }}
36
37
message : ${{ steps.message.outputs.result }}
37
38
tag : ${{ steps.tag.outputs.result }}
38
39
version : ${{ steps.version.outputs.match }}
39
40
steps :
40
41
- id : debug
41
42
name : Print environment variables and event payload
42
43
44
+ - id : fail-actor
45
+ if : contains(vars.MAINTAINERS, github.actor) == false
46
+ name : Fail on unauthorized actor
47
+ run : |
48
+ echo '**Unauthorized actor: ${{ github.actor }}**' >>$GITHUB_STEP_SUMMARY
49
+ exit 1
43
50
- id : checkout
44
51
name : Checkout ${{ github.ref_name }}
45
52
46
53
with :
47
54
persist-credentials : false
48
55
ref : ${{ github.ref }}
56
+ - id : diff-tree
57
+ name : Get diff tree
58
+ run : echo "result=$(git diff-tree --name-only -r ${{ github.sha }})" >>$GITHUB_OUTPUT
59
+ - id : fail-diff-tree
60
+ if : steps.diff-tree.outputs.result != ''
61
+ name : Fail on invalid diff tree
62
+ run : |
63
+ ERR='**Invalid diff tree**
64
+ ```sh
65
+ ${{ steps.diff-tree.outputs.result }}
66
+ ```'
67
+ echo "$ERR" >>$GITHUB_STEP_SUMMARY
68
+ exit 1
49
69
- id : version
50
70
name : Get release version
51
71
52
72
with :
53
- regex : ${{ vars.RELEASE_BRANCH_REGEX }}
54
- text : ${{ github.ref_name }}
55
- - id : version- fail
73
+ regex : ${{ vars.RELEASE_CHORE_REGEX }}
74
+ text : ${{ github.event.head_commit.message }}
75
+ - id : fail-version
56
76
if : steps.version.outputs.match == ''
57
77
name : Fail on invalid release version
58
78
run : |
59
- ERR='**Invalid release branch: ${{ github.ref_name }}**
60
- Branch must match [`${{ vars.RELEASE_BRANCH_REGEX }}`](https://regex101.com/r/OwpOr2)'
79
+ ERR='**Invalid release chore commit**
80
+ ```sh
81
+ ${{ github.event.head_commit.message }}
82
+ ```
83
+ Message must match [`${{ vars.RELEASE_CHORE_REGEX }}`](https://regex101.com/r/OwpOr2)'
61
84
echo "$ERR" >>$GITHUB_STEP_SUMMARY
62
85
exit 1
63
86
- id : tag
@@ -66,10 +89,35 @@ jobs:
66
89
echo "result=$(jq .tagprefix grease.config.json -r)${{ steps.version.outputs.match }}" >>$GITHUB_OUTPUT
67
90
- id : message
68
91
name : Get release message
92
+ run : ' echo "result=release: ${{ steps.tag.outputs.result }}" >>$GITHUB_OUTPUT'
93
+ - id : branch
94
+ name : Get release branch name
95
+ run : echo "result=release/${{ steps.version.outputs.match }}" >>$GITHUB_OUTPUT
96
+ branch :
97
+ needs : preflight
98
+ runs-on : ubuntu-latest
99
+ steps :
100
+ - id : bot-token
101
+ name : Get bot token
102
+
103
+ with :
104
+ app-id : ${{ secrets.BOT_APP_ID }}
105
+ private-key : ${{ secrets.BOT_PRIVATE_KEY }}
106
+ - id : checkout
107
+ name : Checkout ${{ github.ref_name }}
108
+
109
+ with :
110
+ ref : ${{ github.ref }}
111
+ token : ${{ steps.bot-token.outputs.token }}
112
+ - id : branch
113
+ name : Create and push branch ${{ needs.preflight.outputs.branch }}
69
114
run : |
70
- echo "result=release: ${{ steps.tag.outputs.result }}" >>$GITHUB_OUTPUT
115
+ git branch ${{ needs.preflight.outputs.branch }}
116
+ git push origin --no-verify ${{ needs.preflight.outputs.branch }}
71
117
prepare :
72
- needs : preflight
118
+ needs :
119
+ - branch
120
+ - preflight
73
121
permissions :
74
122
packages : read
75
123
runs-on : ubuntu-latest
@@ -83,18 +131,18 @@ jobs:
83
131
app-id : ${{ secrets.BOT_APP_ID }}
84
132
private-key : ${{ secrets.BOT_PRIVATE_KEY }}
85
133
- id : checkout
86
- name : Checkout ${{ github.ref_name }}
134
+ name : Checkout ${{ needs.preflight.outputs.branch }}
87
135
88
136
with :
89
137
fetch-depth : 0
90
138
persist-credentials : false
91
- ref : ${{ github.ref }}
139
+ ref : ${{ needs.preflight.outputs.branch }}
92
140
token : ${{ steps.bot-token.outputs.token }}
93
141
- id : yarn
94
142
name : Install dependencies
95
143
env :
96
144
HUSKY : 0
97
- run : yarn --immutable
145
+ run : yarn
98
146
- id : build
99
147
name : Build project
100
148
env :
@@ -111,20 +159,20 @@ jobs:
111
159
echo "$(node ./dist/cli.mjs changelog)" >>$GITHUB_STEP_SUMMARY
112
160
node ./dist/cli.mjs changelog -sw
113
161
- id : commit
114
- name : Commit release preparation
115
- uses :
tohgarashi/[email protected]
116
- env :
117
- GH_TOKEN : ${{ steps.bot-token.outputs.token }}
162
+ name : Commit and push release preparation
163
+ uses :
flex-development/[email protected]
118
164
with :
119
- commit-message : |
120
- ${{ needs.preflight.outputs.message }}
121
-
122
- Signed-off-by: ${{ vars.BOT_NAME }} <${{ vars.BOT_EMAIL }}>
123
-
124
- detect-changed : true
125
- ref : ${{ github.ref }}
165
+ message : ${{ needs.preflight.outputs.message }}
166
+ ref : ${{ needs.preflight.outputs.branch }}
167
+ token : ${{ steps.bot-token.outputs.token }}
168
+ trailers : ' Signed-off-by: ${{ vars.BOT_NAME }} <${{ vars.BOT_EMAIL }}>'
169
+ - id : commit-url
170
+ name : Print commit url
171
+ run : |
172
+ echo ${{ format('{0}/{1}/commit/{2}', github.server_url, github.repository, steps.commit.outputs.sha) }}
126
173
pr :
127
174
needs :
175
+ - branch
128
176
- preflight
129
177
- prepare
130
178
runs-on : ubuntu-latest
@@ -135,21 +183,17 @@ jobs:
135
183
with :
136
184
app-id : ${{ secrets.BOT_APP_ID }}
137
185
private-key : ${{ secrets.BOT_PRIVATE_KEY }}
138
- - id : github-token
139
- name : Set env.GITHUB_TOKEN
140
- run : echo "GITHUB_TOKEN=${{ steps.bot-token.outputs.token }}" >>$GITHUB_ENV
141
- - id : gh-auth
142
- name : Check gh authentication state
143
- run : gh auth status
144
186
- id : checkout
145
- name : Checkout ${{ github.ref_name }}
187
+ name : Checkout ${{ needs.preflight.outputs.branch }}
146
188
147
189
with :
148
190
persist-credentials : false
149
- ref : ${{ github.ref }}
191
+ ref : ${{ needs.preflight.outputs.branch }}
150
192
token : ${{ steps.bot-token.outputs.token }}
151
193
- id : pr
152
194
name : Create pull request
195
+ env :
196
+ GITHUB_TOKEN : ${{ steps.bot-token.outputs.token }}
153
197
run : |
154
198
gh pr create --title='${{ needs.preflight.outputs.message }}' --label=scope:release --assignee=${{ github.actor }} --reviewer=${{ github.actor }} --body='## Description
155
199
0 commit comments