-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor taskcluster artifact download into a composite action
- Loading branch information
Showing
5 changed files
with
103 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Download taskcluster artifact | ||
descrion: Download artifacts from a Taskcluster task | ||
inputs: | ||
taskid: | ||
description: 'Taskcluster task identifier to fetch artifacts from' | ||
required: true | ||
type: string | ||
artifact-name: | ||
description: "Artifact name to download from the task" | ||
required: true | ||
type: string | ||
path: | ||
description: Location to save the artifact | ||
default: ${{ github.workspace }} | ||
type: string | ||
|
||
runs: | ||
using: "composite" | ||
env: | ||
TASKGRAPH_TASK_URL: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/${{ inputs.taskid }} | ||
TASKGRAPH_ARTIFACT: public%2Fbuild%2F${{ inputs.artifact-name }} | ||
steps: | ||
- name: Wait for taskcluster job | ||
id: taskgraph | ||
shell: bash | ||
run: | | ||
pip install requests | ||
${{ github.action_path }}/await-taskcluster-status.py -t 3600 ${{ inputs.task-id }} | tee ${{ runner.temp }}/taskcluster-job-status.json | ||
echo run-id=$(jq '.runs[] | select(.state == "completed").runId' ${{ runner.temp }}/taskcluster-job-status.json) >> $GITHUB_OUTPUT | ||
- name: Download build artifact | ||
shell: bash | ||
run: | | ||
curl -sSL -o ${{ inputs.path }}/${{ inputs.artifact-name }} \ | ||
${TASKGRAPH_TASK_URL}/runs/${{ steps.taskgraph.outputs.run-id }}/artifacts/${TASKGRAPH_ARTIFACT} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import requests | ||
import json | ||
import os | ||
import sys | ||
|
||
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN') | ||
|
||
def fetch(url, version='2022-11-28', timeout=None): | ||
headers = { | ||
'Accept': 'application/vnd.github+json', | ||
'X-GitHub-Api-Version': version, | ||
} | ||
if GITHUB_TOKEN is not None: | ||
headers['Authorization'] = f"Bearer {GITHUB_TOKEN}" | ||
|
||
r = requests.get(url, headers) | ||
if r.status_code != 200: | ||
r.raise_for_status() | ||
return r.json() | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Await a external check to complete") | ||
parser.add_argument("ref", metavar="REF", type=str, action="store", | ||
help="Github reference fetch checks for") | ||
parser.add_argument("name", metavar="NAME", type=str, action="store", | ||
help="Name of the check to wait for") | ||
parser.add_argument("-a", "--app", metavar="SUITE", type=str, action="store", | ||
help="App name to fetch checks from") | ||
args = parser.parse_args() | ||
|
||
# Find the URL to fetch checks from. | ||
checks_url = None | ||
if args.app: | ||
js = fetch(f"https://api.github.com/repos/mozilla-mobile/mozilla-vpn-client/commits/{args.ref}/check-suites") | ||
for suite in js['check_suites']: | ||
if suite["app"]["name"] == args.app: | ||
checks_url = suite["check_runs_url"] | ||
if not checks_url: | ||
raise KeyError(f"No suite {args.app} found for ${args.ref}") | ||
else: | ||
checks_url = f"https://api.github.com/repos/mozilla-mobile/mozilla-vpn-client/commits/{args.ref}/check-runs" | ||
|
||
# Fetch the JSON for the desired check. | ||
js = fetch(checks_url) | ||
for check in js['check_runs']: | ||
if check["name"] == args.name: | ||
json.dump(check, sys.stdout) | ||
|
||
print(f"DEBUG: {checks_url}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters