-
-
Notifications
You must be signed in to change notification settings - Fork 6
129 lines (113 loc) · 5.12 KB
/
wiki.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
name: 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 --nocolors --escape
python scripts/update-chartguide-data.py --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: Check script output
id: check_script
run: |
if [[ "${{ steps.run_script.outputs.OUTPUT_LOG }}" == *"Updated song extra data from wiki"* ]]; then
echo "Updated song data from wiki. Creating a pull request."
echo "COMMIT=true" >> "$GITHUB_OUTPUT"
else
echo "Nothing updated. Skipping pull request creation."
echo "COMMIT=false" >> "$GITHUB_OUTPUT"
fi
- name: Get existing branch if already exists
id: get_existing_branch
if: steps.check_script.outputs.COMMIT == 'true'
run: |
existing_branch=$(git branch -r --format='%(refname:short)' --sort='-committerdate' | grep origin/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
if: steps.check_script.outputs.COMMIT == 'true'
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/update-\* | head -n 1)
else
echo "Creating new branch"
git checkout -b update-${{ steps.extract_date.outputs.DATESTAMP }}
fi
git commit -m "[Automated] Apply updated data from wiki ${{ steps.extract_date.outputs.DATESTAMP }}"
git push origin 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] Update website with updated song data (${{ steps.extract_date.outputs.DATESTAMP }})" \
--body "${{ steps.run_script.outputs.OUTPUT_LOG }}"
else
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 "${{ steps.get_existing_branch.outputs.EXISTING_BRANCH }}" \
--title "[Automation] 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 }}