Last active
February 10, 2023 09:26
-
-
Save vitoo/568011d3680e5c0b1b73e5821b84103a to your computer and use it in GitHub Desktop.
Download last github action artifact of a given repository and branch
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
#!/bin/bash | |
set -e | |
cd /tmp | |
# Define the repository and branch name | |
repo=$1 | |
branch=$2 | |
token=$3 | |
# Get the artifacts of the repository | |
curl -H "Authorization: Bearer $token" -s "https://api.github.com/repos/$repo/actions/artifacts" | jq -r --arg branch "$branch" '.artifacts[] | select(.workflow_run.head_branch == $branch) | .archive_download_url' > artifact_url.txt | |
# Read the first line of the artifact URL | |
artifact_url=$(head -n 1 artifact_url.txt) | |
echo $artifact_url | |
# Download the artifact | |
wget -v --header="Authorization: Bearer $token" -O artifact.zip $artifact_url | |
# Extract the artifact | |
unzip -o artifact.zip | |
# Remove the artifact URL file | |
rm artifact_url.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage :