Skip to content

Instantly share code, notes, and snippets.

@vitoo
Last active February 10, 2023 09:26
Show Gist options
  • Save vitoo/568011d3680e5c0b1b73e5821b84103a to your computer and use it in GitHub Desktop.
Save vitoo/568011d3680e5c0b1b73e5821b84103a to your computer and use it in GitHub Desktop.
Download last github action artifact of a given repository and branch
#!/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
@vitoo
Copy link
Author

vitoo commented Feb 9, 2023

Usage :

download_artifact.sh <owner/repo> <branch> <github_token>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment