Repository navigation
136 lines (126 loc) · 4.53 KB
/
Copy pathrelease.yml
File metadata and controls
136 lines (126 loc) · 4.53 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
# Releases a version when a tag like v1.0.1 is pushed:
# 1. checks that the tag, package.json and src/version.ts agree and that
# CHANGELOG.md has a section for the version, then runs every check;
# 2. publishes to npm with trusted publishing, unless that version is
# already there, with a provenance statement once the repository is public;
# 3. creates the GitHub release from the version's CHANGELOG.md section.
#
# Run it by hand from the Actions tab to rehearse: it runs every check and
# `npm publish --dry-run`, but publishes and releases nothing.
#
# One-time setup on npmjs.com, after the first version is published by hand:
# the package's Settings > Trusted publisher > GitHub Actions, for
# FlightByte-dev/flightbyte-node and the workflow release.yml.
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
check:
name: Check versions, notes and code
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
published: ${{ steps.version.outputs.published }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- id: version
name: Compare versions
run: |
version="$(node -p "require('./package.json').version")"
name="$(node -p "require('./package.json').name")"
if [[ "$GITHUB_REF_TYPE" == tag && "$GITHUB_REF_NAME" != "v$version" ]]; then
echo "::error::Tag $GITHUB_REF_NAME does not match version $version in package.json."
exit 1
fi
if ! grep -qx "export const VERSION = '$version';" src/version.ts; then
echo "::error::src/version.ts does not say $version."
exit 1
fi
published=false
if npm view "$name@$version" version > /dev/null 2>&1; then published=true; fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "published=$published" >> "$GITHUB_OUTPUT"
echo "Version $version, already on npm: $published"
- name: Release notes
run: |
{
echo "## Release notes for ${{ steps.version.outputs.version }}"
echo
tool/release_notes.sh "${{ steps.version.outputs.version }}"
} >> "$GITHUB_STEP_SUMMARY"
- run: npm ci
- run: npm run check
publish:
name: npm
needs: check
if: needs.check.outputs.published == 'false'
runs-on: ubuntu-latest
permissions:
contents: read
# Trusted publishing: npm exchanges this for a short-lived token.
id-token: write
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
registry-url: https://registry.npmjs.org
cache: npm
# Trusted publishing needs npm 11.5.1 or later.
- run: npm install --global npm@latest
- run: npm ci
- run: npm run build
- name: Rehearse
if: github.event_name != 'push'
run: npm publish --dry-run
- name: Publish
if: github.event_name == 'push'
env:
# npm can attest provenance only for a public repository.
PROVENANCE: ${{ github.event.repository.private == false && '--provenance' || '' }}
run: |
tag=latest
[[ "${{ needs.check.outputs.version }}" == *-* ]] && tag=next
npm publish --access public --tag "$tag" $PROVENANCE
release:
name: GitHub release
needs: [check, publish]
if: >-
always() &&
github.event_name == 'push' &&
needs.check.result == 'success' &&
(needs.publish.result == 'success' || needs.publish.result == 'skipped')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- name: Create the release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.check.outputs.version }}
run: |
if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then
echo "Release $GITHUB_REF_NAME already exists."
exit 0
fi
tool/release_notes.sh "$VERSION" > "$RUNNER_TEMP/notes.md"
flags=()
[[ "$VERSION" == *-* ]] && flags+=(--prerelease)
gh release create "$GITHUB_REF_NAME" \
--title "$GITHUB_REF_NAME" \
--notes-file "$RUNNER_TEMP/notes.md" \
--verify-tag \
"${flags[@]}"