Skip to content

Deploy API Data to GitHub Pages #394

Deploy API Data to GitHub Pages

Deploy API Data to GitHub Pages #394

Workflow file for this run

name: Deploy API Data to GitHub Pages
on:
push:
branches: [main]
schedule:
- cron: '0 0 * * *' # Daily at midnight UTC
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run the build with tmate set "debug_enabled"'
type: boolean
required: false
default: false
use_cached_data:
description: 'Skip data fetch and use the latest history snapshot instead (skips history commit too)'
type: boolean
required: false
default: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPONSORED_ORG_NAME: ${{ github.repository_owner }}
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
test:
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install requirements
run: |
sudo npm install -g strip-json-comments-cli
- name: Test script execution
run: |
scripts/combine-sponsorships.sh
jq . data/all-sponsorships.json > /dev/null
- name: Test SVG generation
run: |
scripts/generate-sponsorship-svg.sh
grep -q '<svg' data/tmp/sponsorship-badge.svg
grep -q '<svg' data/tmp/sponsorship-badge-dark.svg
deploy:
runs-on: ubuntu-24.04
# Only run deployment on schedule or workflow_dispatch
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
needs: test
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Load 1password secret(s)
uses: 1password/load-secrets-action@v4
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: "${{ secrets.TESTS_SERVICE_ACCOUNT_TOKEN }}"
SPONSORSHIPS_READ_TOKEN: "op://test-secrets/DDEV_READ_ORG_SPONSORSHIPS/credential"
- name: Install requirements
run: |
sudo npm install -g strip-json-comments-cli
- name: Setup tmate session
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: true
- name: Load latest history snapshot (cached data)
if: ${{ inputs.use_cached_data }}
run: |
git fetch origin history
LATEST=$(git ls-tree --name-only origin/history data/history/ | sort | tail -1)
git show "origin/history:${LATEST}" > data/all-sponsorships.json
echo "Using cached data from ${LATEST}"
- name: Fetch GitHub sponsorship data
if: ${{ !inputs.use_cached_data }}
run: |
set -eu -o pipefail
SPONSORED_ENTITY_NAME=ddev SPONSORED_ENTITY_TYPE=organization scripts/github-sponsorships.sh
SPONSORED_ENTITY_NAME=rfay SPONSORED_ENTITY_TYPE=user scripts/github-sponsorships.sh
- name: Generate combined data from github and static info
if: ${{ !inputs.use_cached_data }}
run: |
scripts/combine-sponsorships.sh
- name: Commit and push history snapshot to history branch
if: ${{ !inputs.use_cached_data }}
run: |
# Save current data to temp location
SNAPSHOT_DATE=$(date +%F)
TEMP_SNAPSHOT="/tmp/snapshot-${SNAPSHOT_DATE}.json"
cp data/all-sponsorships.json "${TEMP_SNAPSHOT}"
# Configure git
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Fetch and checkout history branch
git fetch origin history || true
git checkout -B history origin/history || git checkout --orphan history
# Create directory and copy snapshot
mkdir -p data/history
cp "${TEMP_SNAPSHOT}" "data/history/${SNAPSHOT_DATE}.json"
# Commit and push if there are changes
git add data/history/
if ! git diff --cached --quiet; then
git commit -m "chore: add sponsorship snapshot for ${SNAPSHOT_DATE}"
git push origin history
else
echo "No new history to commit"
fi
# Return to main branch
git checkout -
- name: Setup Pages
id: pages
uses: actions/configure-pages@v6
- name: Generate sponsorship SVG badges
run: |
scripts/generate-sponsorship-svg.sh data/all-sponsorships.json _site/badges/sponsorship-badge.svg _site/badges/sponsorship-badge-dark.svg
- name: Prepare Pages deployment
run: |
mkdir -p _site/data _site/api
cp data/all-sponsorships.json _site/data/
cp data/all-sponsorships.json _site/api/
cp src/index.html _site/index.html
sed -i 's|https://ddev.github.io/sponsorship-data|${{ steps.pages.outputs.base_url }}|g' _site/index.html
- name: Upload artifact
uses: actions/upload-pages-artifact@v5
with:
path: './_site'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5