forked from EdgeTTS/EdgeTTS.github.io
-
Notifications
You must be signed in to change notification settings - Fork 2
200 lines (169 loc) · 6.38 KB
/
Copy pathdeploy.yml
File metadata and controls
200 lines (169 loc) · 6.38 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
name: Deploy to GitHub Pages
on:
push:
branches: [master]
# Minimum permissions needed: write for Pages deployment, id-token for OIDC.
permissions:
contents: write
pages: write
id-token: write
# Allow only one concurrent deployment. New pushes queue rather than
# cancelling a running deployment mid-flight.
concurrency:
group: pages
cancel-in-progress: false
jobs:
# ---------------------------------------------------------------------------
# Enumerate all v* semver tags so the matrix below can be generated
# dynamically. Produces a JSON array like ["v1.0.0","v1.1.0"].
# ---------------------------------------------------------------------------
list-tags:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.tags.outputs.list }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # full history is required to see all tags
- name: Collect v* tags as a sorted JSON array
id: tags
# `git tag -l` may return nothing; `jq -s` always produces at least '[]'.
# `sort -V` ensures natural version ordering (v1.9 < v1.10).
run: |
LIST=$(git tag -l 'v*' | sort -V | jq -R . | jq -s -c .)
echo "list=$LIST" >> "$GITHUB_OUTPUT"
# ---------------------------------------------------------------------------
# Build the current master branch into the "latest" deployment slot.
# ---------------------------------------------------------------------------
build-latest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # needed for git-based version stamps, if any
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build and stage latest
shell: bash
run: |
set -euo pipefail
npm run build
# Guard: fail loudly if the build didn't produce the expected output.
[[ -d dist/latest ]] || { echo "::error::dist/latest not found after build"; exit 1; }
[[ -f dist/404.html ]] || { echo "::error::dist/404.html not found after build"; exit 1; }
mkdir -p "deploy/sha"
cp -r dist/latest "deploy/sha/${GITHUB_SHA}"
cp dist/404.html deploy/404.html
- uses: actions/upload-artifact@v4
with:
name: deploy-sha-${{ github.sha }}
path: deploy/
# ---------------------------------------------------------------------------
# Build each tagged release into its own versioned deployment slot.
# Each tag is cached so repeated deployments are cheap.
# Skipped entirely when there are no v* tags.
# ---------------------------------------------------------------------------
build-tags:
needs: list-tags
if: needs.list-tags.outputs.tags != '[]'
runs-on: ubuntu-latest
strategy:
matrix:
tag: ${{ fromJSON(needs.list-tags.outputs.tags) }}
fail-fast: false # one bad tag should not block all others
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Restore cached build for ${{ matrix.tag }}
id: tag-cache
uses: actions/cache@v4
with:
path: deploy/${{ matrix.tag }}
key: tag-build-${{ matrix.tag }}
# Only rebuild if the cache was cold. The cached directory is uploaded
# as-is in the next step regardless.
- name: Build ${{ matrix.tag }}
if: steps.tag-cache.outputs.cache-hit != 'true'
shell: bash
run: |
set -euo pipefail
git checkout "${{ matrix.tag }}"
# Re-install deps for this tag's lockfile (may differ from master).
npm ci
npm run build
[[ -d dist/latest ]] || {
echo "::error::dist/latest not found after building ${{ matrix.tag }}"
exit 1
}
mkdir -p "deploy/${{ matrix.tag }}"
rm -rf "deploy/${{ matrix.tag }}"
cp -r dist/latest "deploy/${{ matrix.tag }}"
- uses: actions/upload-artifact@v4
with:
name: deploy-${{ matrix.tag }}
path: deploy/
# ---------------------------------------------------------------------------
# Merge all per-job artifacts and publish to GitHub Pages.
# Runs even when build-tags was skipped (no tags exist yet);
# fails only when build-latest itself failed.
# ---------------------------------------------------------------------------
deploy:
needs: [build-latest, build-tags]
if: always() && needs.build-latest.result == 'success'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
# `merge-multiple: true` flattens all deploy-* artifacts directly into
# `deploy/` without nesting, eliminating the need for a manual move loop.
- name: Download and merge all build artifacts
uses: actions/download-artifact@v4
with:
pattern: deploy-*
path: deploy/
merge-multiple: true
- name: Cleanup old SHA builds (keep newest 10)
env:
SHA_KEEP_COUNT: 50
shell: bash
run: |
if [[ -d deploy/sha ]]; then
cd deploy/sha
# List directories, sort (most recent = highest SHA first), skip the newest 10
ls -1d */ 2>/dev/null \
| sort -r \
| tail -n +$((SHA_KEEP_COUNT + 1)) \
| xargs -r rm -rf
echo "Cleaned up old SHA builds"
fi
- name: Write latest/ redirect stub for backward compatibility
shell: bash
run: |
mkdir -p deploy/latest
cat > deploy/latest/index.html << 'STUB'
<!DOCTYPE html>
<html>
<head><meta http-equiv="refresh" content="0;url=/"></head>
<body><p>Redirecting to <a href="/">EdgeTTS Builds</a>...</p></body>
</html>
STUB
- name: Generate version index page
run: node scripts/generate-index.js deploy ${{ github.sha }}
- uses: actions/configure-pages@v4
- uses: actions/upload-pages-artifact@v3
with:
path: deploy/
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4