-
Notifications
You must be signed in to change notification settings - Fork 3.6k
140 lines (123 loc) · 4.77 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
name: Release
on:
push:
tags:
- "*alpha*"
- "*pre*"
- "*beta*"
- "1[0-9]+.[0-9]+.[0-9]+"
permissions:
contents: read
jobs:
prerelease:
permissions:
contents: write # for git push
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout highlight.js
uses: actions/checkout@v4
- name: Tag is ${{ github.ref }}.
# we have to repeat ourselves here since the environment is not actually updated
# until the next step executes, so we can't access $TAG_NAME yet
run: |
echo "TAG_NAME=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
echo "MAJOR_VERSION=$(echo ${GITHUB_REF/refs\/tags\//} | cut -d'.' -f1)" >> $GITHUB_ENV
- name: Make sure we are pushing a tag...
if: ${{ !contains(github.ref,'refs/tags/') }}
run: false
# run: echo "TAG_NAME=0.0.0-test0" >> $GITHUB_ENV
- if: contains(github.ref, 'beta') || contains(github.ref, 'pre') || contains(github.ref, 'alpha')
run: |
echo "NPM_TAG=beta" >> $GITHUB_ENV
echo "RELEASING=beta" >> $GITHUB_ENV
- if: ${{ !(contains(github.ref, 'beta') || contains(github.ref, 'pre') || contains(github.ref, 'alpha')) }}
run: |
echo "NPM_TAG=latest" >> $GITHUB_ENV
echo "RELEASING=stable" >> $GITHUB_ENV
- name: match-tag-to-package-version
uses: geritol/match-tag-to-package-version@0.2.0
env:
TAG_PREFIX: refs/tags/ # Optional, default prefix refs/tags/
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Build Node.js package
run: |
npm install
node ./tools/build.js -t node
npm test
- name: Publish highlight.js to NPM
id: publish
uses: JS-DevTools/npm-publish@v3
with:
check-version: true
token: ${{ secrets.NPM_TOKEN }}
package: ./build/package.json
tag: ${{ env.NPM_TAG }}
- if: steps.publish.outputs.type != 'none'
run: |
echo "Version changed: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}"
# if stable release
- name: Stable Release
if: env.RELEASING == 'stable'
run: echo "BRANCH_NAME=${MAJOR_VERSION}-stable" >> $GITHUB_ENV
# else (beta)
- name: Beta Release
if: env.RELEASING == 'beta'
run: echo "BRANCH_NAME=main" >> $GITHUB_ENV
- name: Confirm release is either stable or beta
if: ${{ !(env.RELEASING == 'stable' || env.RELEASING == 'beta') }}
run: |
echo We seem to be releasing `${RELEASING}`.
false
- name: Checkout cdn-release
uses: actions/checkout@v4
with:
repository: 'highlightjs/cdn-release'
path: 'cdn-release'
token: ${{ secrets.CDN_REPO_TOKEN }}
ref: ${{ env.BRANCH_NAME }}
- name: Build CDN package
run: node ./tools/build.js -t cdn :common
- name: Commmit & Push cdn-release ${{ env.TAG_NAME }}
working-directory: ./cdn-release
run: |
rm -r ./build
mv ../build/ ./build/
mv ./build/DIGESTS.md .
git config user.name github-actions
git config user.email github-actions@github.com
git add ./build/
git add ./DIGESTS.md
git commit -m'Update to version ${{ env.TAG_NAME }}'
git tag ${TAG_NAME}
git push -f --atomic origin ${BRANCH_NAME} ${TAG_NAME}
- name: Publish cdn-assets to NPM
id: publish_cdn
uses: JS-DevTools/npm-publish@v3
with:
check-version: true
token: ${{ secrets.NPM_TOKEN }}
package: ./cdn-release/build/package.json
tag: ${{ env.NPM_TAG }}
# log.info('Updating CDN repo at %s' % settings.HLJS_CDN_SOURCE)
# run(['nodejs', 'tools/build.js', '--target', 'cdn', ':common'])
# os.chdir(settings.HLJS_CDN_SOURCE)
# run(['git', 'pull', '-f'])
# lines = run(['git', '--git-dir', os.path.join(settings.HLJS_CDN_SOURCE, '.git'), 'tag'])
# build_dir = os.path.join(settings.HLJS_CDN_SOURCE, 'build')
# if version in lines:
# log.info('Tag %s already exists in the local CDN repo' % version)
# else:
# if os.path.exists(build_dir):
# shutil.rmtree(build_dir)
# shutil.move(os.path.join(settings.HLJS_SOURCE, 'build'), build_dir)
# run(['git', 'add', '.'])
# run(['git', 'commit', '-m', 'Update to version %s' % version])
# run(['git', 'tag', version])
# run(['git', 'push'])
# run(['git', 'push', '--tags'])
# npm_publish(build_dir)
# os.chdir(settings.HLJS_SOURCE)