-
Notifications
You must be signed in to change notification settings - Fork 9
175 lines (144 loc) · 5.48 KB
/
deploy-pages.yml
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
# Simple workflow for deploying static content to GitHub Pages
name: Deploy content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
purgeCache:
description: "A list of URLs to purge from the cache, separated by \"|\".\n\nTo clear the entire cache, use \"--all\"."
default: ""
recheckUrls:
description: "Should the existing URLs be re-checked to determine if there are any missing?"
type: boolean
default: false
schedule:
- cron: "48 0 * * *"
repository_dispatch:
types: [trigger_deploy]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Get username and repository
run: |
echo "REPO_USERNAME=${GITHUB_REPOSITORY%%/*}" >> $GITHUB_ENV
echo "REPO_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
echo "REPO_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
- name: Set pages url
run: |
HOMEPAGE_URL="$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$GITHUB_REPOSITORY/pages" | jq -r '.html_url' | sed 's/\/$//')"
if [ "$HOMEPAGE_URL" == "null" ]; then
echo "PAGES_URL=https://$REPO_USERNAME.github.io/$REPO_NAME" >> $GITHUB_ENV
else
echo "PAGES_URL=$HOMEPAGE_URL" >> $GITHUB_ENV
fi
- name: Set page path
run: |
echo "PAGES_PATH=$(echo "$PAGES_URL" | awk -F/ -v OFS="/" '{$1=$2=$3=""; print $0}' | sed 's/\/\+/\//')" >> $GITHUB_ENV
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Download cache
if: (github.event.inputs.purgeCache != '--all')
continue-on-error: true
run: |
wget "https://github.com/$GITHUB_REPOSITORY/releases/download/cache/cache.txz?`date +%s`" -O cache.txz
- name: Extract cache
if: (github.event.inputs.purgeCache != '--all')
continue-on-error: true
run: |
tar -xJvf cache.txz
- name: Delete cache
if: (github.event.inputs.purgeCache != '--all')
continue-on-error: true
run: |
rm cache.txz
- name: Install npm modules
run: |
(cd source/scripts && npm install)
(cd source/website && npm install)
- name: Purge specified items from cache
if: ((github.event.inputs.purgeCache != '') && (github.event.inputs.purgeCache != '--all'))
run: |
cd source/scripts
npx tsx ./purgecache.ts "${{ github.event.inputs.purgeCache }}"
- name: Update mirror
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p mod-mirror
cd source/scripts
npx tsx ./mirror-mods.ts 2>&1
cd ../../mod-mirror
find -type f | while read file; do
gh release upload mod-mirror "$file" || true
done
if [ -f "metadata.json" ]; then
gh release upload mod-mirror --clobber "metadata.json"
fi
- name: Process the json (schedule)
if: (github.event_name == 'schedule' || github.event.inputs.recheckUrls == 'true')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd source/scripts
npx tsx ./combine.ts "--baseHref=$PAGES_URL" --updateFunding --recheckUrls 2>&1 | tee ../website/public/deploy-log.txt
- name: Process the json (normal)
if: (github.event_name != 'schedule')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd source/scripts
npx tsx ./combine.ts "--baseHref=$PAGES_URL" 2>&1 | tee ../website/public/deploy-log.txt
- name: "Archive cache"
run: |
tar -cJvf cache.txz \
source/website/public/covers \
source/website/public/funding-info.json \
source/website/public/mod-metadata.json
- name: Build website
run: |
cd source/website
npx astro build --base "$PAGES_PATH"
- name: Precompress assets
run: |
find source/website/out -type f | while read -r file; do
if [[ "$file" == *.html || "$file" == *.css || "$file" == *.js || "$file" == *.json ]]; then
echo "$file"
brotli -k -q 11 "$file"
fi
done
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: "./source/website/out"
- name: Push cache
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload cache --clobber "cache.txz"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4