upload Kyoto temple skyline picture (#10) #33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v3 | |
with: | |
path: big_imgs | |
- name: git clone imgs | |
uses: actions/checkout@v3 | |
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 |