-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (105 loc) · 3.99 KB
/
Copy pathgenerate-cache.yml
File metadata and controls
126 lines (105 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Generate Image Cache and Deploy to GitHub Pages
on:
# 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: write
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://x-access-token:${GITHUB_TOKEN}@github.com/Trease-Focus/cache-trees-cdn.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