Skip to content

Commit 676cfa2

Browse files
committed
ci/wait-for-statuses: cleanup
Signed-off-by: Unai Martinez-Corral <[email protected]>
1 parent 4b60e79 commit 676cfa2

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

ci/wait-for-statuses.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,41 @@
11
#!/usr/bin/env python3
22

3-
import urllib.request
4-
import json
5-
import subprocess
6-
import time
7-
import os
8-
import sys
3+
from pathlib import Path
4+
from sys import exit as sys_exit
5+
from os import environ
6+
from subprocess import check_call
7+
from urllib.request import urlopen
8+
from json import loads as json_loads
99

1010
# We're limited to this number by GH Actions API
1111
# https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-jobs-for-a-workflow-run
1212
max_jobs = 100
1313

1414
status_url = "https://api.github.com/repos/" \
15-
+ os.environ['GITHUB_REPOSITORY'] \
15+
+ environ['GITHUB_REPOSITORY'] \
1616
+ "/actions/runs/" \
17-
+ os.environ['GITHUB_RUN_ID'] \
17+
+ environ['GITHUB_RUN_ID'] \
1818
+ "/jobs" \
1919
+ "?per_page=" + str(max_jobs)
2020

21-
numOfJobs = int(os.environ['NUM_OF_JOBS'])
21+
numOfJobs = int(environ.get('NUM_OF_JOBS', 0))
2222

2323
if(numOfJobs > max_jobs):
24-
sys.exit("ERROR: number of jobs exceeded max_jobs: " + str(max_jobs))
24+
sys_exit("ERROR: number of jobs exceeded max_jobs: " + str(max_jobs))
2525

2626
# Check if all jobs succeeded
2727
jobFailure = False
28-
with urllib.request.urlopen(status_url) as url:
29-
data = json.loads(url.read().decode())
28+
with urlopen(status_url) as url:
29+
data = json_loads(url.read().decode())
3030
for j in data["jobs"]:
3131
# THIS is master-package job, still in progress (not concluded)
3232
if(j["conclusion"] != "success" and j["name"] != "master-package"):
3333
jobFailure = True
3434
break
3535

36-
scripts_dir = os.environ['CI_SCRIPTS_PATH']
36+
scripts_dir = Path(environ['CI_SCRIPTS_PATH'])
3737

38-
branch = os.environ.get('GITHUB_REF', '')
39-
# Upload packages only when whole build succeeded and we are on master branch
40-
if not (branch == 'refs/heads/master'):
41-
print("Not on master branch, don't execute master-package.sh. Current branch: " + str(branch))
42-
elif(not jobFailure):
43-
subprocess.call(os.path.join(scripts_dir, "master-package.sh"))
38+
if environ.get('GITHUB_REF', '') == 'refs/heads/master':
39+
check_call(scripts_dir / "master-package.sh")
4440

45-
# Always clean up
46-
subprocess.call(os.path.join(scripts_dir, "cleanup-anaconda.sh"))
47-
48-
if(jobFailure):
49-
sys.exit("ERROR: some jobs failed")
41+
check_call(scripts_dir / "cleanup-anaconda.sh")

0 commit comments

Comments
 (0)