Repository navigation
111 lines (93 loc) · 3.71 KB
/
Copy pathrelease.yml
File metadata and controls
111 lines (93 loc) · 3.71 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
name: Create release
on:
workflow_dispatch:
inputs:
version:
required: true
type: choice
description: Which version should be published?
options: [patch, minor, major, prepatch, preminor, premajor, prerelease]
tag:
required: true
type: choice
description: Which npm tag should this be published to?
options: [latest, next]
jobs:
create-release:
runs-on: ubuntu-latest
environment: Publish package
permissions:
contents: write
id-token: write
steps:
- name: Generate Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.BOT_APP_ID }}
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
fetch-depth: 0
- name: Configure Git Identity
run: |
git config user.name "ambitiondev-release-bot[bot]"
git config user.email "ambitiondev-release-bot[bot]@users.noreply.github.com"
- name: Setup
uses: ./.github/actions/setup
- name: Ensure Latest NPM
run: npm install -g npm@latest
- name: Bump Root Changelog and Sync Packages
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
PRERELEASE_FLAG=""
if [[ "${{ github.event.inputs.version }}" == pre* ]]; then PRERELEASE_FLAG="--prerelease"; fi
# Only run changelogen at root: this updates root version + root changelog.
pnpm dlx changelogen@latest --bump $PRERELEASE_FLAG --${{ github.event.inputs.version }}
VERSION="$(node -p "require('./package.json').version")"
# Sync the same version to all packages/* package.json files.
for file in packages/*/package.json; do
node -e "const fs=require('fs');const p=process.argv[1];const v=process.argv[2];const j=JSON.parse(fs.readFileSync(p,'utf8'));j.version=v;fs.writeFileSync(p,JSON.stringify(j,null,2)+'\\n');" "$file" "$VERSION"
done
# Mirror the root changelog into each package changelog to keep one unified release note.
for file in packages/*/CHANGELOG.md; do
cp CHANGELOG.md "$file"
done
git add package.json CHANGELOG.md packages/*/package.json packages/*/CHANGELOG.md
git commit -m "chore(release): v$VERSION"
git tag "v$VERSION"
git push
git push --tags
- name: Build
run: pnpm -r --filter "./packages/*" run build
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
VERSION="$(node -p "require('./package.json').version")"
RELEASE_FLAG=""
if [[ "${{ github.event.inputs.version }}" == pre* ]]; then RELEASE_FLAG="--prerelease"; fi
# Extract the newest changelog section and prepend it to generated GitHub notes.
awk '
BEGIN { capture = 0 }
/^## / {
if (capture == 0) {
capture = 1
} else {
exit
}
}
capture == 1 { print }
' CHANGELOG.md > /tmp/release-notes.md
if [[ ! -s /tmp/release-notes.md ]]; then
cp CHANGELOG.md /tmp/release-notes.md
fi
gh release create "v$VERSION" --generate-notes --notes-file /tmp/release-notes.md $RELEASE_FLAG
- name: Publish to NPM
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
pnpm -r --filter "./packages/*" publish --provenance --access public --tag ${{ github.event.inputs.tag }} --no-git-checks