-
Notifications
You must be signed in to change notification settings - Fork 0
257 lines (213 loc) · 6.9 KB
/
Copy pathdeploy-pages.yml
File metadata and controls
257 lines (213 loc) · 6.9 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
name: Deploy GitHub Pages
on:
push:
branches:
- main
workflow_dispatch:
inputs:
bump:
description: "Version bump"
required: true
default: "auto"
type: choice
options:
- auto
- patch
- minor
- major
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: github-pages
cancel-in-progress: false
jobs:
version:
name: Prepare SemVer release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.bump.outputs.version }}
tag: ${{ steps.bump.outputs.tag }}
bump: ${{ steps.bump.outputs.bump }}
sha: ${{ steps.bump.outputs.sha }}
build_time: ${{ steps.bump.outputs.build_time }}
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Calculate and commit next version
id: bump
env:
BUMP_INPUT: ${{ github.event.inputs.bump || 'auto' }}
run: |
set -euo pipefail
git fetch --tags --force
LAST_TAG="$(git describe --tags --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' 2>/dev/null || true)"
if [ -n "$LAST_TAG" ]; then
BASE_VERSION="${LAST_TAG#v}"
COMMITS="$(git log "${LAST_TAG}..HEAD" --pretty=format:'%s%n%b')"
else
BASE_VERSION="$(node -p "require('./package.json').version || '0.0.0'")"
COMMITS="$(git log --pretty=format:'%s%n%b')"
fi
if [ "$BUMP_INPUT" != "auto" ]; then
BUMP="$BUMP_INPUT"
elif printf '%s\n' "$COMMITS" | grep -Eiq '\[major\]|BREAKING CHANGE|^[a-z]+(\([^)]+\))?!:'; then
BUMP="major"
elif printf '%s\n' "$COMMITS" | grep -Eiq '\[minor\]|^feat(\([^)]+\))?:|^feature(\([^)]+\))?:'; then
BUMP="minor"
else
BUMP="patch"
fi
IFS='.' read -r MAJOR MINOR PATCH <<VERSION_PARTS
$BASE_VERSION
VERSION_PARTS
MAJOR="${MAJOR:-0}"
MINOR="${MINOR:-0}"
PATCH="${PATCH:-0}"
case "$BUMP" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
*)
echo "Unknown bump type: $BUMP"
exit 1
;;
esac
NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}"
NEXT_TAG="v${NEXT_VERSION}"
if git rev-parse "$NEXT_TAG" >/dev/null 2>&1; then
echo "Tag already exists: $NEXT_TAG"
exit 1
fi
npm version "$NEXT_VERSION" --no-git-tag-version --allow-same-version
git add package.json
if [ -f package-lock.json ]; then
git add package-lock.json
fi
git commit -m "chore(release): ${NEXT_TAG} [skip ci]"
git tag -a "$NEXT_TAG" -m "$NEXT_TAG"
git push origin HEAD:main
git push origin "$NEXT_TAG"
BUILD_TIME="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
RELEASE_SHA="$(git rev-parse HEAD)"
echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$NEXT_TAG" >> "$GITHUB_OUTPUT"
echo "bump=$BUMP" >> "$GITHUB_OUTPUT"
echo "sha=$RELEASE_SHA" >> "$GITHUB_OUTPUT"
echo "build_time=$BUILD_TIME" >> "$GITHUB_OUTPUT"
build:
name: Build static PWA
needs: version
runs-on: ubuntu-latest
steps:
- name: Checkout release tag
uses: actions/checkout@v5
with:
ref: ${{ needs.version.outputs.tag }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
env:
VITE_APP_VERSION: ${{ needs.version.outputs.version }}
VITE_APP_VERSION_TAG: ${{ needs.version.outputs.tag }}
VITE_APP_BUILD_SHA: ${{ needs.version.outputs.sha }}
VITE_APP_BUILD_TIME: ${{ needs.version.outputs.build_time }}
run: npm run build
- name: Add build version metadata
env:
APP_VERSION: ${{ needs.version.outputs.version }}
APP_VERSION_TAG: ${{ needs.version.outputs.tag }}
APP_VERSION_BUMP: ${{ needs.version.outputs.bump }}
APP_BUILD_SHA: ${{ needs.version.outputs.sha }}
APP_BUILD_TIME: ${{ needs.version.outputs.build_time }}
run: |
node <<'NODE'
const fs = require('fs');
const versionInfo = {
name: 'auditm-field',
version: process.env.APP_VERSION,
tag: process.env.APP_VERSION_TAG,
bump: process.env.APP_VERSION_BUMP,
sha: process.env.APP_BUILD_SHA,
builtAt: process.env.APP_BUILD_TIME,
};
fs.writeFileSync('dist/version.json', JSON.stringify(versionInfo, null, 2) + '\n');
NODE
- name: Add SPA fallback
run: cp dist/index.html dist/404.html
- name: Configure GitHub Pages
uses: actions/configure-pages@v5
- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v5
with:
path: dist
deploy:
name: Deploy static PWA
needs:
- version
- build
runs-on: ubuntu-latest
outputs:
page_url: ${{ steps.deployment.outputs.page_url }}
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
release:
name: Create GitHub Release
needs:
- version
- deploy
runs-on: ubuntu-latest
steps:
- name: Checkout release tag
uses: actions/checkout@v5
with:
ref: ${{ needs.version.outputs.tag }}
fetch-depth: 0
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ needs.version.outputs.tag }}
PAGE_URL: ${{ needs.deploy.outputs.page_url }}
VERSION_BUMP: ${{ needs.version.outputs.bump }}
BUILD_SHA: ${{ needs.version.outputs.sha }}
run: |
gh release create "$RELEASE_TAG" \
--repo "$GITHUB_REPOSITORY" \
--target "$BUILD_SHA" \
--title "$RELEASE_TAG" \
--notes "AuditM-Field GitHub Pages deployment.
Version bump: $VERSION_BUMP
Commit: $BUILD_SHA
Deployed URL: $PAGE_URL"