Skip to content

Generate Image Cache and Deploy to GitHub Pages #25

Generate Image Cache and Deploy to GitHub Pages

Generate Image Cache and Deploy to GitHub Pages #25

name: Generate Image Cache and Deploy to GitHub Pages
on:
# Run on a schedule (every day at midnight UTC)
schedule:
- cron: '0 0 * * *'
# Allow manual trigger
workflow_dispatch:
# Triggered by another repository (trease-backend)
repository_dispatch:
types: [trigger-cache-generation]
# Also run on push to main branch
push:
branches:
- main
# 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
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v4
- name: Clone trease-backend repository
run: |
git clone https://github.com/Trease-Focus/trease-backend.git trease-backend --depth 1
- name: Install ffmpeg
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
working-directory: trease-backend
run: bun install
- name: Generate Image Cache
working-directory: trease-backend
run: bun run cache-gen/generate_image_cache.ts
- name: Generate Video Cache
working-directory: trease-backend
run: bun run cache-gen/generate_video_cache.ts
- name: Generate Data Cache
working-directory: trease-backend
run: bun run cache-gen/generate_entity_data.ts
- name: Prepare output for GitHub Pages
run: |
mkdir -p _site
# Copy generated cache files to _site directory
# Adjust this path based on where the script outputs files
cp -r trease-backend/cache/* _site/ 2>/dev/null
# Create an index.html if one doesn't exist
if [ ! -f _site/index.html ]; then
echo '<!DOCTYPE html><html><head><title>Image Cache</title></head><body><h1>Image Cache Generated</h1><p>Last updated: '"$(date -u)"'</p></body></html>' > _site/index.html
fi
- name: Copy Additional Assets
run: |
# Copy any additional assets needed for the cache display
cp cache/images/* _site/images 2>/dev/null || true
cp cache/video/* _site/video 2>/dev/null || true
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: '_site'
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