Skip to content

Commit 47d89ea

Browse files
Merge pull request #3 from RandomCoderOrg/auto-entry-release-builds
auto update json
2 parents d6c1617 + 2969dc0 commit 47d89ea

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

.github/workflows/build-and-release.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,15 @@ jobs:
7777
hub release edit -F release.md "${assets[@]}" -m "$tag_name" "$tag_name"
7878
env:
7979
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
81+
- name: update json
82+
run: |
83+
sudo apt-get install python3 -y
84+
sudo python3 gen-update-json.py --release-tag ${{ env.VERSIONTAG }}
85+
set +e
86+
git config user.name github-actions[bot]
87+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
88+
git add --all
89+
git commit -m "AUTO: update distro-data.json"
90+
git push
91+
set -e

gen-update-json.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import os
2+
import json
3+
import optparse
4+
5+
GIT_ROOT = os.popen("git rev-parse --show-toplevel").read().strip()
6+
DIR = "."
7+
VERBOSE = False
8+
JSON_CONF = f"{GIT_ROOT}/distro-data.json"
9+
10+
def update_json_conf(file) -> None:
11+
data = strip_info(file)
12+
jdata = json.load(open(JSON_CONF, 'r'))
13+
14+
# update url
15+
jdata[data[0]][data[1]][f"{data[2]}Url"] = get_release_url(
16+
RELEASE_TAG, data[3])
17+
18+
# update sha
19+
jdata[data[0]][data[1]][f"{data[2]}sha"] = os.popen(
20+
f"sha256sum {DIR}/{data[3]}").read().split()[0]
21+
22+
# update JSON_CONF
23+
file = open(JSON_CONF, 'w')
24+
json.dump(jdata, file, indent=4)
25+
26+
27+
def strip_info(file):
28+
basename = os.path.basename(file)
29+
name = os.path.splitext(basename)[0]
30+
name = os.path.splitext(name)[0]
31+
32+
sp = name.split("-")
33+
ar = {
34+
"armhf": "armhf",
35+
"arm": "armhf",
36+
"arm64": "aarch64",
37+
"aarch64": "aarch64",
38+
"amd64": "amd64",
39+
"x86_64": "amd64"
40+
}
41+
42+
suite = sp[0]
43+
variant = sp[1]
44+
arch = ar[sp[2]]
45+
46+
return [suite, variant, arch, basename]
47+
48+
def get_release_url(release_tag, file) -> str:
49+
repo="https://github.com/RandomCoderOrg/udroid-download"
50+
url="{}/releases/download/{}/{}".format(repo, release_tag, file)
51+
return url
52+
53+
if __name__ == '__main__':
54+
# parse command line options
55+
parser = optparse.OptionParser()
56+
57+
parser.add_option('-R', '--release-tag', dest='release_tag',
58+
help='release tag', type=str)
59+
60+
options, args = parser.parse_args()
61+
# get release tag
62+
63+
RELEASE_TAG = options.release_tag
64+
for file in os.listdir(DIR):
65+
if file.endswith(".tar.gz"):
66+
update_json_conf(file)
67+

0 commit comments

Comments
 (0)