-
Notifications
You must be signed in to change notification settings - Fork 3
143 lines (119 loc) · 4.96 KB
/
update-genshin.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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 }}"
REPO="dvaJi/genshin-data"
PER_PAGE=100
PAGE=1
ALL_COMMITS=""
while true; do
COMMITS=$(gh api "repos/$REPO/commits?per_page=$PER_PAGE&page=$PAGE" \
--jq '.[] | "\(.sha) \(.commit.message)"')
if [ -z "$COMMITS" ]; then
break
fi
FILTERED_COMMITS=$(echo "$COMMITS" | awk -v last="$LAST_COMMIT" '
$1 == last {exit}
/feat: update .*data .*(v|version).*[0-9]+\.[0-9]+$/ {
gsub(/version[[:space:]]?/, "v");
gsub(/v[[:space:]]?/, "v");
print
}
')
echo "$FILTERED_COMMITS"
ALL_COMMITS="$ALL_COMMITS
$FILTERED_COMMITS"
if echo "$COMMITS" | grep -q "$LAST_COMMIT"; then
break
fi
PAGE=$((PAGE + 1))
done
if [ -z "$ALL_COMMITS" ]; then
echo "No new commits to process."
echo "new_commits=" >> $GITHUB_OUTPUT
exit 0
fi
ESCAPED_COMMITS=$(echo "$ALL_COMMITS" | sed 's/$/\\n/' | tr -d '\n')
echo "new_commits<<EOF" >> $GITHUB_OUTPUT
echo -e "$ESCAPED_COMMITS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
VERSIONS=$(echo "$ALL_COMMITS" | sed -n 's/.*v\([0-9]\+\.[0-9]\+\)$/\1/p' | tr '\n' ' ')
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
readarray -t COMMIT_ARRAY <<< "$COMMITS"
# Process commits in reverse order
for ((i=${#COMMIT_ARRAY[@]}-1; i>=0; i--)); do
# Remove line number and extract commit hash and message
LINE=$(echo "${COMMIT_ARRAY[i]}")
COMMIT=$(echo "$LINE" | awk '{print $1}')
MESSAGE=$(echo "$LINE" | cut -d' ' -f2-)
# Debug: Print extracted COMMIT and MESSAGE
echo "Extracted MESSAGE: $MESSAGE"
VERSION=$(echo "$MESSAGE" | sed -n 's/.*v\([0-9]\+\.[0-9]\+\)$/\1/p')
if [ "$COMMIT" == "388d16c6f1ad3118f38365b77dbf9bc32474c837" ]; then
VERSION="3.6"
fi
# Check if COMMIT is not empty and 40 characters long before proceeding
if [ -n "$COMMIT" ] && [ ${#COMMIT} -eq 40 ]; then
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"
else
echo "Warning: Invalid COMMIT for line: ${COMMIT_ARRAY[i]}"
fi
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-${{ github.run_number }}
delete-branch: true