Skip to content

Update Data from Source #136

Update Data from Source

Update Data from Source #136

name: Update Data from Source
on:
schedule:
- cron: "0 0 * * *" # Runs every day at midnight UTC
workflow_dispatch:
jobs:
update-data:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout dvalin-data repo
uses: actions/checkout@v4
with:
repository: "dval-in/dvalin-data"
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Get last processed commit
id: get_last_commit
run: echo "last_commit=$(cat .last_processed_commit || echo '')" >> $GITHUB_OUTPUT
- name: Fetch commit history
id: fetch_commits
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LAST_COMMIT="${{ steps.get_last_commit.outputs.last_commit }}"
COMMITS=$(gh api repos/dvaJi/genshin-data/commits \
--jq '.[] | "\(.sha) \(.commit.message)"' | \
awk -v last="$LAST_COMMIT" '
$1 == last {exit}
/^[^ ]+ feat: update GI data v[0-9]+\.[0-9]+$/ {print}
')
if [ -z "$COMMITS" ]; then
echo "No new commits to process."
echo "new_commits=" >> $GITHUB_OUTPUT
exit 0
fi
VERSIONS=$(echo "$COMMITS" | sed -n 's/.*v\([0-9]\+\.[0-9]\+\)$/\1/p' | tr '\n' ' ')
echo "new_commits=$COMMITS" >> $GITHUB_OUTPUT
echo "versions=$VERSIONS" >> $GITHUB_OUTPUT
- name: Process new commits
if: steps.fetch_commits.outputs.new_commits != ''
env:
COMMITS: ${{ steps.fetch_commits.outputs.new_commits }}
VERSIONS: ${{ steps.fetch_commits.outputs.versions }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "GitHub Actions Bot"
git config user.email "[email protected]"
git clone https://github.com/dvaJi/genshin-data.git
echo "$COMMITS" | while read -r COMMIT MESSAGE; do
VERSION=$(echo "$MESSAGE" | sed -n 's/.*v\([0-9]\+\.[0-9]\+\)$/\1/p')
gh api "repos/dvaJi/genshin-data/git/trees/$COMMIT?recursive=1" \
--jq '.tree[] | select(.type == "blob") | .path' > changed_files.txt
bun run ./scripts/workflow/update_file.ts "$VERSION"
echo "$COMMIT" > .last_processed_commit
git add .
git commit -m "feat: update dvalin data v$VERSION"
done
rm -rf genshin-data
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Auto-update: Dvalin Data Update"
title: "Auto-update: Dvalin Data v${{ steps.fetch_commits.outputs.versions }}"
body: |
This is an automated pull request to update Dvalin data.
Updates made in this pull request:
- Updated data to version(s): ${{ steps.fetch_commits.outputs.versions }}
Please review the changes and merge if everything looks correct.
branch: update-dvalin-data-${{ steps.fetch_commits.outputs.versions }}
base: main
delete-branch: true