Repository navigation
69 lines (64 loc) · 2.48 KB
/
Copy pathrelease.yml
File metadata and controls
69 lines (64 loc) · 2.48 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
name: release
# Every npm version needs a GitHub Release. When a version lands on main, this
# creates the matching release from its CHANGELOG.md section, so the release no
# longer depends on someone remembering to create it.
on:
push:
branches: [main]
paths: [package.json]
workflow_dispatch:
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
github-release:
# A manual run from another branch would tag an unmerged commit as the release.
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
with:
fetch-depth: 0
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5
with:
node-version: 22
- id: package
run: |
echo "name=$(node -p "require('./package.json').name")" >> "$GITHUB_OUTPUT"
echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
- id: existing
env:
GH_TOKEN: ${{ github.token }}
TAG: v${{ steps.package.outputs.version }}
run: |
if gh release view "$TAG" > /dev/null 2>&1; then
echo "Release $TAG already exists."
echo "found=true" >> "$GITHUB_OUTPUT"
else
echo "found=false" >> "$GITHUB_OUTPUT"
fi
- if: steps.existing.outputs.found == 'false'
run: npm test
- if: steps.existing.outputs.found == 'false'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.package.outputs.version }}
run: |
awk -v heading="## $VERSION " 'index($0, heading) == 1 { found = 1; next } /^## / { found = 0 } found' CHANGELOG.md \
| sed '/./,$!d' > release-notes.md
if ! grep -q '[^[:space:]]' release-notes.md; then
echo "::error file=CHANGELOG.md::CHANGELOG.md has no section for $VERSION."
exit 1
fi
gh release create "v$VERSION" --target "$GITHUB_SHA" --title "v$VERSION" --notes-file release-notes.md
- env:
PACKAGE: ${{ steps.package.outputs.name }}
VERSION: ${{ steps.package.outputs.version }}
run: |
if npm view "$PACKAGE@$VERSION" version > /dev/null 2>&1; then
echo "$PACKAGE@$VERSION is on npm."
else
echo "::warning::$PACKAGE@$VERSION is not on npm yet. Publish it so the release and the package match."
fi