Skip to content

Commit

Permalink
Helper script for issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
sio committed Oct 15, 2021
1 parent 42fdd94 commit 6071392
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ package: | venv
.PHONY: upload
upload: package $(VENV)/twine
$(VENV)/twine upload $(TWINE_ARGS) dist/*


.PHONY: debug/build_status
debug/build_status: | venv
$(VENV)/python $@.py $(DEBUG_BUILD_ID)
40 changes: 40 additions & 0 deletions debug/build_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import json
import os
import sys
from time import sleep


from cirrus_run import CirrusAPI
from cirrus_run.cli import ENVIRONMENT


def main():
token = os.environ[ENVIRONMENT['token']]
api = CirrusAPI(token)
build_id = sys.argv[1]

query = '''
query GetBuild($build: ID!) {
build(id: $build) {
durationInSeconds
clockDurationInSeconds
status
buildCreatedTimestamp
changeTimestamp
}
}
'''
print('https://cirrus-ci.com/build/{}'.format(build_id))
while True:
response = api(query, params=dict(build=build_id))
print(json.dumps(response, indent=2, ensure_ascii=False))
try:
if response['build']['status'] not in {'CREATED', 'TRIGGERED', 'EXECUTING'}:
break
except (TypeError, KeyError) as exc:
pass
sleep(2)


if __name__ == '__main__':
main()

0 comments on commit 6071392

Please sign in to comment.