Skip to content

Google Cloud Build Monitor #41669

Google Cloud Build Monitor

Google Cloud Build Monitor #41669

Workflow file for this run

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Google Cloud Build Monitor
on:
check_run:
types: [completed]
permissions:
contents: read
issues: write
jobs:
create-issue-on-failure:
runs-on: ubuntu-24.04
# Only alert for a failed GCB build on the main branch.
if: >
github.repository == 'googleapis/google-cloud-rust' && github.event.check_run.app.name == 'Google Cloud Build' && github.event.check_run.check_suite.head_branch == 'main' && (github.event.check_run.conclusion == 'failure' || github.event.check_run.conclusion == 'timed_out' || github.event.check_run.conclusion == 'cancelled')
steps:
- name: Create or update CI failure issue
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
BUILD_URL: ${{ github.event.check_run.details_url }}
BUILD_NAME: ${{ github.event.check_run.name }}
COMMIT_SHA: ${{ github.event.check_run.head_sha }}
run: |
ISSUE_TITLE="Post-merge failure for \`$BUILD_NAME\`"
# Query GitHub for any PRs associated with this commit
PRS=$(gh api repos/$GH_REPO/commits/$COMMIT_SHA/pulls --jq '.[].number')
PR_TEXT=""
if [[ -n "$PRS" ]]; then
PR_TEXT="**Associated Pull Requests:**"
for pr in $PRS; do
PR_TEXT="$PR_TEXT"$'\n'"- #$pr"
done
fi
BODY="**Failure in Google Cloud Build on \`main\`:**
- **Build:** \`$BUILD_NAME\`
- **Build Log:** $BUILD_URL
- **Commit:** $COMMIT_SHA
$PR_TEXT"
# Check for an existing open issue with the same title.
EXISTING_ISSUE=$(gh issue list --repo $GH_REPO --search "\"$ISSUE_TITLE\" in:title" --state open --json number --jq '.[0].number')
if [[ -n "$EXISTING_ISSUE" && "$EXISTING_ISSUE" != "null" ]]; then
echo "Found existing open issue #$EXISTING_ISSUE. Adding comment."
gh issue comment "$EXISTING_ISSUE" --repo $GH_REPO --body "$BODY"
else
echo "Creating new issue."
ISSUE_LINK=$(gh issue create --title "$ISSUE_TITLE" --body "$BODY" --label ":rotating_light: critical" --assignee ${GITHUB_ACTOR} -R $GH_REPO)
ISSUE_NUM=${ISSUE_LINK##*/}
gh issue comment $ISSUE_NUM --repo $GH_REPO --body "@googleapis/cloud-sdk-rust-team A critical issue has been created, please respond immediately."
fi