Skip to content

Commit

Permalink
Added input for the Run ID
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammedSentry committed Jun 27, 2024
1 parent 9e543b7 commit 1e25369
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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."
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit 1e25369

Please sign in to comment.