Repository navigation
199 lines (173 loc) · 6.83 KB
/
Copy pathpublish-release.yml
File metadata and controls
199 lines (173 loc) · 6.83 KB
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
name: publish-release
# Publishes the version in package.json when a release pull request from prepare-release.yml merges.
# The build job runs the dependency code and packs every release file, with read-only permissions.
# The publish job holds the publish credentials and runs no dependency code. It waits for approval
# in the `release` environment. Every publish step skips work that is already done, so a failed run
# can be run again. See RELEASE.md.
on:
push:
branches: [main]
paths: [package.json]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: publish-release
cancel-in-progress: false
jobs:
check:
runs-on: ubuntu-latest
outputs:
release: ${{ steps.check.outputs.release }}
version: ${{ steps.check.outputs.version }}
dist-tag: ${{ steps.check.outputs.dist-tag }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
fetch-tags: true
persist-credentials: false
- name: Decide whether this commit is a release
id: check
run: |
set -euo pipefail
VERSION=$(node -p "require('./package.json').version")
TAG="v$VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# A package.json change that keeps the version, such as a dependency update, is not a release
if git rev-parse -q --verify "refs/tags/$TAG" > /dev/null; then
if [ "$(git rev-list -n 1 "$TAG")" != "$(git rev-parse HEAD)" ]; then
echo "Tag $TAG is on another commit, so this commit is not a release"
echo "release=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Tag $TAG is on this commit. Resume the publish steps that did not finish."
fi
if [[ "$VERSION" == *-* ]]; then
PRERELEASE="${VERSION#*-}"
DIST_TAG="${PRERELEASE%%.*}"
else
DIST_TAG=latest
fi
echo "Release $VERSION with the npm dist-tag '$DIST_TAG'"
echo "release=true" >> "$GITHUB_OUTPUT"
echo "dist-tag=$DIST_TAG" >> "$GITHUB_OUTPUT"
build:
needs: check
if: needs.check.outputs.release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm ci
env:
NODE_OPTIONS: '--max-old-space-size=4096'
# Publish files built from the release commit, not the committed dist/
- name: Build dist/
run: npm run build
env:
NODE_OPTIONS: '--max-old-space-size=4096'
- name: Pack the release files
run: |
set -euo pipefail
mkdir -p build/release/packages
npm pack --pack-destination build/release/packages
npm run sync-packages -- --pack build/release/packages
./tasks/cdn_publish.sh --prepare-only
node tasks/release_notes.mjs > build/release/notes.md
ls -l build/release/packages
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: release-files
path: |
build/release
build/sync
if-no-files-found: error
# Dependency code can read every credential in its job, so this job installs no dependencies and runs no build
publish:
needs: [check, build]
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
id-token: write
env:
VERSION: ${{ needs.check.outputs.version }}
DIST_TAG: ${{ needs.check.outputs.dist-tag }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
# Trusted publishing needs npm 11.5.1 or later, and Node.js 22 ships npm 10
- name: Install npm 11
run: npm install -g npm@11
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: release-files
path: build
- name: Tag the release
run: |
set -euo pipefail
if git rev-parse -q --verify "refs/tags/v$VERSION" > /dev/null; then
echo "Tag v$VERSION already exists"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "v$VERSION" -m "v$VERSION"
git push origin "v$VERSION"
- name: Publish the packages to npm
run: |
set -euo pipefail
cd build/release/packages
# Publish plotly.js first, then the bundle and locale packages
for FILE in "plotly.js-$VERSION.tgz" $(ls -- *.tgz | grep -vxF "plotly.js-$VERSION.tgz"); do
NAME="${FILE%-"$VERSION".tgz}"
if npm view "$NAME@$VERSION" version > /dev/null 2>&1; then
echo "Skip $NAME@$VERSION, which is already on npm"
continue
fi
npm publish "$FILE" --tag "$DIST_TAG"
done
- name: Configure AWS credentials for the CDN
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: ${{ vars.CDN_AWS_ROLE_ARN }}
aws-region: ${{ vars.CDN_AWS_REGION }}
- name: Upload the bundles to the CDN
run: |
set -euo pipefail
./tasks/cdn_publish.sh --upload-only
for FILE in "plotly-$VERSION.js" "plotly-$VERSION.min.js"; do
curl --fail --silent --show-error --head "https://cdn.plot.ly/$FILE" > /dev/null
done
- name: Create the GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
if gh release view "v$VERSION" > /dev/null 2>&1; then
echo "GitHub release v$VERSION already exists"
exit 0
fi
FLAGS=()
if [[ "$VERSION" == *-* ]]; then FLAGS+=(--prerelease); fi
gh release create "v$VERSION" --verify-tag --title "v$VERSION" --notes-file build/release/notes.md "${FLAGS[@]}"
- name: Write the run summary
run: |
{
echo "### Published plotly.js v$VERSION"
echo "- npm dist-tag: \`$DIST_TAG\`"
echo "- GitHub release: https://github.com/${{ github.repository }}/releases/tag/v$VERSION"
} >> "$GITHUB_STEP_SUMMARY"