From c1d405957376869ba9f6b43a11fb0cf59f13db03 Mon Sep 17 00:00:00 2001 From: Mohammed Kaddouri Date: Wed, 5 Jun 2024 15:54:24 +0200 Subject: [PATCH] Download test --- .github/workflows/main.yml | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d4bf4f4..a20c4eb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Download Artifacts +name: Download Artifacts from MetricsHub on: push: @@ -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 }}