[Chunithm] Fetch from wiki & sdvx.in #4
This file contains 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: "[Chunithm] Fetch from wiki & sdvx.in" | |
on: | |
schedule: | |
- cron: '0 2 * * THU' | |
workflow_dispatch: | |
jobs: | |
fetch_from_wiki: | |
name: Fetch from wiki & sdvx.in | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set timezone | |
uses: szenius/[email protected] | |
with: | |
timezoneLinux: "Asia/Tokyo" | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.x | |
- name: Install dependencies | |
run: | | |
pip install -r requirements.txt | |
- name: Configure Git user | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
- name: Run wiki script and capture output | |
id: run_script | |
run: | | |
{ | |
echo "OUTPUT_LOG<<EOF" | |
python scripts/update-wiki-data.py --chunithm --nocolors --escape | |
python scripts/update-chartguide-data.py --chunithm --nocolors --escape | |
echo "EOF" | |
} >> "$GITHUB_OUTPUT" | |
- name: Extract datestamp from script output | |
id: extract_date | |
run: echo "datestamp=$(cat data/music-ex.json | jq '.[-1].date | tonumber')" >> "$GITHUB_OUTPUT" | |
- name: Get existing branch if already exists | |
id: get_existing_branch | |
run: | | |
existing_branch=$(git branch -r --format='%(refname:short)' --sort='-committerdate' | grep origin/chunithm-update-\* | head -n 1 | sed 's/^origin\///') | |
echo "${existing_branch}" | |
if [ ! -z "${existing_branch}" ]; then | |
echo "Existing branch found. Checking out branch" | |
echo "EXISTING_BRANCH=${existing_branch}" >> "$GITHUB_OUTPUT" | |
else | |
echo "No existing branch found" | |
fi | |
- name: Create new branch and commit changes | |
id: checkout_branch_commit | |
env: | |
UNIQUE_STRING: ${{ github.run_id }}-${{ github.run_attempt }} | |
run: | | |
echo ${{ steps.get_existing_branch.outputs.EXISTING_BRANCH }} | |
git add . | |
if output=$(git status --porcelain) && [ -z "$output" ]; then | |
echo "HAS_DIFFS=false" >> "$GITHUB_OUTPUT" | |
echo "No changes. Skipping PR request" | |
else | |
if [ ! -z ${{ steps.get_existing_branch.outputs.EXISTING_BRANCH }} ]; then | |
echo "Branch already exists, checkout existing branch" | |
git fetch origin | |
git checkout \ | |
-b ${{ steps.get_existing_branch.outputs.EXISTING_BRANCH }} \ | |
--track $(git branch -r --format='%(refname:short)' --sort='-committerdate' | grep origin/chunithm-update-\* | head -n 1) | |
else | |
echo "Creating new branch" | |
git checkout -b chunithm-update-${{ steps.extract_date.outputs.DATESTAMP }} | |
fi | |
git commit -m "[Automated] Apply updated data from wiki ${{ steps.extract_date.outputs.DATESTAMP }}" | |
git push origin chunithm-update-${{ steps.extract_date.outputs.DATESTAMP }} | |
echo "Commited changes." | |
echo "HAS_DIFFS=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Checkout existing PR or create new | |
if: steps.checkout_branch_commit.outputs.HAS_DIFFS == 'true' | |
run: | | |
if [ ! -z ${{ steps.get_existing_branch.outputs.EXISTING_BRANCH }} ]; then | |
if [[ $(gh pr list --state merged --head ${{ steps.get_existing_branch.outputs.EXISTING_BRANCH }} | grep ${{ steps.get_existing_branch.outputs.EXISTING_BRANCH }}) ]]; then | |
echo "Previous PR for this branch is already merged. Create new PR" | |
gh pr create \ | |
-B ${{ github.ref_name }} \ | |
-H "${{ steps.get_existing_branch.outputs.EXISTING_BRANCH }}" \ | |
--title "[Automation] Chunithm: Update website with updated song data (${{ steps.extract_date.outputs.DATESTAMP }})" \ | |
--body "${{ steps.run_script.outputs.OUTPUT_LOG }}" | |
else | |
echo "Add comment to existing open PR" | |
gh pr comment ${{ steps.get_existing_branch.outputs.EXISTING_BRANCH }} \ | |
--body "${{ steps.run_script.outputs.OUTPUT_LOG }}" | |
fi | |
else | |
echo "No previous PR found. Create new PR" | |
gh pr create \ | |
-B ${{ github.ref_name }} \ | |
-H "chunithm-update-${{ steps.extract_date.outputs.DATESTAMP }}" \ | |
--title "[Automation] Chunithm: Update website with updated song data (${{ steps.extract_date.outputs.DATESTAMP }})" \ | |
--body "${{ steps.run_script.outputs.OUTPUT_LOG }}" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |