-
Notifications
You must be signed in to change notification settings - Fork 1
167 lines (145 loc) · 4.96 KB
/
manual-release.yml
File metadata and controls
167 lines (145 loc) · 4.96 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Manual Release
on:
workflow_dispatch:
inputs:
version:
description: "Release version (for example: 0.2.0)"
required: true
type: string
draft:
description: "Create release as draft"
required: true
default: false
type: boolean
prerelease:
description: "Mark release as prerelease"
required: true
default: false
type: boolean
release_notes:
description: "Optional release notes body (leave empty to auto-generate)"
required: false
default: ""
type: string
permissions:
contents: write
concurrency:
group: manual-release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout latest main
uses: actions/checkout@v4
with:
ref: refs/heads/main
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Validate version input
run: |
VERSION="${{ inputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version: $VERSION"
echo "Expected numeric extension version, e.g. 0.2.0"
exit 1
fi
- name: Ensure tag does not exist
run: |
TAG="v${{ inputs.version }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists. Please choose a new version."
exit 1
fi
- name: Update package and manifest versions
run: |
VERSION="${{ inputs.version }}" node - <<'NODE'
const fs = require('node:fs');
const version = process.env.VERSION;
if (!version) {
throw new Error('VERSION is missing in environment');
}
const pkgPath = 'package.json';
const manifestPath = 'src/manifest.ts';
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
pkg.version = version;
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
const manifestRaw = fs.readFileSync(manifestPath, 'utf8');
const nextManifest = manifestRaw.replace(
/version:\s*'[^']*'/,
`version: '${version}'`
);
if (manifestRaw === nextManifest) {
throw new Error('Failed to update version in src/manifest.ts');
}
fs.writeFileSync(manifestPath, nextManifest);
NODE
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build
- name: Package extension
run: |
VERSION="${{ inputs.version }}"
ZIP_NAME="folio-extension-v${VERSION}.zip"
cd dist
zip -r "../${ZIP_NAME}" .
cd ..
sha256sum "${ZIP_NAME}" > "folio-extension-v${VERSION}.sha256.txt"
- name: Commit release version changes
id: commit_version
run: |
VERSION="${{ inputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json src/manifest.ts
if git diff --cached --quiet; then
echo "No version file changes to commit."
echo "changed=false" >> "$GITHUB_OUTPUT"
else
git commit -m "chore(release): v${VERSION}"
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Push version bump to main
if: steps.commit_version.outputs.changed == 'true'
run: git push origin HEAD:main
- name: Create and push tag
run: |
VERSION="${{ inputs.version }}"
TAG="v${VERSION}"
git tag "$TAG"
git push origin "$TAG"
- name: Create GitHub Release (manual notes)
if: inputs.release_notes != ''
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ inputs.version }}
target_commitish: main
name: v${{ inputs.version }}
body: ${{ inputs.release_notes }}
draft: ${{ inputs.draft }}
prerelease: ${{ inputs.prerelease }}
files: |
folio-extension-v${{ inputs.version }}.zip
folio-extension-v${{ inputs.version }}.sha256.txt
- name: Create GitHub Release (auto notes)
if: inputs.release_notes == ''
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ inputs.version }}
target_commitish: main
name: v${{ inputs.version }}
generate_release_notes: true
draft: ${{ inputs.draft }}
prerelease: ${{ inputs.prerelease }}
files: |
folio-extension-v${{ inputs.version }}.zip
folio-extension-v${{ inputs.version }}.sha256.txt