[Chunithm] Fetch from wiki & sdvx.in #2168
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: '5 */4 * * *' | |
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 | |
with: | |
fetch-depth: 0 | |
- 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: Checkout existing branch or create new | |
run : | | |
git fetch origin | |
if git show-ref --quiet refs/remotes/origin/chunithm-staging; then | |
git switch chunithm-staging | |
git rebase origin/master | |
else | |
git checkout -b chunithm-staging | |
fi | |
# git pull origin chunithm-staging | |
# git push --force --set-upstream origin chunithm-staging | |
- name: Run wiki script and capture output | |
id: run_script | |
run: | | |
{ | |
echo "OUTPUT_LOG<<EOF" | |
python scripts/update-wiki-data.py --chunithm --nocolors --escape --markdown --noskip --no_timestamp --no_verbose | |
python scripts/update-chartguide-data.py --chunithm --nocolors --escape --markdown --no_timestamp --no_verbose | |
echo "EOF" | |
} >> "$GITHUB_OUTPUT" | |
- name: Extract datestamp from script output | |
id: extract_date | |
run: | | |
echo "datestamp=$(cat chunithm/data/music-ex.json | jq '.[-1].date_added | tonumber')" >> "$GITHUB_OUTPUT" | |
# echo "datestamp=$(date '+%Y%m%d')" >> "$GITHUB_OUTPUT" | |
- name: Commit changes | |
id: commit_changes | |
env: | |
UNIQUE_STRING: ${{ github.run_id }}-${{ github.run_attempt }} | |
run: | | |
git add . | |
if output=$(git status --porcelain) && [ -z "$output" ]; then | |
echo "HAS_DIFFS=false" >> "$GITHUB_OUTPUT" | |
echo "No changes. Skipping PR request" | |
else | |
git commit -m "data(chunithm): [bot] add song extra data ${{ steps.extract_date.outputs.DATESTAMP }}" | |
git push origin chunithm-staging --force-with-lease | |
echo "Commited changes." | |
echo "HAS_DIFFS=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Checkout existing PR or create new | |
if: steps.commit_changes.outputs.HAS_DIFFS == 'true' | |
run: | | |
if [[ $(gh pr list --state open --head chunithm-staging | grep chunithm-staging) ]]; then | |
echo "PR currently open. Add comment to existing open PR" | |
gh pr comment chunithm-staging \ | |
--body "${{ steps.run_script.outputs.OUTPUT_LOG }}" | |
else | |
echo "No currently open PR for chunithm-staging. Create new PR" | |
gh pr create \ | |
-B ${{ github.ref_name }} \ | |
-H "chunithm-staging" \ | |
--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 }} |