Skip to content

Commit a6ce97c

Browse files
Commit imported data automatically, add scheduler to trigger build every day if needed
1 parent 4badc5a commit a6ce97c

File tree

2 files changed

+101
-20
lines changed

2 files changed

+101
-20
lines changed

.github/workflows/astro.yml

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
workflow_dispatch:
77

88
permissions:
9-
contents: read
9+
contents: write
1010
pages: write
1111
id-token: write
1212

@@ -27,6 +27,8 @@ jobs:
2727
steps:
2828
- name: Checkout
2929
uses: actions/checkout@v4
30+
with:
31+
token: ${{ secrets.GITHUB_TOKEN }}
3032

3133
- name: Detect package manager
3234
id: detect-package-manager
@@ -73,32 +75,14 @@ jobs:
7375
restore-keys: |
7476
${{ runner.os }}-astro-cache-
7577
76-
# ===== /content cache keyed by content/meta.json (source commit) =====
77-
- name: Restore content cache
78-
id: content-cache
79-
uses: actions/cache/restore@v4
80-
with:
81-
path: ${{ env.BUILD_PATH }}/content
82-
key: ${{ runner.os }}-content-${{ hashFiles('content/meta.json') }}-primary
83-
restore-keys: |
84-
${{ runner.os }}-content-${{ hashFiles('content/meta.json') }}-
85-
${{ runner.os }}-content-
86-
87-
# Always run; import should reuse restored files and fetch only updates
78+
# Fetch the latest data
8879
- name: Fetch data
8980
run: npm run import
9081
working-directory: ${{ env.BUILD_PATH }}
9182
env:
9283
STADIA_MAPS_API_KEY: ${{ secrets.STADIA_MAPS_API_KEY }}
9384
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9485

95-
# Save refreshed /content with a unique key to avoid collisions
96-
- name: Save content cache
97-
uses: actions/cache/save@v4
98-
with:
99-
path: ${{ env.BUILD_PATH }}/content
100-
key: ${{ runner.os }}-content-${{ hashFiles('content/meta.json') }}-${{ github.run_id }}
101-
10286
- name: Print env
10387
run: |
10488
echo "vars.SITE_URL='${{ vars.SITE_URL }}'"
@@ -112,6 +96,42 @@ jobs:
11296
SITE_URL: ${{ vars.SITE_URL }}
11397
BASE_PATH: ${{ vars.BASE_PATH }}
11498

99+
- name: Run tests
100+
run: |
101+
# TODO: Implement actual tests
102+
echo "Tests placeholder - returning success"
103+
exit 0
104+
working-directory: ${{ env.BUILD_PATH }}
105+
106+
- name: Commit content updates
107+
if: success()
108+
run: |
109+
# Configure git
110+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
111+
git config --local user.name "github-actions[bot]"
112+
113+
# Check if there are changes to commit
114+
if [ -n "$(git status --porcelain content/)" ]; then
115+
# Read upstream commit from meta.json
116+
UPSTREAM_COMMIT=$(jq -r '.commitHash' content/meta.json)
117+
echo "Upstream commit from meta.json: $UPSTREAM_COMMIT"
118+
119+
# Stage content changes, including content/meta.json
120+
git add content/
121+
122+
# Create commit message with upstream reference
123+
git commit -m "Auto import content $UPSTREAM_COMMIT
124+
125+
https://github.com/owddm/public/commit/$UPSTREAM_COMMIT"
126+
127+
# Push changes
128+
git push
129+
130+
echo "Content updates committed and pushed"
131+
else
132+
echo "No content changes to commit"
133+
fi
134+
115135
# IMPORTANT: Always save Astro cache so new variants produced this run are kept.
116136
# Append run_id to avoid "already exists", and rely on the restore prefix above to pick the newest next time.
117137
- name: Save Astro cache (always)

.github/workflows/scheduler.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Content Update Scheduler
2+
3+
on:
4+
schedule:
5+
# Run daily at 11pm JST (2pm UTC)
6+
- cron: "0 14 * * *"
7+
workflow_dispatch:
8+
9+
jobs:
10+
check-for-updates:
11+
name: Check for content updates
12+
runs-on: ubuntu-latest
13+
outputs:
14+
has-updates: ${{ steps.check-commit.outputs.has-updates }}
15+
new-commit: ${{ steps.check-commit.outputs.new-commit }}
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Check for new upstream commit
22+
id: check-commit
23+
run: |
24+
UPSTREAM_REPO="owddm/public"
25+
26+
# Read current commit from meta.json
27+
CURRENT_COMMIT=$(jq -r '.commitHash' content/meta.json)
28+
echo "Current commit: $CURRENT_COMMIT"
29+
30+
31+
# Get latest commit from upstream main branch
32+
LATEST_COMMIT=$(curl -s "https://api.github.com/repos/$UPSTREAM_REPO/commits/main" | jq -r '.sha')
33+
echo "Latest upstream commit: $LATEST_COMMIT"
34+
35+
if [ "$CURRENT_COMMIT" != "$LATEST_COMMIT" ]; then
36+
echo "New commit detected!"
37+
echo "has-updates=true" >> $GITHUB_OUTPUT
38+
echo "new-commit=$LATEST_COMMIT" >> $GITHUB_OUTPUT
39+
else
40+
echo "No new commits"
41+
echo "has-updates=false" >> $GITHUB_OUTPUT
42+
fi
43+
44+
trigger-build:
45+
name: Trigger build
46+
needs: check-for-updates
47+
if: needs.check-for-updates.outputs.has-updates == 'true'
48+
runs-on: ubuntu-latest
49+
50+
steps:
51+
- name: Trigger builder workflow
52+
uses: actions/github-script@v7
53+
with:
54+
github-token: ${{ secrets.GITHUB_TOKEN }}
55+
script: |
56+
await github.rest.actions.createWorkflowDispatch({
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
workflow_id: 'astro.yml',
60+
ref: 'main'
61+
})

0 commit comments

Comments
 (0)