Skip to content

Download test

Download test #32

Workflow file for this run

name: Download Artifacts from MetricsHub
on:
push:
branches:
- main
jobs:
download-artifacts:
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v2
- name: Download artifacts from MetricsHub
run: |
echo "Downloading artifacts from MetricsHub"
# Define variables
OWNER="MohammedSentry"
REPO="metricshub"
BRANCH="main"
# Get the latest workflow run ID
RUN_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=1" | jq -r '.workflow_runs[0].id')
echo "Latest workflow run ID: $RUN_ID"
# Get the artifact download URL
ARTIFACTS_URL="https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts"
ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $ARTIFACTS_URL)
echo "Artifacts JSON: $ARTIFACTS"
# Extract artifact information
ARTIFACT_ID=$(echo $ARTIFACTS | jq -r '.artifacts[0].id')
if [ "$ARTIFACT_ID" = "null" ]; then
echo "No artifacts found for this run ID: $RUN_ID"
exit 1
fi
echo "Artifact ID: $ARTIFACT_ID"
DOWNLOAD_URL="https://api.github.com/repos/$OWNER/$REPO/actions/artifacts/$ARTIFACT_ID/zip"
# Download the artifact
echo "Downloading artifact from $DOWNLOAD_URL"
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o artifact.zip $DOWNLOAD_URL
# Check if the downloaded file is a valid ZIP
if file artifact.zip | grep -q 'Zip archive data'; then
echo "Artifact is a valid ZIP file"
else
echo "Artifact is not a valid ZIP file"
exit 1
fi
# Create artifacts directory
mkdir -p artifacts
# Unzip the artifact
unzip artifact.zip -d artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: List downloaded files
run: ls -al artifacts