-
Notifications
You must be signed in to change notification settings - Fork 315
CI: Avoid manual lookup of the run ID in the release workflow #918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2f4af79
Initial plan
Copilot de393b0
Implement automatic run ID lookup from git tag in release workflow
Copilot 0502fcf
Improve run ID lookup script with better error handling and tool vali…
Copilot 23f9a64
Add default empty string value to optional run-id input
Copilot 23789bc
Add comment explaining fetch-depth: 0 requirement for lookup-run-id s…
Copilot bdd328b
Merge branch 'main' into copilot/fix-917
leofang 5ba9113
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] fb2c30a
apply review comments
leofang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
leofang marked this conversation as resolved.
|
||
|
|
||
| # A utility script to find the GitHub Actions workflow run ID for a given git tag. | ||
| # This script looks for the CI workflow run that corresponds to the commit of the given tag. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Check required arguments | ||
| if [[ $# -lt 2 ]]; then | ||
| echo "Usage: $0 <git-tag> <repository> [workflow-name]" >&2 | ||
|
leofang marked this conversation as resolved.
|
||
| echo " git-tag: The git tag to find the corresponding workflow run for" >&2 | ||
| echo " repository: The GitHub repository (e.g., NVIDIA/cuda-python)" >&2 | ||
| echo " workflow-name: Optional workflow name to filter by (default: CI)" >&2 | ||
| echo "" >&2 | ||
| echo "Examples:" >&2 | ||
| echo " $0 v13.0.1 NVIDIA/cuda-python" >&2 | ||
| echo " $0 v13.0.1 NVIDIA/cuda-python \"CI\"" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| GIT_TAG="${1}" | ||
| REPOSITORY="${2}" | ||
| WORKFLOW_NAME="${3:-CI}" | ||
|
|
||
| # Ensure we have required tools | ||
| if [[ -z "${GH_TOKEN:-}" ]]; then | ||
| echo "Error: GH_TOKEN environment variable is required" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! command -v jq >/dev/null 2>&1; then | ||
| echo "Error: jq is required but not installed" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! command -v gh >/dev/null 2>&1; then | ||
| echo "Error: GitHub CLI (gh) is required but not installed" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Looking up run ID for tag: ${GIT_TAG} in repository: ${REPOSITORY}" >&2 | ||
|
leofang marked this conversation as resolved.
|
||
|
|
||
| # Resolve git tag to commit SHA | ||
| if ! COMMIT_SHA=$(git rev-parse "${GIT_TAG}"); then | ||
| echo "Error: Could not resolve git tag '${GIT_TAG}' to a commit SHA" >&2 | ||
| echo "Make sure the tag exists and you have fetched it" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Resolved tag '${GIT_TAG}' to commit: ${COMMIT_SHA}" >&2 | ||
|
|
||
| # Find workflow runs for this commit | ||
| echo "Searching for '${WORKFLOW_NAME}' workflow runs for commit: ${COMMIT_SHA}" >&2 | ||
|
leofang marked this conversation as resolved.
|
||
|
|
||
| # Get workflow runs for the commit, filter by workflow name and successful status | ||
| RUN_DATA=$(gh run list \ | ||
| --repo "${REPOSITORY}" \ | ||
| --commit "${COMMIT_SHA}" \ | ||
| --workflow "${WORKFLOW_NAME}" \ | ||
| --status completed \ | ||
| --json databaseId,workflowName,status,conclusion,headSha \ | ||
| --limit 10) | ||
|
|
||
| if [[ -z "${RUN_DATA}" || "${RUN_DATA}" == "[]" ]]; then | ||
| echo "Error: No completed '${WORKFLOW_NAME}' workflow runs found for commit ${COMMIT_SHA}" >&2 | ||
| echo "Available workflow runs for this commit:" >&2 | ||
| gh run list --repo "${REPOSITORY}" --commit "${COMMIT_SHA}" --limit 10 || true | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Filter for successful runs (conclusion = success) and extract the run ID from the first one | ||
| RUN_ID=$(echo "${RUN_DATA}" | jq -r '.[] | select(.conclusion == "success") | .databaseId' | head -1) | ||
|
|
||
| if [[ -z "${RUN_ID}" || "${RUN_ID}" == "null" ]]; then | ||
| echo "Error: No successful '${WORKFLOW_NAME}' workflow runs found for commit ${COMMIT_SHA}" >&2 | ||
| echo "Available workflow runs for this commit:" >&2 | ||
| gh run list --repo "$REPOSITORY" --commit "${COMMIT_SHA}" --limit 10 || true | ||
| echo "" >&2 | ||
| echo "Completed runs with their conclusions:" >&2 | ||
| echo "${RUN_DATA}" | jq -r '.[] | "\(.databaseId): \(.conclusion)"' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Found workflow run ID: ${RUN_ID} for tag '${GIT_TAG}'" >&2 | ||
|
|
||
| # Verify the run has the expected artifacts by checking if there are any artifacts | ||
| echo "Verifying artifacts exist for run ${RUN_ID}..." >&2 | ||
| ARTIFACT_LIST=$(gh run view "${RUN_ID}" --repo "${REPOSITORY}" --json url || echo "") | ||
|
|
||
| if [[ -z "${ARTIFACT_LIST}" ]]; then | ||
| echo "Warning: Could not verify artifacts for workflow run ${RUN_ID}" >&2 | ||
| fi | ||
|
|
||
| # Output the run ID (this is what gets used by calling scripts) | ||
| echo "${RUN_ID}" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.