Skip to content

Build and Deploy Gatsby #135

Build and Deploy Gatsby

Build and Deploy Gatsby #135

Workflow file for this run

name: Build and Deploy Gatsby
on:
push:
branches: [ main ]
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
inputs:
useCache:
description: "Use Gatsby cache?"
required: true
default: "false"
type: choice
options:
- "true"
- "false"
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
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: false
# Default to bash
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
env:
# Decide when cache is enabled
CACHE_ENABLED: ${{
(github.event_name == 'push') ||
(github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.useCache || 'false') == 'true')}}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install dependencies
run: npm ci
- name: Restore Gatsby cache
if: env.CACHE_ENABLED == 'true'
uses: actions/cache/restore@v4
with:
path: |
.cache
public
# Use main branch for consistent cache key across all events
key: gatsby-cache-${{ github.run_number }}
restore-keys: |
gatsby-cache-
- name: Clear Gatsby cache dirs if disabled
if: env.CACHE_ENABLED != 'true'
run: |
echo "🧹 Removing .cache and public directories..."
rm -rf .cache public
- name: Build
env:
NODE_ENV: production
PREFIX_PATHS: 'true'
# Path prefix for GitHub Pages deployment
GATSBY_PATH_PREFIX: '/toolfindr'
# Wikidata SPARQL data source
GATSBY_WD_SPARQL_URL: 'https://query.wikidata.org/sparql'
# Wikidata Linked Data Fragments server
GATSBY_WD_LDF_URL: 'https://query.wikidata.org/bigdata/ldf'
# TaDiRAH SPARQL data source
GATSBY_TADIRAH_FILE_URL: 'https://vocabs-downloads.acdh.oeaw.ac.at/vocabs-main/Humanities/TaDiRAH/tadirah.ttl'
# MediaWiki Commons API Endpoint
GATSBY_COMMONS_API_URL: 'https://commons.wikimedia.org/w/api.php'
run: npm run build
- name: Save Gatsby cache
#if: env.CACHE_ENABLED == 'true'
uses: actions/cache/save@v4
with:
path: |
.cache
public
key: gatsby-cache-${{ github.run_number }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: ./public
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4