Skip to content

Commit 49c1e9a

Browse files
CI: Add auto-update
1 parent db8eda2 commit 49c1e9a

File tree

3 files changed

+168
-41
lines changed

3 files changed

+168
-41
lines changed

.github/workflows/pr.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: PR
2+
run-name: PR
3+
on:
4+
pull_request:
5+
types: [opened, reopened, labeled, synchronize]
6+
jobs:
7+
CI:
8+
uses: ./.github/workflows/ci.yml
9+
10+
Auto-Merge:
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
runs-on: ubuntu-latest
15+
needs: CI
16+
outputs:
17+
auto_release: ${{ steps.auto-merge.outputs.auto_release }}
18+
steps:
19+
- name: Check out repository code
20+
uses: actions/checkout@v4
21+
with:
22+
submodules: recursive
23+
- name: Auto-merge
24+
id: auto-merge
25+
env:
26+
GITHUB_TOKEN: ${{ github.token }}
27+
run: |
28+
prnum=$(jq --raw-output '.pull_request.number' "$GITHUB_EVENT_PATH")
29+
author=$(gh pr view "$prnum" --json 'author' --jq '.author.login')
30+
31+
git fetch --depth=1 origin master
32+
git fetch --depth=10 origin bot || exit 0
33+
if [ "$author" == "app/github-actions" ] && [ "$GITHUB_WORKFLOW_SHA" == "$(git rev-parse FETCH_HEAD)" ]; then
34+
git checkout master
35+
git merge origin/bot
36+
git push
37+
fi
38+
39+
if git log -1 --pretty="format:" --name-only | grep -q '^version.txt$'; then
40+
echo "auto_release=1" >> "$GITHUB_OUTPUT"
41+
fi
42+
43+
Auto-Release:
44+
permissions:
45+
actions: write
46+
runs-on: ubuntu-latest
47+
needs: Auto-Merge
48+
if: ${{ needs.Auto-Merge.outputs.auto_release }}
49+
steps:
50+
- name: Check out repository code
51+
uses: actions/checkout@v4
52+
with:
53+
submodules: recursive
54+
- name: Auto-release
55+
env:
56+
GITHUB_TOKEN: ${{ github.token }}
57+
run: |
58+
gh workflow run release.yml

.github/workflows/update.yml

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,83 @@ run-name: Update
33
on:
44
workflow_dispatch:
55
schedule:
6-
- cron: "0 8 * * *"
6+
- cron: "0 8,20 * * *"
77
jobs:
8-
Check-Updates:
8+
Update-Dependencies:
99
permissions:
10+
contents: write
11+
pull-requests: write
1012
issues: write
1113
runs-on: ubuntu-latest
1214
steps:
1315
- name: Check out repository code
1416
uses: actions/checkout@v4
1517
with:
16-
fetch-depth: 1
1718
submodules: recursive
18-
- name: Check updates
19+
- name: Update dependencies
1920
env:
2021
GITHUB_TOKEN: ${{ github.token }}
2122
run: |
22-
set -eu
23-
title='[BOT] Update Dependencies'
24-
message=''
23+
git config user.name 'GitHub Actions'
24+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
25+
git pull
26+
git branch -D bot 2>/dev/null || true
27+
git checkout -b bot
2528
26-
if [ "$(gh issue list --json 'id' --jq length --state 'open' --search "${title}")" != '0' ]; then
27-
echo 'Issue already exists, skipping...'
28-
exit 0
29-
fi
29+
has_updates=0
30+
31+
git submodule update --remote
3032
31-
pushd ./libfastjson
32-
git fetch origin
33-
if [ $(git rev-parse --verify origin/master) != $(git rev-parse --verify HEAD) ]; then
34-
message="${message}- libfastjson is outdated"$'\n'
33+
if [ -n "$(git diff libfastjson)" ]; then
34+
has_updates=1
35+
commitid=$(cd libfastjson && git rev-parse --short HEAD)
36+
git add libfastjson
37+
git commit -m "chore: Update submodule libfastjson to $commitid"
3538
fi
36-
popd
3739
38-
pushd ./libpatchelf/patchelf
39-
git fetch origin
40-
if [ $(git rev-parse --verify origin/master) != $(git rev-parse --verify HEAD) ]; then
41-
message="${message}- patchelf is outdated"$'\n'
40+
if [ -n "$(git diff libpatchelf/patchelf)" ]; then
41+
has_updates=1
42+
commitid=$(cd libpatchelf/patchelf && git rev-parse --short HEAD)
43+
git add libpatchelf/patchelf
44+
git commit -m "chore: Update submodule patchelf to $commitid"
4245
fi
43-
popd
4446
45-
scripts/update-deps.py
47+
bump_msg=$(scripts/update-deps.py)
48+
4649
if [ -n "$(git diff scripts/deps.sh)" ]; then
47-
message="${message}- \`scripts/deps.sh\` is outdated"$'\n'
50+
has_updates=1
51+
git add scripts/deps.sh version.txt
52+
git commit -m "chore: $bump_msg"
4853
fi
4954
50-
if [ -n "${message}" ]; then
51-
owner="$(gh repo view --json 'owner' --jq '.owner.login')"
52-
gh issue create --assignee "${owner}" --title "${title}" --body "${message}"
55+
if [ "$has_updates" -ne 0 ]; then
56+
echo "has_updates=1" >> $GITHUB_ENV
57+
git push --force -u origin bot
58+
fi
59+
- name: Open PR
60+
env:
61+
GITHUB_TOKEN: ${{ github.token }}
62+
if: ${{ env.has_updates }}
63+
run: |
64+
pr_url=$(gh pr create --head bot --base master --title "[BOT] Update dependencies" --body "Update dependencies")
65+
echo "pr_url=$pr_url" >> $GITHUB_ENV
66+
- name: Lable PR
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.pr_token }}
69+
if: ${{ env.pr_url }}
70+
run: |
71+
gh pr edit '${{ env.pr_url }}' --add-label bot
72+
- name: Create issue on failure
73+
if: failure()
74+
env:
75+
GITHUB_TOKEN: ${{ github.token }}
76+
run: |
77+
message="[BOT] Job ${{github.job}} is failling"
78+
owner="$(gh repo view --json 'owner' --jq '.owner.login')"
79+
len=$(gh issue list --json 'id' --jq length --state 'open' \
80+
--search "$message")
81+
if [ "$len" = '0' ]; then
82+
gh issue create --assignee "${owner}" \
83+
--title "$message" \
84+
--body "$message"
5385
fi

