From 1a9b38abc8f10d528f4e79ef7248eb457e6abf34 Mon Sep 17 00:00:00 2001 From: Mohammed Kaddouri Date: Thu, 6 Jun 2024 14:35:49 +0200 Subject: [PATCH] Powershell --- .github/workflows/main.yml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8e34617..53676e7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,35 +17,38 @@ jobs: run: choco install jq - name: Download artifacts from MetricsHub + shell: pwsh run: | # Define variables - OWNER="MohammedSentry" - REPO="metricshub" - BRANCH="main" + $OWNER = "MohammedSentry" + $REPO = "metricshub" + $BRANCH = "main" # Get the latest successful workflow run ID - WORKFLOW_RUNS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5") - RUN_ID=$(echo $WORKFLOW_RUNS | jq -r '.workflow_runs[] | select(.conclusion == "success") | .id' | head -n 1) - + $workflow_runs = Invoke-RestMethod -Headers @{ Authorization = "token $env:GITHUB_TOKEN" } -Uri "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5" + $run_id = ($workflow_runs.workflow_runs | Where-Object { $_.conclusion -eq "success" })[0].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) + $artifacts_url = "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/artifacts" + $artifacts = Invoke-RestMethod -Headers @{ Authorization = "token $env:GITHUB_TOKEN" } -Uri $artifacts_url # Extract artifact information - ARTIFACT_ID=$(echo $ARTIFACTS | jq -r '.artifacts[0].id') - DOWNLOAD_URL="https://api.github.com/repos/$OWNER/$REPO/actions/artifacts/$ARTIFACT_ID/zip" + $artifact_id = $artifacts.artifacts[0].id + $download_url = "https://api.github.com/repos/$OWNER/$REPO/actions/artifacts/$artifact_id/zip" # Download the artifact - curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o artifact.zip $DOWNLOAD_URL + Invoke-WebRequest -Headers @{ Authorization = "token $env:GITHUB_TOKEN" } -Uri $download_url -OutFile artifact.zip # Unzip the artifact - mkdir -p artifacts + mkdir artifacts tar -xzf artifact.zip -C artifacts - name: MetricsHub version + shell: pwsh run: | - cd artifacts/metricshub/bin + Set-Location artifacts/metricshub/bin ./metricshub --version - name: List downloaded files - run: dir artifacts + shell: pwsh + run: Get-ChildItem -Path artifacts