Repository navigation
280 lines (256 loc) · 12.9 KB
/
Copy pathdeploy-github-pages.yml
File metadata and controls
280 lines (256 loc) · 12.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: "Deploy ePlus OnAir to GitHub Pages"
# Deploy only merged, trusted source. Never give publishing credentials to PRs.
# A successful skipped stale job must not be treated as a public release.
# Verify the exact branch HEAD again just before uploading generated Pages,
# because newer changes can land while a long full-site prerender is running.
# The integration source is staging; deprecated develop never triggers Pages publishing.
on:
push:
branches: [staging, main]
# Only changes to the delivered website justify regenerating thousands of
# station pages. Workflows, docs, tests and one-off crawlers do not.
paths:
- "app.vue"
# Workflow-only release fixes must be able to trigger deployment.
- ".github/workflows/deploy-github-pages.yml"
- "app.config.ts"
- "error.vue"
- "nuxt.config.ts"
- "package.json"
- "package-lock.json"
- "tsconfig.json"
- "assets/**"
- "build/**"
- "components/**"
- "composables/**"
- "config/**"
- "data/**"
- "lang/**"
- "layouts/**"
- "middleware/**"
- "pages/**"
- "plugins/**"
- "public/**"
- "server/**"
- "stores/**"
- "types/**"
- "utils/**"
- "scripts/build-station-search-index.mjs"
- "scripts/generate-social-preview.mjs"
- "scripts/generate-station-og-images.mjs"
# Manual deploy remains possible even without site changes.
workflow_dispatch:
permissions:
contents: read
# All repository work shares one queue, including different PRs/branches.
# Preserve distinct queued work; never interrupt an active deploy/image upload.
concurrency:
group: onair-repository-work
queue: max
cancel-in-progress: false
jobs:
publish:
name: "Publish ${{ github.ref_name }} to Pages"
# Production is released from trusted main pushes; the first step verifies
# the exact public repository, credentials, domain and write permission.
# Staging uses its own opt-in readiness flag after environment migration.
# Until the staging Environment is provisioned, legacy development settings remain active.
if: >-
(github.ref_name == 'staging' &&
(vars.PAGES_STAGING_READY == 'true' ||
(vars.PAGES_STAGING_READY == '' && vars.PAGES_DEV_READY == 'true'))) ||
(github.ref_name == 'main')
runs-on: ubuntu-latest
timeout-minutes: 90
# Production is immutable; staging moves to its own Environment only after
# the repo-level PAGES_STAGING_READY flag is true and secrets are provisioned.
# The legacy development fallback prevents disrupting the current staging site.
environment:
name: ${{ github.ref_name == 'main' && 'production' || (vars.PAGES_STAGING_READY == 'true' && 'staging' || 'development') }}
env:
NUXT_PUBLIC_SITE_URL: ${{ vars.NUXT_PUBLIC_SITE_URL }}
# GitHub Environment variable: distinct browser-tab title for each tier.
NUXT_PUBLIC_SITE_NAME: ${{ vars.NUXT_PUBLIC_SITE_NAME }}
# Browser-side TuneIn lookup uses the same configured CORS proxy as country radio.
# Static GitHub Pages builds must receive the public env during generation.
NUXT_PUBLIC_CORS_SERVER_1: ${{ vars.NUXT_PUBLIC_CORS_SERVER_1 }}
# Approved ePlus-backed stream resolver, if enabled in each environment.
# Nuxt static output captures NUXT_PUBLIC_* only at build time.
NUXT_PUBLIC_GLOBAL_RADIO_RESOLVER_URL: ${{ vars.NUXT_PUBLIC_GLOBAL_RADIO_RESOLVER_URL }}
NUXT_APP_BASE_URL: /
# Indexing is tier-specific: staging never indexed, production indexed.
# Never force noindex globally; that breaks production SEO and GA4.
NUXT_PUBLIC_NO_INDEX: ${{ github.ref_name == 'staging' && 'true' || 'false' }}
TARGET_REPOSITORY: ${{ github.ref_name == 'main' && 'ePlus-DEV/onair-production-pages' || 'ePlus-DEV/onair-staging-pages' }}
TARGET_DOMAIN: ${{ github.ref_name == 'main' && 'radio.eplus.dev' || 'stg.radio.eplus.dev' }}
ONAIR_SKIP_STATION_OG: 'true'
NUXT_PUBLIC_STATION_OG_BASE_URL: ${{ vars.STATION_OG_BASE_URL }}
TARGET_KIND: ${{ github.ref_name == 'main' && 'production' || 'staging' }}
SEO_EXPECTED_SITE_URL: ${{ vars.NUXT_PUBLIC_SITE_URL }}
steps:
- name: Skip an obsolete queued website release
id: current
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
live_sha="$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_REF_NAME" --jq '.sha')"
if [ "$live_sha" != "$GITHUB_SHA" ]; then
echo "::notice::Skip obsolete deployment: a newer commit exists on $GITHUB_REF_NAME."
echo "run=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "run=true" >> "$GITHUB_OUTPUT"
# Cheap preflight BEFORE npm ci and 4,000+ page prerender. This catches
# missing target repositories, expired PATs and wrong credentials fast.
- name: Verify exact Pages repository and PAT before building
if: steps.current.outputs.run == 'true'
shell: bash
env:
PAGES_DEPLOY_TOKEN: ${{ secrets.PAGES_DEPLOY_TOKEN }}
run: |
set -euo pipefail
case "$TARGET_REPOSITORY:$TARGET_DOMAIN" in
ePlus-DEV/onair-staging-pages:stg.radio.eplus.dev|ePlus-DEV/onair-production-pages:radio.eplus.dev) ;;
*) echo "::error::Unexpected Pages target repository or domain"; exit 1 ;;
esac
if [ "$NUXT_PUBLIC_SITE_URL" != "https://$TARGET_DOMAIN" ] || [ "$NUXT_APP_BASE_URL" != "/" ]; then
echo "::error::Check Environment variable NUXT_PUBLIC_SITE_URL: expected https://$TARGET_DOMAIN and Nuxt base /."
exit 1
fi
if [ -z "$PAGES_DEPLOY_TOKEN" ]; then
echo "::error::Missing PAGES_DEPLOY_TOKEN in the source repository's environment secrets."
exit 1
fi
auth="$(printf 'x-access-token:%s' "$PAGES_DEPLOY_TOKEN" | base64 -w0)"
if ! GIT_TERMINAL_PROMPT=0 git -c "http.https://github.com/.extraheader=AUTHORIZATION: basic $auth" \
ls-remote --exit-code "https://github.com/$TARGET_REPOSITORY.git" refs/heads/main >/dev/null; then
echo "::error::Pages target $TARGET_REPOSITORY is missing or this token cannot read it."
exit 1
fi
# Read access alone is insufficient: check that the PAT can push
# before spending minutes on Nuxt generation.
if ! curl --fail --silent --show-error \
-H "Authorization: Bearer $PAGES_DEPLOY_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$TARGET_REPOSITORY" | node -e '
let data = "";
process.stdin.on("data", chunk => { data += chunk; });
process.stdin.on("end", () => {
try {
const repo = JSON.parse(data);
if (repo.permissions?.push !== true) {
console.error("::error::The Pages PAT does not have write access to the selected repository.");
process.exitCode = 1;
}
} catch {
console.error("::error::Could not validate Pages token permissions.");
process.exitCode = 1;
}
});
'; then
echo "::error::Fix Pages token Contents permissions before rebuilding."
exit 1
fi
echo "Validated target $TARGET_REPOSITORY and read/write PAT permissions."
- name: Check out trusted source
if: steps.current.outputs.run == 'true'
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Set up Node.js
if: steps.current.outputs.run == 'true'
uses: actions/setup-node@v7
with:
node-version: "24.15.0"
cache: npm
- name: Explain Global Radio activation status
if: steps.current.outputs.run == 'true'
shell: bash
run: |
if [ -n "${NUXT_PUBLIC_CORS_SERVER_1:-}" ]; then
case "$NUXT_PUBLIC_CORS_SERVER_1" in
https://*) echo "::notice::CORS proxy configured for ${TARGET_DOMAIN}; verify TuneIn JSON and real HLS playback." ;;
*) echo "::error::NUXT_PUBLIC_CORS_SERVER_1 must be an HTTPS proxy origin"; exit 1 ;;
esac
else
echo "::notice::NUXT_PUBLIC_CORS_SERVER_1 is unset for ${TARGET_DOMAIN}; public TuneIn lookup is disabled (no hardcoded fallback)."
fi
if [ -n "${NUXT_PUBLIC_GLOBAL_RADIO_RESOLVER_URL:-}" ]; then
case "$NUXT_PUBLIC_GLOBAL_RADIO_RESOLVER_URL" in
https://*) echo "::notice::Optional approved Apple Music resolver configured for ${TARGET_DOMAIN}." ;;
*) echo "::error::NUXT_PUBLIC_GLOBAL_RADIO_RESOLVER_URL must be a full HTTPS endpoint"; exit 1 ;;
esac
elif [ -z "${NUXT_PUBLIC_CORS_SERVER_1:-}" ]; then
echo "::notice::No Global Radio resolver configured; Apple Music playback is unavailable, external provider links remain available."
fi
- name: Install dependencies
if: steps.current.outputs.run == 'true'
run: npm ci
- name: Run unit tests
if: steps.current.outputs.run == 'true'
run: npm test
- name: Generate static website
if: steps.current.outputs.run == 'true'
run: npm run generate:site
- name: Check SEO for chosen environment
if: steps.current.outputs.run == 'true'
run: |
node scripts/assert-sitemap-xml.mjs
node scripts/assert-route-social-meta.mjs
node scripts/assert-all-station-social-meta.mjs
node scripts/assert-brand-assets.mjs
if [ "$TARGET_KIND" = staging ]; then
node scripts/assert-staging-noindex.mjs
fi
- name: Check project Pages links and artwork before publishing
if: steps.current.outputs.run == 'true'
run: node scripts/assert-project-pages-output.mjs .output/public custom-domain
- name: Validate GA4 tag installation in generated HTML
if: steps.current.outputs.run == 'true'
run: node scripts/assert-ga4-output.mjs .output/public "$TARGET_KIND"
- name: Check Pages output and GitHub hosting size limit
if: steps.current.outputs.run == 'true'
run: node scripts/check-pages-build.mjs .output/public "$TARGET_KIND"
- name: Publish generated output to public repository
if: steps.current.outputs.run == 'true'
shell: bash
env:
PAGES_DEPLOY_TOKEN: ${{ secrets.PAGES_DEPLOY_TOKEN }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
# A newer staging/main commit may arrive during Nuxt prerender.
# Never publish an obsolete build over the newest Pages content.
live_sha="$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_REF_NAME" --jq '.sha')"
if [ "$live_sha" != "$GITHUB_SHA" ]; then
echo "::notice::Skip obsolete Pages upload: $GITHUB_REF_NAME is now $live_sha; this run built $GITHUB_SHA."
exit 0
fi
if [ -z "$PAGES_DEPLOY_TOKEN" ]; then
echo "::error::Missing PAGES_DEPLOY_TOKEN secret with Contents: Read and write access to both public Pages repositories."
exit 1
fi
target="$RUNNER_TEMP/onair-pages"
auth="$(printf 'x-access-token:%s' "$PAGES_DEPLOY_TOKEN" | base64 -w0)"
GIT_TERMINAL_PROMPT=0 git -c "http.https://github.com/.extraheader=AUTHORIZATION: basic $auth" clone --depth 1 --branch main "https://github.com/$TARGET_REPOSITORY.git" "$target"
# Keep the destination repository README across generated-site releases.
rsync -a --delete --exclude='.git/' --exclude='/README.md' "$GITHUB_WORKSPACE/.output/public/" "$target/"
touch "$target/.nojekyll"
# rsync --delete replaces the output tree; restore the custom domain
# before committing so a redeploy never removes GitHub Pages CNAME.
printf '%s\n' "$TARGET_DOMAIN" > "$target/CNAME"
git -C "$target" config user.name "github-actions[bot]"
git -C "$target" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git -C "$target" add --all
if git -C "$target" diff --cached --quiet; then
echo "No changes to publish to $TARGET_REPOSITORY."
exit 0
fi
git -C "$target" commit -m "deploy: $TARGET_KIND from $GITHUB_REPOSITORY@$GITHUB_SHA"
# GITHUB_TOKEN cannot write to a different repository. Keep the
# repository-scoped PAT out of the remote URL and git configuration.
auth="$(printf 'x-access-token:%s' "$PAGES_DEPLOY_TOKEN" | base64 -w0)"
git -C "$target" -c "http.https://github.com/.extraheader=AUTHORIZATION: basic $auth" push origin HEAD:main
echo "Published $TARGET_KIND to $TARGET_REPOSITORY"