WIP #437
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: "Website" | |
on: | |
push: | |
branches: | |
- locally-serve-fonts | |
paths: | |
- website/** | |
pull_request: | |
branches: | |
- locally-serve-fonts | |
paths: | |
- website/** | |
env: | |
CARGO_TERM_COLOR: always | |
INDEX_HTML_HEAD_INCLUSION: REPLACE_ME | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
deployments: write | |
pull-requests: write | |
steps: | |
- name: 📥 Clone and checkout repository | |
uses: actions/checkout@v3 | |
- name: 🕸 Install Zola | |
uses: taiki-e/install-action@v2 | |
with: | |
tool: zola@0.19.1 | |
- name: ✂ Replace template in <head> of index.html | |
run: | | |
# Check if we are on the locally-serve-fonts branch | |
if git rev-parse --abbrev-ref HEAD | grep locally-serve-fonts > /dev/null; then | |
export INDEX_HTML_HEAD_SCRIPT=$(curl -s https://graphite.rs/visit/script.hash.js) || exit 1 | |
echo "INDEX_HTML_HEAD_INCLUSION=<script data-domain=\"graphite.rs\" data-api=\"/visit/event\">$INDEX_HTML_HEAD_SCRIPT</script>" >> $GITHUB_ENV | |
else | |
echo "INDEX_HTML_HEAD_INCLUSION=<script>alert();</script>" >> $GITHUB_ENV | |
fi | |
- name: 🌐 Build Graphite website with Zola | |
env: | |
MODE: prod | |
run: | | |
cd website | |
zola --config config_prod.toml build | |
- name: 🔍 Check if `website/other` directory changed | |
uses: dorny/paths-filter@v3 | |
id: changes | |
with: | |
filters: | | |
other: | |
- "website/other/**" | |
- name: 💿 Restore cache of `website/other/dist` directory, if available and `website/other` didn't change | |
if: steps.changes.outputs.other != 'true' | |
id: cache-website-other-dist | |
uses: actions/cache/restore@v3 | |
with: | |
path: website/other/dist | |
key: website-other-dist-${{ runner.os }} | |
- name: 🟢 Set up Node only if we are going to build in the next step | |
if: steps.cache-website-other-dist.outputs.cache-hit != 'true' | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "latest" | |
- name: 📁 Build `website/other` directory only if changed or not cached | |
if: steps.cache-website-other-dist.outputs.cache-hit != 'true' | |
id: build-website-other | |
run: | | |
sh website/other/build.sh | |
- name: 💾 Save cache of `website/other/dist` directory if it was built above | |
if: steps.cache-website-other-dist.outputs.cache-hit != 'true' | |
uses: actions/cache/save@v3 | |
with: | |
path: website/other/dist | |
key: ${{ steps.cache-website-other-dist.outputs.cache-primary-key }} | |
- name: 🚚 Move `website/other/dist` contents to `website/public` | |
run: | | |
mv website/other/dist/* website/public | |
- name: 📤 Publish to Cloudflare Pages | |
id: cloudflare | |
uses: cloudflare/pages-action@1 | |
continue-on-error: true | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
projectName: graphite-website | |
directory: website/public |