Skip to content

Data Synchronization #180

Data Synchronization

Data Synchronization #180

Workflow file for this run

name: Data Synchronization
on:
schedule:
# 選課期間每小時執行一次
- cron: "0 * * * *"
workflow_dispatch: # 允許手動觸發
permissions:
contents: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v8.0.0
with:
version: "latest"
enable-cache: true
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: ".python-version"
- name: Install dependencies
run: uv sync
- name: Run Scraper Script
run: uv run python scripts/fetch_data.py
- name: Deploy Scholarship to separate branch
run: |
mkdir -p dist-scholarship
cp dist/scholarships.json dist-scholarship/
cd dist-scholarship
git init
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b data-scholarship
git add .
git commit -m "Update scholarship data: $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git push -f origin data-scholarship
- name: Deploy Courses to semester branch
run: |
SEMESTER=$(cat dist/semester.txt)
echo "Deploying to semester branch: $SEMESTER"
# Remove files we don't want in the course branch
rm -f dist/semester.txt
rm -f dist/scholarships.json
cd dist
git init
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "$SEMESTER"
git add .
git commit -m "Update courses data for $SEMESTER: $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git push -f origin "$SEMESTER"