-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-for-new-release-requests.py
executable file
·131 lines (114 loc) · 4.68 KB
/
check-for-new-release-requests.py
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
#!/usr/bin/env python3
"""Scans all repositories, looking for tags with the following
naming convention:
release/<rock>/<revision>/<targetTrack>/<targetRisk>
If there are any of these tags, without an associated GitHub release,
then release and re-tag (OCI) that ROCK."""
import logging
import os
import re
import requests
import sys
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(SCRIPT_DIR)
from helper_functions import get_all_pages, check_org_argparse, list_rocks_projects
ORG = "rockcrafters"
GIT_API_URL = "https://api.github.com"
SUPPORTED_RISKS = ["edge", "beta", "candidate", "stable"]
if __name__ == "__main__":
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
parser = check_org_argparse(
"Scan the rockcrafters GitHub organization, finding which ROCK repos asking for releases to be made."
)
args = parser.parse_args()
headers = {
"Authorization": f"token {args.token}",
"Accept": "application/vnd.github+json",
}
rocks_projects, exclude_repos = list_rocks_projects(
GIT_API_URL, ORG, headers, args.on_repo
)
new_release_tags = []
for rock in rocks_projects:
if rock["name"] in exclude_repos:
continue
logging.info(f"Scanning new release requests in {rock['name']} project...")
# Get all tags
url = f"{GIT_API_URL}/repos/{ORG}/{rock['name']}/tags"
all_rock_tags = get_all_pages(url, headers, {})
release_tags = list(
filter(
lambda t: re.match(
rf"release/.*/[0-9]+/.*/({'|'.join(SUPPORTED_RISKS)})$", t["name"]
),
all_rock_tags,
)
)
build_tags = list(
filter(
lambda t: re.match(
r"channels/.*/.*/.*/[0-9][0-9]\.[0-9][0-9]/[0-9]+$", t["name"]
),
all_rock_tags,
)
)
for rtag in release_tags:
# Get GH release (if any) for this tag
url = (
f"{GIT_API_URL}/repos/{ORG}/{rock['name']}/releases/tags/{rtag['name']}"
)
gh_release = requests.get(url, headers=headers)
try:
gh_release.raise_for_status()
except requests.exceptions.HTTPError as err:
if "404" in str(err):
# This is want we are looking for - a release tag without a GH release
pass
else:
raise
else:
# There is already a GH release for this release tag...move on
continue
rock_image_name, revision, track, risk = rtag["name"].split("/")[1:]
logging.info(
f"There is a release request tag {rtag['name']} without a GitHub release"
)
# Confirm that the corresponding release tag as an associated build tag
corresponding_build_tag = [
t
for t in build_tags
if t["name"].endswith(f"/{revision}") and f"{rock_image_name}/{track}" in t["name"]
]
if not corresponding_build_tag:
logging.warning(
(
f"Release request tag {rtag['name']} does not have "
f"a matching build tag with revision number {revision}"
)
)
continue
if corresponding_build_tag[0]["commit"]["sha"] != rtag["commit"]["sha"]:
raise Exception(
f"The requested release tag {rtag['name']} does not point to the "
f"same commit as its corresponding build tag {corresponding_build_tag[0]['name']}"
)
build_tag_name = corresponding_build_tag[0]["name"]
rock_name, rock_version, rock_base = build_tag_name.split("/")[-4:-1]
revision, track, risk = rtag["name"].split("/")[2:]
new_release_tags.append(
{
"full_name": f"{ORG}/{rock['name']}",
"name": rock["name"],
"sha": rtag["commit"]["sha"],
"tag": rtag["name"],
"revision": revision,
"track": track,
"risk": risk,
"all_risks": f"{risk} {' '.join(SUPPORTED_RISKS[:SUPPORTED_RISKS.index(risk)])}",
"build_tag": build_tag_name,
"rock_name": rock_name,
"rock_version": rock_version,
"rock_base": rock_base,
}
)
print(f"::set-output name=releases::{new_release_tags}")