Skip to content

Commit

Permalink
Download test
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammedSentry committed Jun 5, 2024
1 parent 44db86a commit c1d4059
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Download Artifacts
name: Download Artifacts from MetricsHub

on:
push:
Expand All @@ -13,24 +13,50 @@ jobs:
- name: Checkout this repository
uses: actions/checkout@v2

- name: Download artifacts from another repository
- name: Download artifacts from MetricsHub
run: |
echo "Downloading artifacts from MetricsHub"
# Define variables
OWNER="MohammedSentry"
REPO="MohammedSentry/metricshub"
RUN_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=main&status=completed&per_page=1" | jq -r '.workflow_runs[0].id')
ARTIFACTS_URL="https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts"
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 }}

Expand Down

0 comments on commit c1d4059

Please sign in to comment.