scripts/update-deps.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import json
44
import os
55
import re
6+
import sys
67
import urllib.request
78

9+
def eprint(msg):
10+
sys.stderr.write("%s\n" % (msg,))
11+
812

913
def get_latest(url, pattern):
1014
if type(pattern) is str:
@@ -92,6 +96,16 @@ def get_latest_mpfr_tar():
9296
return ver, url + tarname
9397

9498

99+
def get_current_vscode_prod_ver():
100+
prod_ver = None
101+
version_txt_path = os.path.join(os.path.dirname(__file__), "../version.txt")
102+
if os.path.isfile(version_txt_path):
103+
fo = open(version_txt_path, "r")
104+
prod_ver = fo.read().strip()
105+
fo.close()
106+
return prod_ver
107+
108+
95109
def update_latest_vscode_prod_ver():
96110
url = 'https://update.code.visualstudio.com/api/releases/stable'
97111
res = urllib.request.urlopen(url)
@@ -102,11 +116,18 @@ def update_latest_vscode_prod_ver():
102116
fo = open(version_txt_path, "w")
103117
fo.write(str(prod_ver).strip() + "\n")
104118
fo.close()
119+
return prod_ver
120+
121+
122+
def update_dict_add(d, name, old_ver, new_ver):
123+
if old_ver != new_ver:
124+
d[name] = new_ver, new_ver
105125

106126

107127
def update_deps_info():
108128
verdict = {}
109129
latest = {}
130+
updict = {}
110131
deps_path = os.path.join(os.path.dirname(__file__), "deps.sh")
111132
if os.path.exists(deps_path):
112133
fo = open(deps_path, "r")
@@ -120,62 +141,69 @@ def update_deps_info():
120141
verdict[k] = v
121142
fo.close()
122143

123-
print('updating binutils...')
144+
eprint('updating binutils...')
124145
latest['binutils_filename'] = "binutils-src.tar.xz"
125146
latest['binutils_version'], latest['binutils_url'] = get_latest_binutils_tar()
126147
latest['binutils_sha256'] = verdict['binutils_sha256'] if verdict.get('binutils_version') == latest['binutils_version'] else get_sha256(latest['binutils_url'])
148+
update_dict_add(updict, 'binutils', verdict.get('binutils_version'), latest['binutils_version'])
127149

128-
print('updating gcc...')
150+
eprint('updating gcc...')
129151
latest['gcc_filename'] = "gcc-src.tar.xz"
130152
latest['gcc_version'], latest['gcc_url'] = get_latest_gcc_tar()
131153
latest['gcc_sha256'] = verdict['gcc_sha256'] if verdict.get('gcc_version') == latest['gcc_version'] else get_sha256(latest['gcc_url'])
154+
update_dict_add(updict, 'gcc', verdict.get('gcc_version'), latest['gcc_version'])
132155

133-
print('updating glibc...')
156+
eprint('updating glibc...')
134157
latest['glibc_filename'] = "glibc-src.tar.xz"
135158
latest['glibc_version'], latest['glibc_url'] = get_latest_glibc_tar()
136159
latest['glibc_sha256'] = verdict['glibc_sha256'] if verdict.get('glibc_version') == latest['glibc_version'] else get_sha256(latest['glibc_url'])
160+
update_dict_add(updict, 'glibc', verdict.get('glibc_version'), latest['glibc_version'])
137161

