-
Notifications
You must be signed in to change notification settings - Fork 0
276 lines (234 loc) · 8.68 KB
/
Copy pathrelease.yml
File metadata and controls
276 lines (234 loc) · 8.68 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
---
# yamllint disable rule:line-length
name: "Release"
'on':
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
# Allow manual trigger for testing (will do a dry-run)
workflow_dispatch:
inputs:
dry_run:
description: 'Perform dry-run (do not create release)'
required: false
default: 'true'
type: choice
options:
- 'true'
- 'false'
# Prevent concurrent releases
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false # Don't cancel in-progress releases
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # Need full history for release notes
- uses: actions/setup-node@v6
with:
node-version: 26.x
cache: 'npm'
- name: Security Audit
run: npm audit --audit-level=moderate
- name: Install Dependencies and Build
run: |
npm ci --prefer-offline
npm run deploy
- name: Generate SBOM
run: npm sbom --sbom-format=cyclonedx --omit=dev > sbom.json
- name: Verify Tag Matches Package Version
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
# For tag pushes, verify tag matches package.json
if [ "${{ github.event_name }}" = "push" ]; then
TAG_VERSION="${GITHUB_REF#refs/tags/}"
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
echo "Error: Git tag ($TAG_VERSION) does not match package.json version ($PKG_VERSION)"
exit 1
fi
echo "Version verified: $TAG_VERSION"
else
# For manual triggers, verify the tag exists
if ! git rev-parse "$PKG_VERSION" >/dev/null 2>&1; then
echo "Error: Tag $PKG_VERSION does not exist. Available tags:"
git tag -l | tail -5
exit 1
fi
echo "Using package.json version: $PKG_VERSION"
fi
- name: Create Release Archive
run: |
# Determine version to use
if [ "${{ github.event_name }}" = "push" ]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION=$(node -p "require('./package.json').version")
fi
mkdir -p release-artifacts
tar -czf "release-artifacts/openinlets-$VERSION.tar.gz" \
dist/*.bookmarklet \
README.md \
LICENSE \
SECURITY.md \
package.json
# Copy individual bookmarklets
cp dist/*.bookmarklet release-artifacts/
# Save version for next steps
echo "RELEASE_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Generate Release Notes
id: release_notes
run: |
# Determine version to use
if [ "${{ github.event_name }}" = "push" ]; then
TAG_VERSION="${GITHUB_REF#refs/tags/}"
else
TAG_VERSION=$(node -p "require('./package.json').version")
fi
PREV_TAG=$(git describe --abbrev=0 --tags "${TAG_VERSION}^" 2>/dev/null || echo "")
{
if [ -n "$PREV_TAG" ]; then
echo "## What's Changed"
echo ""
git log --pretty=format:"- %s (%h)" "$PREV_TAG..HEAD"
else
echo "## Release $TAG_VERSION"
echo ""
echo "Initial release"
fi
echo ""
echo "## Verification"
echo ""
echo "This release includes:"
echo "- Signed commits and tags (verify with \`git verify-tag $TAG_VERSION\`)"
echo "- Software Bill of Materials (SBOM) in CycloneDX format"
echo "- Security audit results from CI pipeline"
echo ""
echo "See [SECURITY.md](SECURITY.md) for verification procedures."
} > release-notes.md
- name: Create GitHub Release (dry-run)
if: github.event_name == 'workflow_dispatch' && inputs.dry_run == 'true'
run: |
echo "🧪 Dry-run mode - not actually creating release"
echo "Would create release: OpenInlets ${{ env.RELEASE_VERSION }}"
echo ""
echo "Release notes preview:"
cat release-notes.md
echo ""
echo "Release assets that would be uploaded:"
ls -lh release-artifacts/*.tar.gz sbom.json
echo ""
echo "✓ Dry-run successful - release would be created"
- name: Create GitHub Release
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.dry_run == 'false')
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create ${{ env.RELEASE_VERSION }} \
--title "OpenInlets ${{ env.RELEASE_VERSION }}" \
--notes-file release-notes.md \
--verify-tag \
release-artifacts/*.tar.gz \
sbom.json
- name: Upload Release Artifacts
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.dry_run == 'false')
uses: actions/upload-artifact@v7
with:
name: release-${{ env.RELEASE_VERSION }}
path: |
release-artifacts/
sbom.json
retention-days: 90
deploy-gh-pages:
permissions:
contents: write
runs-on: ubuntu-latest
needs: release
timeout-minutes: 8
# Only deploy gh-pages on actual releases, not dry-runs
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.dry_run == 'false')
steps:
- name: Checkout Tag
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
path: release-source
- uses: actions/setup-node@v6
with:
node-version: 26.x
cache: 'npm'
cache-dependency-path: release-source/package-lock.json
- name: Determine Release Version
run: |
cd release-source
if [ "${{ github.event_name }}" = "push" ]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION=$(node -p "require('./package.json').version")
fi
echo "RELEASE_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Build README.md
run: |
cd release-source
npm ci --prefer-offline
npm run deploy
- name: Verify README.md Exists and is Valid
run: |
if [ ! -f release-source/README.md ]; then
echo "Error: README.md not found in release"
exit 1
fi
FILE_SIZE=$(stat -c%s release-source/README.md 2>/dev/null || stat -f%z release-source/README.md)
if [ "$FILE_SIZE" -lt 100 ]; then
echo "Error: README.md is too small (possible corruption)"
exit 1
fi
echo "README.md verified: $FILE_SIZE bytes"
- name: Checkout gh-pages Branch
uses: actions/checkout@v6
with:
ref: gh-pages
path: gh-pages-branch
fetch-depth: 0
- name: Update index.md in gh-pages
run: |
cd gh-pages-branch
# Verify we're on gh-pages branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "gh-pages" ]; then
echo "Error: Not on gh-pages branch (on $CURRENT_BRANCH)"
exit 1
fi
# Copy README.md to index.md
cp ../release-source/README.md index.md
# Verify the copy succeeded and has content
if [ ! -f index.md ] || [ ! -s index.md ]; then
echo "Error: index.md copy failed or is empty"
exit 1
fi
# Check if there are changes
if git diff --quiet index.md; then
echo "No changes to index.md, skipping commit"
exit 0
fi
# Configure git (using GitHub Actions bot)
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Commit and push
git add index.md
git commit -m "chore(docs): update index.md for release ${{ env.RELEASE_VERSION }}
Auto-updated from README.md via release workflow
Source: ${{ github.sha }}
🤖 Generated with GitHub Actions"
# Verify commit was created
if ! git log -1 --pretty=format:"%s" | grep -q "update index.md"; then
echo "Error: Commit was not created properly"
exit 1
fi
git push origin gh-pages
echo "✓ Successfully updated gh-pages index.md for release ${{ env.RELEASE_VERSION }}"