-
Notifications
You must be signed in to change notification settings - Fork 2
119 lines (103 loc) · 4.28 KB
/
release.yml
File metadata and controls
119 lines (103 loc) · 4.28 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., 1.3.0 or 2.0.0-beta.1)'
required: true
type: string
permissions:
contents: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
steps:
# ── Setup ──────────────────────────────────
- uses: actions/checkout@v4
with:
token: ${{ secrets.RELEASE_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
registry-url: https://registry.npmjs.org
- run: npm ci
# ── Validate ───────────────────────────────
- name: Validate version format
run: |
if ! echo "${{ inputs.version }}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$'; then
echo "::error::Invalid version format. Use semver (e.g., 1.3.0 or 2.0.0-beta.1)"
exit 1
fi
- name: Check tag doesn't exist
run: |
if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then
echo "::error::Tag v${{ inputs.version }} already exists"
exit 1
fi
# ── Bump version ───────────────────────────
- name: Bump version in all files
run: npx tsx scripts/bump-version.ts ${{ inputs.version }} > release-notes.md
# ── Build & Test ───────────────────────────
- run: npm run build
- run: npm test
- name: Verify CLI version output
run: |
ACTUAL=$(node dist/cli.js --version)
if [ "$ACTUAL" != "${{ inputs.version }}" ]; then
echo "::error::CLI reports $ACTUAL, expected ${{ inputs.version }}"
exit 1
fi
# ── Commit & Tag ───────────────────────────
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit version bump (if files changed)
run: |
git add -A
if git diff --cached --quiet; then
echo "No changes to commit (version already bumped)"
else
git commit -m "chore: bump version to ${{ inputs.version }}"
git push origin main
fi
- name: Create and push tag
run: |
git tag -a "v${{ inputs.version }}" -m "Version ${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
# ── Publish to npm ─────────────────────────
- name: Determine npm tag
id: npm-tag
run: |
if echo "${{ inputs.version }}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "tag=latest" >> "$GITHUB_OUTPUT"
else
PRE=$(echo "${{ inputs.version }}" | sed 's/^[0-9]*\.[0-9]*\.[0-9]*-//' | sed 's/\..*//')
echo "tag=$PRE" >> "$GITHUB_OUTPUT"
fi
- name: Publish to npm
run: npm publish --provenance --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ── GitHub Release ─────────────────────────
- name: Create GitHub release
run: |
PRERELEASE_FLAG=""
if echo "${{ inputs.version }}" | grep -qE '-'; then
PRERELEASE_FLAG="--prerelease"
fi
gh release create "v${{ inputs.version }}" \
--title "v${{ inputs.version }}" \
--notes-file release-notes.md \
$PRERELEASE_FLAG
env:
GH_TOKEN: ${{ github.token }}
# ── Restore [Unreleased] ───────────────────
- name: Restore [Unreleased] section
run: |
sed -i "s/^## \[${{ inputs.version }}\]/## [Unreleased]\n\n---\n\n## [${{ inputs.version }}]/" CHANGELOG.md
git add CHANGELOG.md
git commit -m "chore: restore [Unreleased] section"
git push origin main