Skip to content

Commit

Permalink
Powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammedSentry committed Jun 6, 2024
1 parent fdd68b4 commit 1a9b38a
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1a9b38a

Please sign in to comment.