Repository navigation
96 lines (84 loc) · 3.43 KB
/
Copy pathrelease.yml
File metadata and controls
96 lines (84 loc) · 3.43 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
# Publishes to npm when a merge to main changes the package version.
#
# Shared verbatim by javascript-excel, react-data-export, react-data-import and
# react-xlsx-viewer; only PACKAGE_DIR differs. npm trusted publishing (OIDC)
# authenticates this exact file name, so it must stay `release.yml`, must not
# be called through workflow_call, and needs no NPM_TOKEN. Provenance is
# attached automatically. See RELEASING.md.
#
# workflow_dispatch is the recovery path: a manual run on main publishes the
# current version if it is not on npm yet, even when it did not change in the
# last commit (for example after a push whose release job failed before
# publishing). Dispatching runs this same file, which is what trusted
# publishing checks.
name: Release
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: write # git tag + GitHub Release
id-token: write # npm trusted publishing
concurrency:
group: release
cancel-in-progress: false
env:
PACKAGE_DIR: packages/javascript-excel
jobs:
release:
name: Release
# The npm environment is limited to main as well; this keeps a dispatch
# from another branch from even starting.
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: npm
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 2
- uses: actions/setup-node@v7
with:
node-version: 26
registry-url: https://registry.npmjs.org
- name: Detect release
id: check
run: node scripts/release-check.mjs --package "$PACKAGE_DIR" --event "${{ github.event_name }}" --notes-out "$RUNNER_TEMP/release-notes.md"
- name: Install
if: steps.check.outputs.release == 'true'
run: npm ci
# Same as ci.yml: test suites that compare against openpyxl require it
# when CI is set. Harmless where no test uses it.
- name: Python tools (openpyxl)
if: steps.check.outputs.release == 'true'
run: |
python3 -m venv "$RUNNER_TEMP/py"
"$RUNNER_TEMP/py/bin/pip" install --quiet openpyxl==3.1.5
echo "JSE_PYTHON=$RUNNER_TEMP/py/bin/python" >> "$GITHUB_ENV"
- name: Verify (typecheck, test, build)
if: steps.check.outputs.release == 'true'
run: |
npm run typecheck --if-present
npm test --if-present
npm run build --if-present
- name: Publish to npm
if: steps.check.outputs.release == 'true'
run: npm publish "./$PACKAGE_DIR" --tag "${{ steps.check.outputs.dist-tag }}"
# Runs whenever the version changed (or on a manual run), not only when
# this run published: a re-run after a successful publish but a failed
# `gh release create` then still creates the tag and Release. Already
# there: no-op.
- name: Tag and GitHub Release
if: steps.check.outputs.tag == 'true'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.check.outputs.version }}
PRERELEASE: ${{ steps.check.outputs.prerelease }}
run: |
if gh release view "v$VERSION" >/dev/null 2>&1; then
echo "Release v$VERSION already exists"
exit 0
fi
flags=()
if [ "$PRERELEASE" = "true" ]; then flags+=(--prerelease); else flags+=(--latest); fi
gh release create "v$VERSION" --target "$GITHUB_SHA" --title "v$VERSION" \
--notes-file "$RUNNER_TEMP/release-notes.md" "${flags[@]}"