Crawl & Deploy #354
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Crawl & Deploy | |
on: | |
workflow_dispatch: | |
schedule: | |
# this workflow triggers every hour | |
- cron: "30 * * * *" | |
permissions: | |
# push | |
contents: write | |
# deploy-pages | |
pages: write | |
id-token: write | |
jobs: | |
daemon: | |
runs-on: ubuntu-latest | |
concurrency: | |
group: daemon | |
cancel-in-progress: true | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: main | |
- name: Setup Rust | |
uses: dtolnay/rust-toolchain@nightly | |
- name: Clone ssufid repository | |
uses: actions/checkout@v4 | |
with: | |
path: ssufid | |
repository: yourssu/ssufid | |
ref: main | |
- name: Retrieve cargo cache | |
uses: Leafwing-Studios/cargo-cache@v2 | |
with: | |
cargo-target-dir: ssufid/target | |
manifest-path: ssufid/Cargo.toml | |
- name: Set ssufid cache directory | |
run: | | |
mkdir -p .cache/ | |
mv .cache/ ssufid/ | |
# .으로 시작하는 폴더(.git, .github, .cache)와 ssufid 폴더를 제외한 | |
# 나머지 이전 데이터 폴더를 ssufid/out으로 이동시킵니다. | |
- name: Set previous data directory | |
run: | | |
shopt -s extglob | |
mkdir -p ssufid/out/ | |
mv !(.*|ssufid)/ ssufid/out/ | |
- name: Run ssufid | |
run: | | |
cd ssufid | |
cargo run | |
cd - | |
# TODO | |
# - name: Report error | |
# if: failure() | |
# run: ... report to slack or something | |
- name: Archive artifacts | |
if: always() | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ssufid/out/ | |
- name: Update data and cache | |
if: always() | |
run: | | |
cp -rv ssufid/.cache/ . | |
cp -rv ssufid/out/* . | |
- run: rm -rf ssufid | |
if: always() | |
- name: Push changes | |
if: always() | |
run: | | |
sudo timedatectl set-timezone 'Asia/Seoul' | |
git config user.name "GitHub Actions" | |
git config user.email "" | |
git add . | |
(git commit -m "update: $(date +'%Y-%m-%d %H:%M')" && git push) || echo "no changes to commit" | |
- name: Deploy to GitHub Pages | |
if: always() | |
uses: actions/deploy-pages@v4 |