Created
August 1, 2023 06:57
-
-
Save abernix/302c836483cb6a90aa76f1c105998041 to your computer and use it in GitHub Desktop.
Get the latest Router nightly builds for a branch (like `dev`)
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
#!/usr/bin/env bash | |
# Requires a PERSONAL CircleCI token defined in the environment | |
# as CIRCLE_TOKEN from https://app.circleci.com/settings/user/tokens. | |
branch_to_get="${1:-dev}" | |
repo_to_use="${2:-router}" | |
echo "Downloading the latest nightly build from the ${branch_to_get} branch on ${repo_to_use}. Pass the first argument as a branch name to change the branch and optionally the repo name as the second argument." | |
curl --request GET \ | |
--url "https://circleci.com/api/v2/project/gh/apollographql/${repo_to_use}/pipeline?branch=${branch_to_get}" \ | |
--header "Circle-Token: $CIRCLE_TOKEN" | | |
jq -rc '.items[] | select(.trigger.type == "api") | "https://circleci.com/api/v2/pipeline/\(.id)/workflow"' | | |
xargs -n1 curl --silent --header "Circle-Token: $CIRCLE_TOKEN" | | |
jq -src 'map(.items[]) | map(select((.name == "nightly") and (.status == "success"))) | first | "https://circleci.com/api/v2/workflow/\(.id)/job"' | | |
xargs -n1 curl --silent --header "Circle-Token: $CIRCLE_TOKEN" | | |
jq --arg REPO "$repo_to_use" -rc '.items[] | "https://circleci.com/api/v2/project/gh/apollographql/\($REPO)/\(.job_number)/artifacts/"' | | |
xargs -n1 curl --location --silent --header "Circle-Token: $CIRCLE_TOKEN" | | |
jq -sr 'map(.items[]) | .[] | .url' | | |
xargs -n1 curl -O --location --retry 10 --retry-max-time 0 -C - --header "Circle-Token: $CIRCLE_TOKEN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment