Skip to content

Commit

Permalink
Refactor taskcluster artifact download into a composite action
Browse files Browse the repository at this point in the history
  • Loading branch information
oskirby committed Nov 23, 2024
1 parent 2666765 commit 0be5123
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 28 deletions.
35 changes: 35 additions & 0 deletions .github/actions/taskcluster-artifact/action.yml
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.
51 changes: 51 additions & 0 deletions .github/scripts/await-taskcluster-job.py
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}")
19 changes: 5 additions & 14 deletions .github/workflows/prod-test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,11 @@ jobs:
name: ${{ inputs.group-name }}-addons
path: build-addons/

- name: Wait for taskcluster job
id: taskgraph
shell: bash
run: |
pip install requests
./.github/scripts/await-taskcluster-status.py -t 3600 ${{ inputs.task-id }} | tee task-status.json
echo run-id=$(jq '.runs[] | select(.state == "completed").runId' task-status.json) >> $GITHUB_OUTPUT
- name: Download build artifact
shell: bash
env:
TASKGRAPH_TASK_URL: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/${{ inputs.task-id }}
TASKGRAPH_ARTIFACT: public%2Fbuild%2F${{ inputs.artifact-name }}
run: curl -sSL -o ${{ inputs.artifact-name }} ${TASKGRAPH_TASK_URL}/runs/${{ steps.taskgraph.outputs.run-id }}/artifacts/${TASKGRAPH_ARTIFACT}
- name: Fetch taskgraph artifact
uses: ./.github/actions/taskcluster-artifact
with:
taskid: ${{ inputs.task-id }}
artifact-name: ${{ inputs.artifact-name }}

- uses: actions/upload-artifact@v4
with:
Expand Down
26 changes: 12 additions & 14 deletions .github/workflows/release_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,25 @@ jobs:
done
- name: Fetch taskgraph
shell: bash
run: |
./.github/scripts/await-taskcluster-status.py -t 180 ${{ steps.decision-task.outputs.taskid }}
curl -sSL -o raw-task-graph.json \
${TASKGRAPH_TASK_API}/${{ steps.decision-task.outputs.taskid }}/runs/0/artifacts/public%2Ftask-graph.json
jq 'to_entries | .[].value' raw-task-graph.json > task-graph.json
jq -r '.task_id' task-graph.json
uses: ./.github/actions/taskcluster-artifact
with:
taskid: ${{ steps.decision-task.outputs.taskid }}
artifact-name: task-graph.json

- name: Parse taskgraph
id: artifacts
shell: bash
run: |
echo linux=$(jq -r 'select(.label == "build-linux64/release-deb").task_id' task-graph.json) >> $GITHUB_OUTPUT
jq -r '.[] | .task_id + " -> " + .label' task-graph.json
echo linux=$(jq -r '.[] | select(.label == "build-linux64/release-deb").task_id' parsed-tasks.json) >> $GITHUB_OUTPUT
if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
echo macos=$(jq -r 'select(.label == "build-macos/pr").task_id' task-graph.json) >> $GITHUB_OUTPUT
echo windows=$(jq -r 'select(.label == "build-windows/opt").task_id' task-graph.json) >> $GITHUB_OUTPUT
echo macos=$(jq -r '.[] | select(.label == "build-macos/pr").task_id' parsed-tasks.json) >> $GITHUB_OUTPUT
echo windows=$(jq -r '.[] | select(.label == "build-windows/opt").task_id' parsed-tasks.json) >> $GITHUB_OUTPUT
else
echo macos=$(jq -r 'select(.label == "signing-macos/opt").task_id' task-graph.json) >> $GITHUB_OUTPUT
echo windows=$(jq -r 'select(.label == "repackage-msi").task_id' task-graph.json) >> $GITHUB_OUTPUT
fi
echo macos=$(jq -r '.[] | select(.label == "signing-macos/opt").task_id' parsed-tasks.json) >> $GITHUB_OUTPUT
echo windows=$(jq -r '.[] | select(.label == "repackage-msi").task_id' parsed-tasks.json) >> $GITHUB_OUTPUT
fi
linux-tests:
needs:
Expand Down

0 comments on commit 0be5123

Please sign in to comment.