toltec icon indicating copy to clipboard operation
toltec copied to clipboard

add script for quick testing of PR artifacts

Open raisjn opened this issue 3 years ago • 5 comments

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.

raisjn avatar Jan 14 '21 14:01 raisjn

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.

matteodelabre avatar Mar 08 '21 14:03 matteodelabre

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.

danshick avatar Mar 08 '21 14:03 danshick

Supplying a token isn't really that difficult for the primary people we are aiming this at, so I'd be okay with that.

Eeems avatar Mar 08 '21 15:03 Eeems

i don't think bw is an issue since every pr build downloads the whole repo (since moving to python script), iirc

raisjn avatar Mar 08 '21 15:03 raisjn

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)

Eeems avatar Dec 06 '23 22:12 Eeems