138-
print('updating gmp...')
162+
eprint('updating gmp...')
139163
latest['gmp_filename'] = "gmp-src.tar.xz"
140164
latest['gmp_version'], latest['gmp_url'] = get_latest_gmp_tar()
141165
latest['gmp_sha256'] = verdict['gmp_sha256'] if verdict.get('gmp_version') == latest['gmp_version'] else get_sha256(latest['gmp_url'])
166+
update_dict_add(updict, 'gmp', verdict.get('gmp_version'), latest['gmp_version'])
142167

143-
print('updating linux...')
168+
eprint('updating linux...')
144169
latest['linux_filename'] = "linux-src.tar.xz"
145170
latest['linux_version'], latest['linux_url'] = get_latest_linux_tar()
146171
latest['linux_sha256'] = verdict['linux_sha256'] if verdict.get('linux_version') == latest['linux_version'] else get_sha256(latest['linux_url'])
172+
update_dict_add(updict, 'linux', verdict.get('linux_version'), latest['linux_version'])
147173

148-
print('updating mpc...')
174+
eprint('updating mpc...')
149175
latest['mpc_filename'] = "mpc-src.tar.gz"
150176
latest['mpc_version'], latest['mpc_url'] = get_latest_mpc_tar()
151177
latest['mpc_sha256'] = verdict['mpc_sha256'] if verdict.get('mpc_version') == latest['mpc_version'] else get_sha256(latest['mpc_url'])
178+
update_dict_add(updict, 'mpc', verdict.get('mpc_version'), latest['mpc_version'])
152179

153-
print('updating mpfr...')
180+
eprint('updating mpfr...')
154181
latest['mpfr_filename'] = "mpfr-src.tar.xz"
155182
latest['mpfr_version'], latest['mpfr_url'] = get_latest_mpfr_tar()
156183
latest['mpfr_sha256'] = verdict['mpfr_sha256'] if verdict.get('mpfr_version') == latest['mpfr_version'] else get_sha256(latest['mpfr_url'])
184+
update_dict_add(updict, 'mpfr', verdict.get('mpfr_version'), latest['mpfr_version'])
157185

158-
print('updating vscode_cli_arm64...')
186+
eprint('updating vscode_cli_arm64...')
159187
latest['vscode_cli_arm64_filename'] = "vscode-cli-arm64.tar.gz"
160188
latest['vscode_cli_arm64_version'], latest['vscode_cli_arm64_url'], latest['vscode_cli_arm64_sha256'] = get_latest_vscode('cli-linux-arm64')
161189

162-
print('updating vscode_cli_armhf...')
190+
eprint('updating vscode_cli_armhf...')
163191
latest['vscode_cli_armhf_filename'] = "vscode-cli-armhf.tar.gz"
164192
latest['vscode_cli_armhf_version'], latest['vscode_cli_armhf_url'], latest['vscode_cli_armhf_sha256'] = get_latest_vscode('cli-linux-armhf')
165193

166-
print('updating vscode_cli_x64...')
194+
eprint('updating vscode_cli_x64...')
167195
latest['vscode_cli_x64_filename'] = "vscode-cli-x64.tar.gz"
168196
latest['vscode_cli_x64_version'], latest['vscode_cli_x64_url'], latest['vscode_cli_x64_sha256'] = get_latest_vscode('cli-linux-x64')
169197

170-
print('updating vscode_server_arm64...')
198+
eprint('updating vscode_server_arm64...')
171199
latest['vscode_server_arm64_filename'] = "vscode-srv-arm64.tar.gz"
172200
latest['vscode_server_arm64_version'], latest['vscode_server_arm64_url'], latest['vscode_server_arm64_sha256'] = get_latest_vscode('server-linux-arm64')
173201

174-
print('updating vscode_server_armhf...')
202+
eprint('updating vscode_server_armhf...')
175203
latest['vscode_server_armhf_filename'] = "vscode-srv-armhf.tar.gz"
176204
latest['vscode_server_armhf_version'], latest['vscode_server_armhf_url'], latest['vscode_server_armhf_sha256'] = get_latest_vscode('server-linux-armhf')
177205

178-
print('updating vscode_server_x64...')
206+
eprint('updating vscode_server_x64...')
179207
latest['vscode_server_x64_filename'] = "vscode-srv-x64.tar.gz"
180208
latest['vscode_server_x64_version'], latest['vscode_server_x64_url'], latest['vscode_server_x64_sha256'] = get_latest_vscode('server-linux-x64')
181209

@@ -184,8 +212,17 @@ def update_deps_info():
184212
fo.write("%s=%s\n" % (k, latest[k]))
185213
fo.close()
186214

187-
print('updating vscode product version...')
188-
update_latest_vscode_prod_ver()
215+
eprint('updating vscode product version...')
216+
old_vscode_ver = get_current_vscode_prod_ver()
217+
new_vscode_ver = update_latest_vscode_prod_ver()
218+
update_dict_add(updict, 'vscode', old_vscode_ver, new_vscode_ver)
219+
220+
msg_list = []
221+
for name, (old_ver, new_ver) in updict.items():
222+
msg_list.append("Bump %s version to %s" % (name, new_ver))
223+
if msg_list:
224+
eprint("------\n")
225+
print("; ".join(msg_list))
189226

190227

191228
def main():

0 commit comments

Comments
 (0)