Skip to content

Scheduled update of JSON data in gh-pages #94

Scheduled update of JSON data in gh-pages

Scheduled update of JSON data in gh-pages #94

name: Scheduled update of JSON data in gh-pages
on:
schedule:
- cron: '0 * * * *' # 每小時的第 0 分鐘執行
workflow_dispatch:
jobs:
update-json:
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: main
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Python update script
run: |
# 執行 buses.py 與 dining.py,若失敗不會中斷流程(加上 || true)
python scripts/buses.py || true
python scripts/dining.py || true
# 有些爬蟲無法順利執行,先註解掉(學校好像有擋國外 IP)
# python scripts/directories.py || true
# python scripts/maps.py || true
# python scripts/newsletters.py || true
python scripts/courses.py || true
# 文件處理
python combine.py || true
python folder.py || true
- name: Copy both static and dynamic JSON files to docs folder
run: |
mkdir -p docs
cp -r data/static/* docs/
cp -r data/dynamic/* docs/ || true
# 文件處理
python combine.py || true
python folder.py || true
- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./docs
# 將 force_orphan 設為 false,避免以 orphan commit 的方式覆寫原有歷史
force_orphan: false
commit_message: "Scheduled update of JSON data [skip ci]"