-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (88 loc) · 3.93 KB
/
Copy pathrelease.yml
File metadata and controls
90 lines (88 loc) · 3.93 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
name: Release
# Editor-style dispatch release (plan 023):
# gh workflow run release.yml -f bump=patch|minor|major
# Bumps packages/lingo, runs the full gate, publishes to npm with provenance,
# then tags and creates the GitHub release.
on:
workflow_dispatch:
inputs:
bump:
description: Version bump
required: true
type: choice
options: [patch, minor, major]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.14
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
- run: bun install --frozen-lockfile
- run: bun run --filter @pascal-app/lingo check
- name: Bump version + roll changelog
id: bump
working-directory: packages/lingo
run: |
# npm version walks up into the bun workspace root and rejects the
# `workspace:*` protocol — bump the version with plain node instead.
VERSION=$(BUMP="${{ inputs.bump }}" node -e '
const fs = require("node:fs")
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"))
const [major, minor, patch] = pkg.version.split(".").map(Number)
pkg.version =
process.env.BUMP === "major" ? `${major + 1}.0.0`
: process.env.BUMP === "minor" ? `${major}.${minor + 1}.0`
: `${major}.${minor}.${patch + 1}`
fs.writeFileSync("package.json", `${JSON.stringify(pkg, null, 2)}\n`)
process.stdout.write(pkg.version)
')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# Promote the [Unreleased] section to a dated version heading, leaving
# a fresh empty [Unreleased] on top (conventions.md docs-surface rule).
# VERSION reaches the script via env, not shell interpolation into JS.
VERSION="$VERSION" node -e '
const fs = require("node:fs")
const p = "CHANGELOG.md"
const date = new Date().toISOString().slice(0, 10)
const src = fs.readFileSync(p, "utf8")
fs.writeFileSync(p, src.replace(
/## \[Unreleased\]/,
"## [Unreleased]\n\n## [" + process.env.VERSION + "] - " + date))
'
- name: Publish (provenance)
run: npx --yes npm@11.12.1 publish --provenance --access public
working-directory: packages/lingo
- name: Commit, tag, release
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add packages/lingo/package.json packages/lingo/CHANGELOG.md
git commit -m "chore(release): v$VERSION"
git tag "v$VERSION"
git push origin HEAD --tags
# Release body = the curated changelog section, never an auto commit
# list. The notes file lives in RUNNER_TEMP so it can't be committed,
# and reaches gh via --notes-file: the changelog is full of backticks
# and quotes that would execute or break quoting if interpolated.
# npm has already published by this point, so a missing or empty
# section falls back to --generate-notes rather than failing the run.
NOTES="$RUNNER_TEMP/release-notes.md"
if node packages/lingo/scripts/changelog-section.mjs "$VERSION" \
--changelog packages/lingo/CHANGELOG.md --out "$NOTES"; then
gh release create "v$VERSION" --title "v$VERSION" --notes-file "$NOTES"
else
echo "::warning::no changelog section for $VERSION; using generated notes"
gh release create "v$VERSION" --title "v$VERSION" --generate-notes
fi
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.bump.outputs.version }}