Add sync-upstream CI workflows for testing.

Sync game_data from upstream IdleFantasy, run smoke tests, optional deploy.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-04 11:57:57 +02:00
co-authored by Cursor
parent a1cd1ad0af
commit c933dcf7d5
3 changed files with 169 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
# Sync vendored recipe JSON from tristinbaker/IdleFantasy, run smoke tests, deploy.
#
# Secrets (repo settings → Actions → Secrets):
# DEPLOY_SSH_KEY — private key for DEPLOY_HOST
# Optional variables:
# DEPLOY_HOST — default root@10.0.0.5
# DEPLOY_DIR — default /opt/apps/Idle-Fantasy-Save-Viewer
# DEPLOY_SERVICE — default viewer
#
# Set AUTO_DEPLOY=false to sync + test only (no SSH deploy).
name: Sync Upstream Game Data
on:
schedule:
- cron: "0 8 * * *"
workflow_dispatch:
inputs:
reason:
description: Why this run was triggered
required: false
default: manual
permissions:
contents: write
jobs:
sync-test-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Sync recipe JSON from upstream IdleFantasy
run: python scripts/sync_game_data.py
- name: Smoke tests
run: |
python test_db_goals.py
python test_advisor.py
- name: Commit and push if game_data changed
id: commit
run: |
if git diff --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "game_data already current"
exit 0
fi
git config user.name "gitea-actions[bot]"
git config user.email "gitea-actions[bot]@users.noreply.local"
git add game_data/
git commit -m "Sync game_data from tristinbaker/IdleFantasy (automated)"
git push
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Deploy to production
if: steps.commit.outputs.changed == 'true' && vars.AUTO_DEPLOY != 'false'
env:
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
DEPLOY_DIR: ${{ vars.DEPLOY_DIR }}
DEPLOY_SERVICE: ${{ vars.DEPLOY_SERVICE }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
run: bash scripts/deploy-ci.sh
+62
View File
@@ -0,0 +1,62 @@
# GitHub mirror of .gitea/workflows/sync-upstream.yml — use after moving the repo to GitHub.
# Copy or symlink when migrating from Gitea; same secrets/vars names apply.
name: Sync Upstream Game Data
on:
schedule:
- cron: "0 8 * * *"
workflow_dispatch:
inputs:
reason:
description: Why this run was triggered
required: false
default: manual
repository_dispatch:
types: [idle-fantasy-upstream-updated]
permissions:
contents: write
jobs:
sync-test-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Sync recipe JSON from upstream IdleFantasy
run: python scripts/sync_game_data.py
- name: Smoke tests
run: |
python test_db_goals.py
python test_advisor.py
- name: Commit and push if game_data changed
id: commit
run: |
if git diff --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add game_data/
git commit -m "Sync game_data from tristinbaker/IdleFantasy"
git push
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Deploy to production
if: steps.commit.outputs.changed == 'true' && vars.AUTO_DEPLOY != 'false'
env:
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
DEPLOY_DIR: ${{ vars.DEPLOY_DIR }}
DEPLOY_SERVICE: ${{ vars.DEPLOY_SERVICE }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
run: bash scripts/deploy-ci.sh
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Non-interactive deploy for CI (Gitea/GitHub Actions). Requires env:
# DEPLOY_SSH_KEY, DEPLOY_HOST, DEPLOY_DIR, DEPLOY_SERVICE
set -euo pipefail
if [[ -z "${DEPLOY_SSH_KEY:-}" ]]; then
echo "DEPLOY_SSH_KEY not set — skipping deploy"
exit 0
fi
HOST="${DEPLOY_HOST:-root@10.0.0.5}"
DIR="${DEPLOY_DIR:-/opt/apps/Idle-Fantasy-Save-Viewer}"
SERVICE="${DEPLOY_SERVICE:-viewer}"
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
SHA="$(git rev-parse HEAD)"
KEY_FILE="$(mktemp)"
trap 'rm -f "$KEY_FILE"' EXIT
install -m 600 /dev/stdin "$KEY_FILE" <<< "$DEPLOY_SSH_KEY"
ssh -i "$KEY_FILE" -o BatchMode=yes -o StrictHostKeyChecking=accept-new "$HOST" \
bash -s -- "$DIR" "$BRANCH" "$SHA" "$SERVICE" <<'REMOTE'
set -euo pipefail
DEPLOY_DIR="$1" BRANCH="$2" EXPECTED_SHA="$3" SERVICE="$4"
cd "$DEPLOY_DIR"
git fetch origin "$BRANCH"
git checkout "$BRANCH"
git reset --hard "origin/$BRANCH"
[[ "$(git rev-parse HEAD)" == "$EXPECTED_SHA" ]] || { echo "SHA mismatch"; exit 1; }
docker compose up -d --build "$SERVICE"
for _ in $(seq 1 30); do
docker compose ps --format json | grep -q '"Health":"healthy"' && exit 0
sleep 2
done
echo "Health check timed out"
exit 1
REMOTE