Skip to content

fix not caching

fix not caching #36

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 (with submodules)
run: |
git clone --recurse-submodules https://github.com/Trease-Focus/trease-tree-compiler.git trease-backend --depth 1
- name: Pull latest cache from cache-data branch
run: |
git fetch origin cache-data || true
git checkout cache-data -- . || true
mkdir -p trease-backend/cache/images trease-backend/cache/video
# Move pulled cache directly into trease-backend/cache
if [ -d cache ]; then
cp -r cache/* trease-backend/cache/ 2>/dev/null || true
rm -rf cache
fi
continue-on-error: true
- 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'
- name: Push cache to cache-data branch
run: |
cd trease-backend/cache
git init
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git remote add origin https://github.com/${{ github.repository }}.git || true
git fetch origin cache-data || true
git checkout -B cache-data || git checkout --orphan cache-data
git add .
git commit -m "Update cache $(date -u)" || echo "No changes to commit"
git push --force origin cache-data
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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