1+ #! /usr/bin/env bash
2+
3+ # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+ #
5+ # SPDX-License-Identifier: Apache-2.0
6+
7+ # A utility script to find the GitHub Actions workflow run ID for a given git tag.
8+ # This script looks for the CI workflow run that corresponds to the commit of the given tag.
9+
10+ set -euo pipefail
11+
12+ # Check required arguments
13+ if [[ $# -lt 2 ]]; then
14+ echo " Usage: $0 <git-tag> <repository> [workflow-name]" >&2
15+ echo " git-tag: The git tag to find the corresponding workflow run for" >&2
16+ echo " repository: The GitHub repository (e.g., NVIDIA/cuda-python)" >&2
17+ echo " workflow-name: Optional workflow name to filter by (default: CI)" >&2
18+ echo " " >&2
19+ echo " Examples:" >&2
20+ echo " $0 v13.0.1 NVIDIA/cuda-python" >&2
21+ echo " $0 v13.0.1 NVIDIA/cuda-python \" CI\" " >&2
22+ exit 1
23+ fi
24+
25+ GIT_TAG=" $1 "
26+ REPOSITORY=" $2 "
27+ WORKFLOW_NAME=" ${3:- CI} "
28+
29+ # Ensure we have a GitHub token
30+ if [[ -z " ${GH_TOKEN:- } " ]]; then
31+ echo " Error: GH_TOKEN environment variable is required" >&2
32+ exit 1
33+ fi
34+
35+ echo " Looking up run ID for tag: $GIT_TAG in repository: $REPOSITORY " >&2
36+
37+ # Resolve git tag to commit SHA
38+ if ! COMMIT_SHA=$( git rev-parse " $GIT_TAG " 2> /dev/null) ; then
39+ echo " Error: Could not resolve git tag '$GIT_TAG ' to a commit SHA" >&2
40+ echo " Make sure the tag exists and you have fetched it" >&2
41+ exit 1
42+ fi
43+
44+ echo " Resolved tag '$GIT_TAG ' to commit: $COMMIT_SHA " >&2
45+
46+ # Find workflow runs for this commit
47+ echo " Searching for '$WORKFLOW_NAME ' workflow runs for commit: $COMMIT_SHA " >&2
48+
49+ # Get workflow runs for the commit, filter by workflow name and successful status
50+ RUN_DATA=$( gh run list \
51+ --repo " $REPOSITORY " \
52+ --commit " $COMMIT_SHA " \
53+ --workflow " $WORKFLOW_NAME " \
54+ --status success \
55+ --json databaseId,workflowName,status,conclusion,headSha \
56+ --limit 10)
57+
58+ if [[ -z " $RUN_DATA " || " $RUN_DATA " == " []" ]]; then
59+ echo " Error: No successful '$WORKFLOW_NAME ' workflow runs found for commit $COMMIT_SHA " >&2
60+ echo " Available workflow runs for this commit:" >&2
61+ gh run list --repo " $REPOSITORY " --commit " $COMMIT_SHA " --limit 10 || true
62+ exit 1
63+ fi
64+
65+ # Extract the run ID from the first (most recent) successful run
66+ RUN_ID=$( echo " $RUN_DATA " | jq -r ' .[0].databaseId // empty' )
67+
68+ if [[ -z " $RUN_ID " || " $RUN_ID " == " null" ]]; then
69+ echo " Error: Could not extract run ID from workflow data" >&2
70+ echo " Workflow data: $RUN_DATA " >&2
71+ exit 1
72+ fi
73+
74+ echo " Found workflow run ID: $RUN_ID for tag '$GIT_TAG '" >&2
75+
76+ # Verify the run has the expected artifacts by checking if there are any artifacts
77+ echo " Verifying artifacts exist for run $RUN_ID ..." >&2
78+ ARTIFACT_LIST=$( gh run view " $RUN_ID " --repo " $REPOSITORY " --json url 2> /dev/null || echo " " )
79+
80+ if [[ -z " $ARTIFACT_LIST " ]]; then
81+ echo " Warning: Could not verify artifacts for workflow run $RUN_ID " >&2
82+ fi
83+
84+ # Output the run ID (this is what gets used by calling scripts)
85+ echo " $RUN_ID "
0 commit comments