toltec
toltec copied to clipboard
add script for quick testing of PR artifacts
it would be nice if we have a quick script so we can say: "toltec-setup-pr 199" or something similar, letting us quickly setup a PR for testing.
Some GitHub API findings:
- To find the latest successful workflow run of PR 300, one can run:
wget "https://api.github.com/repos/toltec-dev/toltec/actions/workflows/pr.yml/runs" --output-document - --quiet | jq '[.workflow_runs[] | select(.pull_requests[] | select(.number == 300)) | select(.status == "completed")] | sort_by(.run_number) | .[-1].artifacts_url' --exit-status --raw-output
This will either output a single URL if the PR exists and has an associated completed run, or output nothing and exit with code 1 otherwise.
- To find the artifacts of a workflow run, using the URL from the previous step, one can run:
wget "https://api.github.com/repos/toltec-dev/toltec/actions/runs/625306645/artifacts" --output-document - --quiet | jq '.artifacts[] | select(.name == "repo") | .archive_download_url' --exit-status --raw-output
This will either output a single URL if the workflow run has a repo artifact attached, or output nothing and exit with code 1 otherwise.
- The URL from the previous step (e.g., https://api.github.com/repos/toltec-dev/toltec/actions/artifacts/45131411/zip) can be used to download the ZIP archive, but it seems that the endpoint requires authentication (as opposed to all the previous endpoints). This is unfortunate, since we can’t really put an API token in the script, it would require each user to supply their own token.
Maybe it is time to consider adding a step to upload artifacts elsewhere as well? Not sure what we can use without incurring storage/infrastructure costs.
Supplying a token isn't really that difficult for the primary people we are aiming this at, so I'd be okay with that.
i don't think bw is an issue since every pr build downloads the whole repo (since moving to python script), iirc
It's probably worth using the github cli for this: https://cli.github.com/manual/
Download the latest build artifact for the current branch:
gh run download $(gh pr status --jq '.currentBranch.statusCheckRollup[] | select(.workflowName == "pr") | select(.name == "Check that it builds without error") | .detailsUrl' --json statusCheckRollup | rev | cut -d'/' -f 3 | rev)