[maimai] Update constants from Google Sheet #2152
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: "[maimai] Update constants from Google Sheet" | |
on: | |
schedule: | |
- cron: '0 */4 * * *' | |
workflow_dispatch: | |
jobs: | |
fetch_constants: | |
name: Fetch latest chart constants from Google Sheet | |
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/maimai-staging; then | |
git switch maimai-staging | |
git rebase origin/master | |
else | |
git checkout -b maimai-staging | |
fi | |
# git pull origin maimai-staging | |
# git push --force --set-upstream origin maimai-staging | |
- name: Run wiki script and capture output | |
id: run_script | |
run: | | |
{ | |
echo "OUTPUT_LOG<<EOF" | |
python scripts/update-const.py --maimai --all --nocolors --escape --markdown --no_timestamp --no_verbose | |
echo "EOF" | |
} >> "$GITHUB_OUTPUT" | |
- name: Extract datestamp from script output | |
id: extract_date | |
run: | | |
echo "datestamp=$(cat maimai/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(maimai): [bot] update song constants" | |
git push origin maimai-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 maimai-staging | grep maimai-staging) ]]; then | |
echo "PR currently open. Add comment to existing open PR" | |
gh pr comment maimai-staging \ | |
--body "${{ steps.run_script.outputs.OUTPUT_LOG }}" | |
else | |
echo "No currently open PR for maimai-staging. Create new PR" | |
gh pr create \ | |
-B ${{ github.ref_name }} \ | |
-H "maimai-staging" \ | |
--title "[Automation] maimai: 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 }} |