Crawl KdB #785
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 KdB | |
permissions: | |
contents: write | |
on: | |
schedule: | |
- cron: "0 15 * * *" | |
workflow_dispatch: | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
crawl: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
sparse-checkout: | | |
/* | |
!/dist/ | |
sparse-checkout-cone-mode: false | |
- name: Cache Rust project | |
id: cache-rust-project | |
uses: actions/cache@v4 | |
with: | |
path: ./target/release/kdb-crawler | |
key: ${{ runner.os }}-binary-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/*.rs') }} | |
- uses: dtolnay/rust-toolchain@stable | |
if: steps.cache-rust-project.outputs.cache-hit != 'true' | |
- name: Build | |
run: cargo build --release | |
if: steps.cache-rust-project.outputs.cache-hit != 'true' | |
- name: Run binary | |
run: ./target/release/kdb-crawler | |
env: | |
KDB_URL: ${{ vars.KDB_URL }} | |
- name: Check for empty commit | |
id: check_empty_commit | |
run: | | |
if [ -z "$(git status --porcelain --ignored | grep 'M dist/')" ]; then | |
echo "KdB に差分が存在しないため、以降のタスクをスキップします。" | |
echo "skip_commit=true" >> $GITHUB_ENV | |
else | |
echo "skip_commit=false" >> $GITHUB_ENV | |
fi | |
- name: Commit files | |
if: env.skip_commit == 'false' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add --sparse -f ./dist/ | |
DATE=$(TZ=Asia/Tokyo date -u +"%Y-%m-%d") | |
git commit -m "Update KdB to $DATE" | |
git push |