-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (75 loc) · 2.88 KB
/
build.yaml
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
name: Build and Deploy
on:
workflow_dispatch:
push:
branches:
- main
jobs:
Build:
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Download prod build
id: prevbuild
uses: dawidd6/action-download-artifact@master
with:
workflow: build.yaml
branch: main
name: github-pages
path: site
if_no_artifact_found: warn
- name: Extract previous build
if: steps.prevbuild.outputs.found_artifact != 'false'
run: |
cd site
tar -xf artifact.tar && rm artifact.tar
- name: git clone big_imgs
uses: actions/checkout@v4
with:
path: big_imgs
- name: git clone imgs
uses: actions/checkout@v4
with:
repository: buddhist-uni/imgs
path: imgs
- name: Generate images
run: |
cd big_imgs
python build.py --remove-old --verbose --dest ../site --cores 3
- name: Upload Build as Artifact
uses: actions/upload-pages-artifact@main
with:
path: site
retention-days: 90
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@main
- name: Invalidate CloudFlare Cache for Modified Items
shell: bash
run: |
purgeaurl(){
HTTP_RESPONSE=$(curl --silent --show-error -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE }}/purge_cache" -H "Authorization: Bearer ${{ secrets.CF_API_TOKEN }}" -H "Content-Type:application/json" -w "HTTP_STATUS:%{http_code}" --data "{\"files\":[\"${1}\"]}")
HTTP_BODY=$(echo "${HTTP_RESPONSE}" | sed -E 's/HTTP_STATUS\:[0-9]{3}$//')
HTTP_STATUS=$(echo "${HTTP_RESPONSE}" | tr -d '\n' | sed -E 's/.*HTTP_STATUS:([0-9]{3})$/\1/')
if [ "${HTTP_STATUS}" -eq "200" ]; then
SUCCESS=$(echo ${HTTP_BODY} | python3 -c "import sys, json;print(json.load(sys.stdin)['success'])")
if [ "${SUCCESS}" = "True" ]; then
echo "Purged $1"
else
echo "::warning title=CloudFlare Cache-Bust Failure::Failed to purge $1 => ${HTTP_BODY}"
fi
else
echo "::warning title=CloudFlare Cache-Bust Failure::Failed to purge $1 => ($HTTP_STATUS): ${HTTP_BODY}"
fi
}
export -f purgeaurl
if [ -f "site/modified_files.txt" ]; then
cat site/modified_files.txt | sed 's/^/https:\/\/buddhistuniversity.net\/big_imgs\//g' | xargs -P 100 -I {} bash -c 'purgeaurl "{}"'
else
echo "No modified files to purge"
fi