Skip to content

Commit f197c98

Browse files
committed
Find builds with more than one task
1 parent d6d00fa commit f197c98

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,10 @@ upload: package $(VENV)/twine
4747
.PHONY: debug/build_status
4848
debug/build_status: | venv
4949
$(VENV)/python $@.py $(DEBUG_BUILD_ID)
50+
51+
52+
.PHONY: debug/find_multiple_tasks
53+
debug/find_multiple_tasks: export CIRRUS_GITHUB_REPO?=libvirt/libvirt
54+
debug/find_multiple_tasks: export CIRRUS_API_TOKEN?=" "
55+
debug/find_multiple_tasks:
56+
$(VENV)/python $@.py

debug/find_multiple_tasks.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'''
2+
Helper script for issue #4: https://github.com/sio/cirrus-run/issues/4
3+
4+
Find recent builds that contain more than one task. This is helpful for finding
5+
builds where a single defined task was automatically restarted by CirrusCI due
6+
to GCP instance termination.
7+
8+
Execute `make debug/find_multiple_tasks` from repo top-level directory
9+
'''
10+
11+
import os
12+
from cirrus_run import CirrusAPI
13+
from cirrus_run.cli import ENVIRONMENT
14+
from cirrus_run.queries import get_repo
15+
16+
17+
def main(*a, **ka):
18+
token = os.environ.get(ENVIRONMENT['token'], "")
19+
api = CirrusAPI(token)
20+
owner, repo = os.environ[ENVIRONMENT['github']].split('/')
21+
repo_id = get_repo(api, owner, repo)
22+
23+
print('Recent builds in {owner}/{repo} with more than 1 task:'.format(**locals()))
24+
for url in filter_builds(api, repo_id):
25+
print(' {}'.format(url))
26+
27+
28+
def filter_builds(api, repo_id):
29+
query = '''
30+
query tasks_by_job($repo_id: ID!) {
31+
repository(id: $repo_id) {
32+
builds(last: 100) {
33+
edges {
34+
node {
35+
id
36+
tasks {
37+
id
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
'''
45+
params = dict(repo_id=repo_id)
46+
response = api(query, params)
47+
url = 'https://cirrus-ci.com/build/{}'
48+
49+
for build in response['repository']['builds']['edges']:
50+
if len(build['node']['tasks']) > 1:
51+
build_id = build['node']['id']
52+
yield url.format(build_id)
53+
54+
55+
if __name__ == '__main__':
56+
main()

0 commit comments

Comments
 (0)