This repository was archived by the owner on Mar 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (86 loc) · 3.08 KB
/
publish.yml
File metadata and controls
103 lines (86 loc) · 3.08 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
name: Publish
run-name: "${{ github.workflow }} (${{ github.sha }})"
on:
workflow_dispatch:
defaults:
run:
shell: bash
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
id-token: write
jobs:
publish:
name: Publish package
runs-on: ubuntu-latest
timeout-minutes: 3
environment: npm-registry
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Checkout Repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
token: ${{ steps.generate_token.outputs.token }}
- name: Initialize
uses: ./.github/actions/setup-environment
- name: Validate and build package
run: bun run prepare:publish
- name: Setup Node.js
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with:
node-version: lts/*
registry-url: "https://registry.npmjs.org"
- name: Install latest npm
run: npm install -g npm@latest
- name: Read version
id: version
run: |
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Extract changelog section
id: changelog
run: |
VERSION="v${{ steps.version.outputs.version }}"
BODY=$(awk "/^## \[$VERSION\]/{found=1; next} found && /^## /{exit} found{print}" CHANGELOG.md)
BODY=$(echo "$BODY" | awk 'NF{found=1} found' | awk '{a[NR]=$0} NF{last=NR} END{for(i=1;i<=last;i++) print a[i]}')
if [ -z "$BODY" ]; then
echo "::warning::No changelog section found for $VERSION in CHANGELOG.md"
fi
{
echo "body<<EOF"
echo "$BODY"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Ensure version not published
run: |
VERSION="v${{ steps.version.outputs.version }}"
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Tag $VERSION already exists"
exit 1
fi
- name: Publish to npm
run: npm publish --provenance --access public
- name: Create and push tag
run: |
git tag "v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANGELOG_BODY: ${{ steps.changelog.outputs.body }}
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/releases" \
-f tag_name="v${{ steps.version.outputs.version }}" \
-f body="$CHANGELOG_BODY" \
-F draft=true \
-F generate_release_notes=true