-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (178 loc) · 6.45 KB
/
Copy pathrelease.yml
File metadata and controls
212 lines (178 loc) · 6.45 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Release version (e.g. 0.4.7). Defaults to auto-bump from latest tag."
required: false
type: string
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
permissions:
contents: write
pull-requests: write
jobs:
test:
uses: ./.github/workflows/test.yml
derive-version:
needs: test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.bump.outputs.version }}
steps:
- uses: actions/checkout@v5
- name: Derive version from latest release and package
id: bump
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
git fetch --tags origin
API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest"
RESPONSE=$(curl -sS -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" -w "\n%{http_code}" "${API_URL}")
BODY=$(printf '%s' "${RESPONSE}" | sed '$d')
STATUS=$(printf '%s' "${RESPONSE}" | tail -n1)
if [[ "${STATUS}" == "200" ]]; then
LATEST_TAG=$(printf '%s' "${BODY}" | jq -r '.tag_name // empty')
elif [[ "${STATUS}" == "404" ]]; then
LATEST_TAG=""
else
echo "Failed to query latest release (HTTP ${STATUS})."
printf '%s\n' "${BODY}"
exit 1
fi
if [[ -n "${{ inputs.version }}" ]]; then
NEW_VERSION="${{ inputs.version }}"
else
if [[ -z "${LATEST_TAG}" ]]; then
BASE_VERSION="0.0.0"
elif [[ "${LATEST_TAG}" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
BASE_VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
else
echo "Unsupported release tag format: ${LATEST_TAG} (expected vX.Y.Z)"
exit 1
fi
IFS='.' read -r major minor patch <<< "${BASE_VERSION}"
NEW_VERSION="${major}.${minor}.$((patch + 1))"
fi
if git ls-remote --exit-code --tags origin "refs/tags/v${NEW_VERSION}" >/dev/null 2>&1; then
echo "Refusing to release: tag v${NEW_VERSION} already exists."
exit 1
fi
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
build-chrome:
needs: derive-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Build Chrome extension
run: |
set -euo pipefail
VERSION="${{ needs.derive-version.outputs.version }}"
echo "Building Chrome version: ${VERSION}"
npm ci
npm run build:release:chrome -- --version="${VERSION}"
- name: Upload Chrome zip
uses: actions/upload-artifact@v4
with:
name: chrome-zip
path: correctly-chrome.zip
build-firefox:
needs: derive-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Build Firefox extension
run: |
set -euo pipefail
VERSION="${{ needs.derive-version.outputs.version }}"
echo "Building Firefox version: ${VERSION}"
npm ci
npm run build:release:firefox -- --version="${VERSION}"
- name: Upload Firefox source directory
uses: actions/upload-artifact@v4
with:
name: dist-firefox
path: dist/correctly/
bump-version:
needs: derive-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Open version bump PR
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
VERSION="${{ needs.derive-version.outputs.version }}"
BRANCH="chore/bump-v${VERSION}"
jq --arg v "${VERSION}" '.version = $v' manifest.base.json > manifest.base.json.tmp
mv manifest.base.json.tmp manifest.base.json
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "${BRANCH}"
git add manifest.base.json
git commit -m "chore: bump version to ${VERSION}"
git push origin "${BRANCH}" --force
gh pr create \
--base main \
--head "${BRANCH}" \
--title "chore: bump version to ${VERSION}" \
--body "Automated version bump from release workflow."
sign:
needs: build-firefox
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Download Firefox source directory
uses: actions/download-artifact@v4
with:
name: dist-firefox
path: dist/correctly/
- name: Verify built manifest version
run: |
echo "Manifest version: $(jq -r '.version // "MISSING"' dist/correctly/manifest.json)"
echo "Extension ID: $(jq -r '.browser_specific_settings.gecko.id // "MISSING"' dist/correctly/manifest.json)"
- name: Sign Firefox add-on on AMO (unlisted)
run: |
set -euo pipefail
rm -f dist/correctly/.amo-upload-uuid dist/correctly/.web-extension-id
npx --yes web-ext sign \
--source-dir dist/correctly \
--channel=unlisted \
--api-key "${{ secrets.AMO_API_KEY }}" \
--api-secret "${{ secrets.AMO_API_SECRET }}"
- name: Normalize signed Firefox artifact name
run: |
set -euo pipefail
SIGNED_XPI=$(find . -maxdepth 3 -type f -name '*.xpi' | grep -v node_modules | head -n1)
if [[ -z "${SIGNED_XPI}" ]]; then
echo "Signed XPI not found"
exit 1
fi
cp "${SIGNED_XPI}" correctly-firefox.xpi
- name: Upload signed XPI
uses: actions/upload-artifact@v4
with:
name: signed-xpi
path: correctly-firefox.xpi
release:
needs: [derive-version, build-chrome, sign]
runs-on: ubuntu-latest
steps:
- name: Download Chrome zip
uses: actions/download-artifact@v4
with:
name: chrome-zip
- name: Download signed XPI
uses: actions/download-artifact@v4
with:
name: signed-xpi
- uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.derive-version.outputs.version }}
name: v${{ needs.derive-version.outputs.version }}
files: |
correctly-chrome.zip
correctly-firefox.xpi
generate_release_notes: true