From 79f80a0dc47a9229864a0da616a5aee45d7e6cc4 Mon Sep 17 00:00:00 2001 From: Mohammed Kaddouri Date: Mon, 17 Jun 2024 14:25:32 +0200 Subject: [PATCH 1/5] Enhance the debug --- .github/workflows/main.yml | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a49c948..41e7417 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - - name: Download artifact from MetricsHub + - name: Download artifact from MetricsHub run: | # Define variables OWNER="sentrysoftware" @@ -33,17 +33,37 @@ jobs: # Get the latest successful workflow run ID WORKFLOW_RUNS=$(curl -s -H "Authorization: token ***" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5") + echo "Workflow runs fetched:" + echo $WORKFLOW_RUNS | jq . RUN_ID=$(echo $WORKFLOW_RUNS | jq -r '.workflow_runs[] | select(.conclusion == "success") | .id' | head -n 1) + + if [ -z "$RUN_ID" ]; then + echo "No successful run ID found." + exit 1 + fi + + echo "Latest successful 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) + ARTIFACTS=$(curl -s -H "Authorization: token ***" $ARTIFACTS_URL) - # Extract artifact information + echo "Artifacts fetched:" + echo $ARTIFACTS | jq . + ARTIFACT_ID=$(echo $ARTIFACTS | jq -r '.artifacts[0].id') + + if [ -z "$ARTIFACT_ID" ]; then + echo "No artifact ID found." + exit 1 + fi + DOWNLOAD_URL="https://api.github.com/repos/$OWNER/$REPO/actions/artifacts/$ARTIFACT_ID/zip" + echo "Artifact download URL: $DOWNLOAD_URL" + # Download the artifact - curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o artifact.zip $DOWNLOAD_URL + curl -L -H "Authorization: token ***" -o artifact.zip $DOWNLOAD_URL # Unzip the artifact and extract tarball mkdir -p artifacts @@ -56,6 +76,12 @@ jobs: # Extract tarball (assuming the correct filename is known) TAR_FILE=$(ls metricshub-linux-*.tar.gz) + + if [ -z "$TAR_FILE" ]; then + echo "No tarball found in artifacts." + exit 1 + fi + tar -xzf $TAR_FILE - name: Run MetricsHub and get version From 526a5497c2dfcd66a83dc1abd81d70483ae3d6da Mon Sep 17 00:00:00 2001 From: Mohammed Kaddouri Date: Mon, 17 Jun 2024 14:28:30 +0200 Subject: [PATCH 2/5] Fixed a typo --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 41e7417..9b34046 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - - name: Download artifact from MetricsHub + - name: Download artifact from MetricsHub run: | # Define variables OWNER="sentrysoftware" From dc66298842d458a2ffbce075879c368c41608879 Mon Sep 17 00:00:00 2001 From: Mohammed Kaddouri Date: Thu, 27 Jun 2024 16:38:29 +0200 Subject: [PATCH 3/5] Fixed the bad authentication with Linux --- .github/workflows/main.yml | 52 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9b34046..f1a7053 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,23 +20,25 @@ jobs: steps: - name: Download artifact from MetricsHub - run: | + shell: bash + env: # Define variables - OWNER="sentrysoftware" - REPO="metricshub" - BRANCH="main" - + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: metricshub + BRANCH: main + run: | # Debug - Print variables echo "Owner: $OWNER" echo "Repo: $REPO" echo "Branch: $BRANCH" - + # Get the latest successful workflow run ID - WORKFLOW_RUNS=$(curl -s -H "Authorization: token ***" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5") + WORKFLOW_RUNS=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5") echo "Workflow runs fetched:" echo $WORKFLOW_RUNS | jq . RUN_ID=$(echo $WORKFLOW_RUNS | jq -r '.workflow_runs[] | select(.conclusion == "success") | .id' | head -n 1) - + if [ -z "$RUN_ID" ]; then echo "No successful run ID found." exit 1 @@ -46,24 +48,22 @@ jobs: # 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 ***" $ARTIFACTS_URL) + ARTIFACTS=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" $ARTIFACTS_URL) echo "Artifacts fetched:" echo $ARTIFACTS | jq . - ARTIFACT_ID=$(echo $ARTIFACTS | jq -r '.artifacts[0].id') + DOWNLOAD_URL=$(echo $ARTIFACTS | jq -r '.artifacts[] | select(.name | startswith("metricshub-linux")) | .archive_download_url') - if [ -z "$ARTIFACT_ID" ]; then + if [ -z "$DOWNLOAD_URL" ]; then echo "No artifact ID found." exit 1 fi - DOWNLOAD_URL="https://api.github.com/repos/$OWNER/$REPO/actions/artifacts/$ARTIFACT_ID/zip" - echo "Artifact download URL: $DOWNLOAD_URL" # Download the artifact - curl -L -H "Authorization: token ***" -o artifact.zip $DOWNLOAD_URL + curl -L -H "Authorization: Bearer $GITHUB_TOKEN" -o artifact.zip $DOWNLOAD_URL # Unzip the artifact and extract tarball mkdir -p artifacts @@ -123,19 +123,15 @@ jobs: runs-on: windows-latest steps: - - name: Checkout this repository - uses: actions/checkout@v4 - - - name: Download artifacts from MetricsHub + - name: Download artifact from MetricsHub shell: pwsh env: + # Define variables GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: metricshub + BRANCH: main run: | - # Define variables - $OWNER = "${{ github.repository_owner }}" - $REPO = "metricshub" - $BRANCH = "main" - # Debug - Print variables Write-Host "Owner: $OWNER" Write-Host "Repo: $REPO" @@ -146,8 +142,13 @@ jobs: Write-Host "Workflow runs: $($workflow_runs | ConvertTo-Json -Depth 3)" $run_id = ($workflow_runs.workflow_runs | Where-Object { $_.conclusion -eq "success" })[0].id + if (-not $run_id) { + Write-Error "No successful run ID found." + exit 1 + } + # Debug - Print run_id - Write-Host "Run ID: $run_id" + Write-Host "Latest successful run ID: $run_id" # Get the artifact download URL $artifacts_url = "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/artifacts" @@ -162,8 +163,7 @@ jobs: Write-Error "No artifact found with name starting with 'metricshub-windows'" exit 1 } - $artifact_id = $artifact.id - $download_url = "https://api.github.com/repos/$OWNER/$REPO/actions/artifacts/$artifact_id/zip" + $download_url = $artifact.archive_download_url # Debug - Print download URL Write-Host "Download URL: $download_url" From 9e543b77786772d40ffbbb80204b80036eff3256 Mon Sep 17 00:00:00 2001 From: Mohammed Kaddouri Date: Thu, 27 Jun 2024 16:46:18 +0200 Subject: [PATCH 4/5] Modified environement variable for wondows --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f1a7053..889dffc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -133,12 +133,12 @@ jobs: BRANCH: main run: | # Debug - Print variables - Write-Host "Owner: $OWNER" - Write-Host "Repo: $REPO" - Write-Host "Branch: $BRANCH" + Write-Host "Owner: ${env:OWNER}" + Write-Host "Repo: ${env:REPO}" + Write-Host "Branch: ${env:BRANCH}" # Get the latest successful workflow run ID - $workflow_runs = Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } -Uri "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5" + $workflow_runs = Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } -Uri "https://api.github.com/repos/${env:OWNER}/${env:REPO}/actions/runs?branch=${env:BRANCH}&status=completed&per_page=5" Write-Host "Workflow runs: $($workflow_runs | ConvertTo-Json -Depth 3)" $run_id = ($workflow_runs.workflow_runs | Where-Object { $_.conclusion -eq "success" })[0].id @@ -151,7 +151,7 @@ jobs: Write-Host "Latest successful run ID: $run_id" # Get the artifact download URL - $artifacts_url = "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/artifacts" + $artifacts_url = "https://api.github.com/repos/${env:OWNER}/${env:REPO}/actions/runs/$run_id/artifacts" $artifacts = Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } -Uri $artifacts_url # Debug - Print artifacts From 1e2536978ab79d8db820fdbafdebeac31fbd6803 Mon Sep 17 00:00:00 2001 From: Mohammed Kaddouri Date: Thu, 27 Jun 2024 17:04:53 +0200 Subject: [PATCH 5/5] Added input for the Run ID --- .github/workflows/main.yml | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 889dffc..eff0ec2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,6 +13,9 @@ on: build_number: description: 'Enter the build number to compare' required: true + run_id: + description: 'Enter the GitHub build run ID, example: 9496848962' + required: false jobs: sanity-check-ubuntu: @@ -27,17 +30,21 @@ jobs: OWNER: ${{ github.repository_owner }} REPO: metricshub BRANCH: main + RUN_ID: ${{ github.event.inputs.run_id }} run: | # Debug - Print variables echo "Owner: $OWNER" echo "Repo: $REPO" echo "Branch: $BRANCH" - # Get the latest successful workflow run ID - WORKFLOW_RUNS=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5") - echo "Workflow runs fetched:" - echo $WORKFLOW_RUNS | jq . - RUN_ID=$(echo $WORKFLOW_RUNS | jq -r '.workflow_runs[] | select(.conclusion == "success") | .id' | head -n 1) + if [ -z "$RUN_ID" ]; then + + # Get the latest successful workflow run ID + WORKFLOW_RUNS=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&status=completed&per_page=5") + echo "Workflow runs fetched:" + echo $WORKFLOW_RUNS | jq . + RUN_ID=$(echo $WORKFLOW_RUNS | jq -r '.workflow_runs[] | select(.conclusion == "success") | .id' | head -n 1) + fi if [ -z "$RUN_ID" ]; then echo "No successful run ID found." @@ -131,16 +138,22 @@ jobs: OWNER: ${{ github.repository_owner }} REPO: metricshub BRANCH: main + RUN_ID: ${{ github.event.inputs.run_id }} run: | # Debug - Print variables Write-Host "Owner: ${env:OWNER}" Write-Host "Repo: ${env:REPO}" Write-Host "Branch: ${env:BRANCH}" - # Get the latest successful workflow run ID - $workflow_runs = Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } -Uri "https://api.github.com/repos/${env:OWNER}/${env:REPO}/actions/runs?branch=${env:BRANCH}&status=completed&per_page=5" - Write-Host "Workflow runs: $($workflow_runs | ConvertTo-Json -Depth 3)" - $run_id = ($workflow_runs.workflow_runs | Where-Object { $_.conclusion -eq "success" })[0].id + if (-not $env:RUN_ID) { + # Get the latest successful workflow run ID + $workflow_runs = Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } -Uri "https://api.github.com/repos/${env:OWNER}/${env:REPO}/actions/runs?branch=${env:BRANCH}&status=completed&per_page=5" + Write-Host "Workflow runs: $($workflow_runs | ConvertTo-Json -Depth 3)" + $run_id = ($workflow_runs.workflow_runs | Where-Object { $_.conclusion -eq "success" })[0].id + + } else { + $run_id = $env:RUN_ID + } if (-not $run_id) { Write-Error "No successful run ID found."