forked from nicolo-ribaudo/babel
-
Notifications
You must be signed in to change notification settings - Fork 0
324 lines (292 loc) · 11.5 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
name: Release
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
version:
# Often minor versions require human intervention, so it's safer if we
# force ourselves to always create them locally.
description: ⚠️ This workflow can only automatically release patch versions, or Babel 8 pre-releases
required: true
default: patch
type: choice
options:
- patch
- breaking-prerelease
permissions:
contents: read
jobs:
check-release-type:
name: Check the release type
runs-on: ubuntu-latest
outputs:
is-babel-8: >-
${{
(github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v8')) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.version == 'breaking-prerelease')
}}
steps:
- name: Log
run: |
echo "Is Babel 8 push? ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v8') }}"
echo "Is Babel 8 dispatch? ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version == 'breaking-prerelease' }}"
log-updates:
name: Log packages to publish
runs-on: ubuntu-latest
needs: check-release-type
if: needs.check-release-type.outputs.is-babel-8 == 'false'
steps:
- name: Checkout the new tag
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: This release will publish the following packages
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
yarn release-tool version --dry patch
else
git diff --name-only HEAD^..HEAD
fi;
git-version:
permissions:
contents: write # for Git to git push
name: Create git tag and commit
runs-on: ubuntu-latest
needs: check-release-type
if: github.event_name == 'workflow_dispatch'
outputs:
branch: ${{ steps.branch-name.outputs.branch }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set @babel-bot as committer
run: |
git config user.name "Babel Bot"
git config user.email "babel-bot@users.noreply.github.com"
- name: Create new version (Babel 7)
if: needs.check-release-type.outputs.is-babel-8 == 'false'
run: |
make new-version-checklist
yarn release-tool version -f @babel/standalone --yes patch
- name: Create new version (Babel 8)
if: needs.check-release-type.outputs.is-babel-8 == 'true'
run: |
make new-babel-8-version
- name: Compute temporary branch name
id: branch-name
run: |
branch="release/temp/$(git describe --abbrev=0)"
echo $branch
echo "branch=$branch" >> $GITHUB_OUTPUT
- name: Push to GitHub
run: |
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:"${{ steps.branch-name.outputs.branch }}" --follow-tags
npm-release:
name: Build, Test and Publish
runs-on: ubuntu-latest
needs:
- check-release-type
- git-version
environment: npm
# The default condition is success(), but this is false when one of the previous jobs is skipped
if: |
always() &&
(needs.git-version.result == 'success' || needs.git-version.result == 'skipped') &&
needs.check-release-type.result == 'success'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout the temporary branch
if: needs.git-version.result == 'success'
run: git checkout ${{ needs.git-version.outputs.branch }}
- name: Set @babel-bot as committer
run: |
git config user.name "Babel Bot"
git config user.email "babel-bot@users.noreply.github.com"
- name: Bump package versions (Babel 8)
if: needs.check-release-type.outputs.is-babel-8 == 'true'
run: |
make new-babel-8-version-create-commit-ci
YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn
- name: Build and Test
run: make prepublish
env:
# Hack: use FORCE_COLOR so that supports-color@5 returnes true for GitHub CI
# Remove once `chalk` is bumped to 4.0.
FORCE_COLOR: true
# Note: `false` doesn't work here, because env vars are strings and Boolean('false')
# is true. Use the empry string instead.
BABEL_8_BREAKING: ${{ needs.check-release-type.outputs.is-babel-8 == 'true' || '' }}
- name: Generate babel-types docs
continue-on-error: true
run: |
mkdir build
node ./packages/babel-types/scripts/generators/docs.js > ./build/types.md
- name: Upload babel-types docs
continue-on-error: true
uses: actions/upload-artifact@v3
with:
name: babel-types-docs
path: build/types.md
retention-days: 3
- name: Publish to npm (Babel 7)
run: yarn release-tool publish --yes
if: needs.check-release-type.outputs.is-babel-8 == 'false'
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm (Babel 8)
# --tag-version-prefix must match the one set in `make new-babel-8-version-create-branch`
run: yarn release-tool publish --yes --tag next --tag-version-prefix tmp.v
if: needs.check-release-type.outputs.is-babel-8 == 'true'
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
BABEL_8_BREAKING: true
USE_ESM: true
github-release:
name: Create GitHub release draft
runs-on: ubuntu-latest
needs:
- check-release-type
- git-version
# The default condition is success(), but this is false when one of the previous jobs is skipped
if: |
always() &&
(needs.git-version.result == 'success' || needs.git-version.result == 'skipped') &&
needs.check-release-type.result == 'success'
outputs:
is-main: ${{ steps.is-main.outputs.result == 1 }}
changelog: ${{ steps.changelog.outputs.changelog }}
version: ${{ steps.tags.outputs.new }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if releasing from main
id: is-main
uses: babel/actions/ref-matches-branch@v2
with:
name: main
- name: Checkout the temporary branch
if: needs.git-version.result == 'success'
run: git checkout ${{ needs.git-version.outputs.branch }}
- name: Get tag info
id: tags
uses: babel/actions/get-release-tags@v2
with:
# GitHub workflow do not support the ternary operator:
# https://github.com/actions/runner/issues/409
# `a && b || c` is equivalent to `a ? b : c` if `b` is truthy
prefix: ${{ needs.check-release-type.outputs.is-babel-8 == 'true' && 'v8' || 'v7' }}
- name: Use Babel 8 PR labels
if: needs.check-release-type.outputs.is-babel-8 == 'true'
run: |
node -e "
const pkg = require('./package.json');
pkg.changelog.labels = pkg.changelog.labels_breaking
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2))
"
- name: Generate the changelog
id: changelog
uses: babel/actions/generate-lerna-changelog@v2
with:
from: ${{ steps.tags.outputs.old }}
to: ${{ steps.tags.outputs.new }}
filter: ${{ needs.check-release-type.outputs.is-babel-8 == 'true' && 'v8' || 'v7' }}
env:
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
- name: Create a draft GitHub release
uses: babel/actions/publish-github-release@v2
with:
tag: ${{ steps.tags.outputs.new }}
changelog: ${{ steps.changelog.outputs.changelog }}
token: ${{ secrets.BOT_TOKEN }}
github-push:
permissions:
contents: write # for Git to git push
name: Push release commit to "main"
runs-on: ubuntu-latest
needs:
- npm-release
- github-release
- git-version
- check-release-type
# The default condition is success(), but this is false when one of the previous jobs is skipped
if: |
always() &&
needs.npm-release.result == 'success' &&
needs.github-release.result == 'success' &&
needs.github-release.outputs.is-main
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout the temporary branch
if: needs.git-version.result == 'success'
run: git checkout ${{ needs.git-version.outputs.branch }}
- name: Get changelog file name
id: filename
run: |
echo "filename=${{ needs.check-release-type.outputs.is-babel-8 == 'true' && '.github/CHANGELOG-v8.md' || 'CHANGELOG.md' }}" >> $GITHUB_OUTPUT
- name: Update CHANGELOG.md
uses: babel/actions/update-changelog@v2
with:
changelog: ${{ needs.github-release.outputs.changelog }}
filename: ${{ steps.filename.outputs.filename }}
- name: Commit CHANGELOG.md
run: |
git add ${{ steps.filename.outputs.filename }}
git -c user.name="Babel Bot" -c user.email="babel-bot@users.noreply.github.com" \
commit -m "Add ${{ needs.github-release.outputs.version }} to ${{ steps.filename.outputs.filename }} [skip ci]" --no-verify --quiet
- name: Push to GitHub
run: |
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:main --follow-tags
- name: Delete temporary branch from GitHub
if: needs.git-version.result == 'success'
run: git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" :${{ needs.git-version.outputs.branch }}
types-docs-updates:
name: Update Babel types docs
runs-on: ubuntu-latest
needs:
- check-release-type
- github-release
- github-push
if: |
always() &&
needs.check-release-type.outputs.is-babel-8 == 'false' &&
needs.github-push.result == 'success' &&
needs.github-release.result == 'success' &&
needs.github-release.outputs.is-main
steps:
- uses: actions/checkout@v4
with:
repository: babel/website
fetch-depth: 0 # Otherwise we cannot push
persist-credentials: false # So that we can push with BOT_TOKEN, otherwise it doesn't trigger CI
- name: Download babel-types docs
uses: actions/download-artifact@v3
with:
name: babel-types-docs
# Downloaded as ./docs/types.md
path: docs
- name: Commit Babel website changes
run: |
git config user.name "Babel Bot"
git config user.email "babel-bot@users.noreply.github.com"
git checkout -b update-types-docs
git commit -am "docs: update babel types"
git push --force "https://babel-bot:${{ secrets.BOT_TOKEN }}@github.com/babel/website.git" update-types-docs
- name: Create Pull Request
uses: babel/actions/create-pull-request@v2
with:
token: ${{ secrets.BOT_TOKEN }}
repository: babel/website
branch: update-types-docs
base: main
title: Update Babel types docs
description: Updated `@babel/types` docs for [Babel ${{ needs.github-release.outputs.version }}](https://github.com/babel/babel/releases/tag/${{ needs.github-release.outputs.version }}).
labels: |
docs
repo automation :robot: