-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (126 loc) · 4.52 KB
/
Copy pathdeploy.yml
File metadata and controls
147 lines (126 loc) · 4.52 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
name: Build & Deploy to GitHub Pages
on:
push:
branches: [main]
paths:
# Rebuild whenever source content or templates change
- 'posts/**'
- 'src/templates/**'
- 'config/**'
- 'scripts/**'
- 'package.json'
- 'template.html'
# Also run when the workflow itself is first added or updated
- '.github/workflows/deploy.yml'
# Allow manual trigger from the Actions tab
workflow_dispatch:
# Grant the GITHUB_TOKEN permission to deploy Pages
permissions:
contents: read
pages: write
id-token: write
# Only one deployment at a time; cancel any in-progress run on a new push
concurrency:
group: pages
cancel-in-progress: true
jobs:
build:
name: Build site
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2 # need two commits to detect changed files
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
# Detect which files changed vs the previous commit so we can do a
# targeted rebuild instead of always rebuilding everything.
- name: Detect changed files
id: changed
run: |
# On a workflow_dispatch there is no "previous" commit to diff
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "CHANGED_FILES=" >> "$GITHUB_ENV"
echo "mode=full" >> "$GITHUB_OUTPUT"
else
FILES=$(git diff --name-only HEAD~1 HEAD)
echo "CHANGED_FILES<<EOF" >> "$GITHUB_ENV"
echo "$FILES" >> "$GITHUB_ENV"
echo "EOF" >> "$GITHUB_ENV"
# If any template / config changed → force full rebuild
if echo "$FILES" | grep -qE '^(src/templates/|config/|template\.html)'; then
echo "mode=full" >> "$GITHUB_OUTPUT"
else
echo "mode=incremental" >> "$GITHUB_OUTPUT"
fi
fi
- name: Build site (full)
if: steps.changed.outputs.mode == 'full' || github.event_name == 'workflow_dispatch'
run: npm run build
- name: Build site (incremental — posts only)
if: steps.changed.outputs.mode == 'incremental'
run: npm run build:changed
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: pages
deploy:
name: Deploy to GitHub Pages
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deploy.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deploy
uses: actions/deploy-pages@v4
archive:
name: Archive to Wayback Machine / archive.today
needs: deploy
# Only run if archiving is enabled in config
runs-on: ubuntu-latest
if: ${{ vars.ARCHIVE_ENABLED == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Read site URL from config
id: cfg
run: |
URL=$(node -e "const c=require('./config/config.json'); console.log(c.site?.url||'')")
echo "site_url=$URL" >> "$GITHUB_OUTPUT"
- name: Submit to archive.org (Wayback Machine)
if: ${{ vars.ARCHIVE_ORG != 'false' }}
# Fire-and-forget: use --max-time so a slow API never blocks the run
run: |
SITE="${{ steps.cfg.outputs.site_url }}"
if [ -z "$SITE" ]; then
echo "No site URL configured; skipping archive.org submission."
exit 0
fi
echo "Submitting $SITE to archive.org…"
# archive.org save API — no key required for basic snapshots
curl --silent --max-time 30 --fail-with-body \
"https://web.archive.org/save/$SITE" || true
# Don't fail the workflow if archiving is unavailable
continue-on-error: true
- name: Submit to archive.today
if: ${{ vars.ARCHIVE_TODAY != 'false' }}
run: |
SITE="${{ steps.cfg.outputs.site_url }}"
if [ -z "$SITE" ]; then
echo "No site URL configured; skipping archive.today submission."
exit 0
fi
echo "Submitting $SITE to archive.today…"
# archive.today submit endpoint
curl --silent --max-time 30 --location \
--data "url=${SITE}&anyway=1" \
"https://archive.today/submit/" || true
continue-on-error: true