|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 |
|
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 |
9 | 9 |
|
10 | 10 | # We're limited to this number by GH Actions API
|
11 | 11 | # https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-jobs-for-a-workflow-run
|
12 | 12 | max_jobs = 100
|
13 | 13 |
|
14 | 14 | status_url = "https://api.github.com/repos/" \
|
15 |
| - + os.environ['GITHUB_REPOSITORY'] \ |
| 15 | + + environ['GITHUB_REPOSITORY'] \ |
16 | 16 | + "/actions/runs/" \
|
17 |
| - + os.environ['GITHUB_RUN_ID'] \ |
| 17 | + + environ['GITHUB_RUN_ID'] \ |
18 | 18 | + "/jobs" \
|
19 | 19 | + "?per_page=" + str(max_jobs)
|
20 | 20 |
|
21 |
| -numOfJobs = int(os.environ['NUM_OF_JOBS']) |
| 21 | +numOfJobs = int(environ.get('NUM_OF_JOBS', 0)) |
22 | 22 |
|
23 | 23 | 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)) |
25 | 25 |
|
26 | 26 | # Check if all jobs succeeded
|
27 | 27 | 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()) |
30 | 30 | for j in data["jobs"]:
|
31 | 31 | # THIS is master-package job, still in progress (not concluded)
|
32 | 32 | if(j["conclusion"] != "success" and j["name"] != "master-package"):
|
33 | 33 | jobFailure = True
|
34 | 34 | break
|
35 | 35 |
|
36 |
| -scripts_dir = os.environ['CI_SCRIPTS_PATH'] |
| 36 | +scripts_dir = Path(environ['CI_SCRIPTS_PATH']) |
37 | 37 |
|
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") |
44 | 40 |
|
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