Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 1 addition & 74 deletions .github/actions/notify-irm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,77 +54,4 @@ runs:
SHA: ${{ github.sha }}
ACTOR: ${{ github.actor }}
SERVER_URL: ${{ github.server_url }}
run: |-
set -euo pipefail
if [ -z "${WEBHOOK_URL}" ]; then
echo "::warning::GRAFANA_IRM_WEBHOOK_URL is empty — skipping IRM notification."
exit 0
fi
if [ "${JOB_FAILED}" != "true" ] && [ "${RESOLVE_ON_SUCCESS}" != "true" ]; then
echo "::notice::All jobs green and resolve-on-success=false — skipping IRM notification."
exit 0
fi
run_url="${SERVER_URL}/${REPOSITORY}/actions/runs/${RUN_ID}"

# Branch the payload by outcome.
# alert_uid is intentionally NOT keyed on SHA: a successful run on a
# later commit (different SHA) must resolve the open incident from the
# previous failed commit. Re-runs and follow-up commits on the same
# branch collapse into the same alert group.
if [ "${JOB_FAILED}" = "true" ]; then
state="alerting"
severity="critical"
title="CI failure on ${REF_NAME}: ${WORKFLOW_NAME}"
msg="Workflow '${WORKFLOW_NAME}' failed on ${REF_NAME} @ ${SHA} (actor: ${ACTOR})."
else
state="ok"
severity="info"
title="CI back to green on ${REF_NAME}: ${WORKFLOW_NAME}"
msg="Workflow '${WORKFLOW_NAME}' succeeded on ${REF_NAME} @ ${SHA} (actor: ${ACTOR}). Auto-resolving any open incident."
fi
echo "::notice::Posting state=${state} for ${WORKFLOW_NAME} on ${REF_NAME} @ ${SHA:0:7}"

# Grafana IRM "Custom" webhook payload — fields map to standard alert
# grouping keys. Both `service` and `service_name` are sent because IRM
# uses `service_name` for SLOs/alerts/synthetic checks but `service`
# for incident & dashboard tags; emitting both keeps every consumer
# happy without an integration-side rename.
payload=$(jq -n \
--arg uid "gha-${REPOSITORY}-${WORKFLOW_NAME}-${REF_NAME}" \
--arg title "${title}" \
--arg state "${state}" \
--arg severity "${severity}" \
--arg link "${run_url}" \
--arg msg "${msg}" \
--arg service "${SERVICE}" \
--arg source "github-actions" \
--arg repo "${REPOSITORY}" \
--arg workflow "${WORKFLOW_NAME}" \
--arg branch "${REF_NAME}" \
--arg sha_short "${SHA:0:7}" \
--arg actor "${ACTOR}" \
'{
alert_uid: $uid,
title: $title,
state: $state,
severity: $severity,
link_to_upstream_details: $link,
message: $msg,
labels: {
service: $service,
service_name: $service,
source: $source,
repo: $repo,
workflow: $workflow,
branch: $branch,
sha: $sha_short,
actor: $actor,
severity: $severity
}
}')
curl --silent --show-error --fail-with-body \
--max-time 30 \
--request POST \
--header 'Content-Type: application/json' \
--data "${payload}" \
"${WEBHOOK_URL}"
run: bash "${GITHUB_ACTION_PATH}/notify.sh"
81 changes: 81 additions & 0 deletions .github/actions/notify-irm/notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
#
# POSTs the alert state to the Grafana IRM webhook (.github/actions/notify-irm,
# step "POST alert state to Grafana IRM webhook"): state=alerting when
# JOB_FAILED is true, state=ok otherwise unless RESOLVE_ON_SUCCESS is false.
# Skips when WEBHOOK_URL is empty.

set -euo pipefail

if [ -z "${WEBHOOK_URL}" ]; then
echo "::warning::GRAFANA_IRM_WEBHOOK_URL is empty — skipping IRM notification."
exit 0
fi
if [ "${JOB_FAILED}" != "true" ] && [ "${RESOLVE_ON_SUCCESS}" != "true" ]; then
echo "::notice::All jobs green and resolve-on-success=false — skipping IRM notification."
exit 0
fi
run_url="${SERVER_URL}/${REPOSITORY}/actions/runs/${RUN_ID}"

# Branch the payload by outcome.
# alert_uid is intentionally NOT keyed on SHA: a successful run on a
# later commit (different SHA) must resolve the open incident from the
# previous failed commit. Re-runs and follow-up commits on the same
# branch collapse into the same alert group.
if [ "${JOB_FAILED}" = "true" ]; then
state="alerting"
severity="critical"
title="CI failure on ${REF_NAME}: ${WORKFLOW_NAME}"
msg="Workflow '${WORKFLOW_NAME}' failed on ${REF_NAME} @ ${SHA} (actor: ${ACTOR})."
else
state="ok"
severity="info"
title="CI back to green on ${REF_NAME}: ${WORKFLOW_NAME}"
msg="Workflow '${WORKFLOW_NAME}' succeeded on ${REF_NAME} @ ${SHA} (actor: ${ACTOR}). Auto-resolving any open incident."
fi
echo "::notice::Posting state=${state} for ${WORKFLOW_NAME} on ${REF_NAME} @ ${SHA:0:7}"

# Grafana IRM "Custom" webhook payload — fields map to standard alert
# grouping keys. Both `service` and `service_name` are sent because IRM
# uses `service_name` for SLOs/alerts/synthetic checks but `service`
# for incident & dashboard tags; emitting both keeps every consumer
# happy without an integration-side rename.
payload=$(jq -n \
--arg uid "gha-${REPOSITORY}-${WORKFLOW_NAME}-${REF_NAME}" \
--arg title "${title}" \
--arg state "${state}" \
--arg severity "${severity}" \
--arg link "${run_url}" \
--arg msg "${msg}" \
--arg service "${SERVICE}" \
--arg source "github-actions" \
--arg repo "${REPOSITORY}" \
--arg workflow "${WORKFLOW_NAME}" \
--arg branch "${REF_NAME}" \
--arg sha_short "${SHA:0:7}" \
--arg actor "${ACTOR}" \
'{
alert_uid: $uid,
title: $title,
state: $state,
severity: $severity,
link_to_upstream_details: $link,
message: $msg,
labels: {
service: $service,
service_name: $service,
source: $source,
repo: $repo,
workflow: $workflow,
branch: $branch,
sha: $sha_short,
actor: $actor,
severity: $severity
}
}')
curl --silent --show-error --fail-with-body \
--max-time 30 \
--request POST \
--header 'Content-Type: application/json' \
--data "${payload}" \
"${WEBHOOK_URL}"
6 changes: 3 additions & 3 deletions .github/workflows/lint-caller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ jobs:
# renovate: datasource=github-releases depName=golangci/golangci-lint
# golangci-lint-version: "v2.12.2"
lint-config-dir: config-sync/files
# Warnings only until this repository's own run: steps are moved into
# scripts (#537); the last PR of that stack makes it blocking.
lint-inline-scripts-blocking: false
# This repository has no inline scripts (#537), so it keeps it that way.
lint-inline-scripts-blocking: true

lint-single-job:
# Exercises `lint-job-mode: single` — the default for private callers —
Expand All @@ -48,5 +47,6 @@ jobs:
mise-version: "2026.10.19"
lint-config-dir: config-sync/files
lint-job-mode: single
lint-inline-scripts-blocking: true
upload-sarif: false
lint-zizmor: false
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ run = [
"bash ./tests/open-pr-push.sh",
"bash ./tests/open-pr-api-commit.sh",
"bash ./tests/open-pr-labels.sh",
"bash ./tests/release-publish-scripts.sh",
"bash ./tests/notify-irm-scripts.sh",
"bash ./tests/config-sync-ai-toolkit-instructions.sh",
"bash ./tests/config-sync-lint-excludes.sh",
"bash ./tests/config-sync-renovate-stub.sh",
Expand Down
22 changes: 1 addition & 21 deletions actions/ai-commits-badge/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,11 @@ runs:
id: generate
shell: bash
env:
ACTION_PATH: ${{ github.action_path }}
BADGE_REF: ${{ inputs.ref }}
BADGE_SINCE: ${{ inputs.since }}
BADGE_NAME: ${{ inputs.name }}
BADGE_LABEL: ${{ inputs.label }}
BADGE_OUT: ${{ inputs.out }}
BADGE_THEMES: ${{ inputs.themes }}
BADGE_REPO_DIR: ${{ inputs.repo-dir }}
run: |-
set -euo pipefail
args=(
"--repo-dir=${BADGE_REPO_DIR}"
"--ref=${BADGE_REF}"
"--since=${BADGE_SINCE}"
"--name=${BADGE_NAME}"
"--label=${BADGE_LABEL}"
"--out=${BADGE_OUT}"
"--github-output=${GITHUB_OUTPUT}"
)
case "${BADGE_THEMES}" in
true) args+=(--themes) ;;
false) ;;
*)
echo "::error::themes must be true or false." >&2
exit 1
;;
esac
python3 "${ACTION_PATH}/ai_commits_badge.py" "${args[@]}"
run: bash "${GITHUB_ACTION_PATH}/generate.sh"
26 changes: 26 additions & 0 deletions actions/ai-commits-badge/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
#
# Generates the AI commits badges (actions/ai-commits-badge, step "Generate AI
# commits badges") by running ai_commits_badge.py with the action's inputs.

set -euo pipefail

action_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
args=(
"--repo-dir=${BADGE_REPO_DIR}"
"--ref=${BADGE_REF}"
"--since=${BADGE_SINCE}"
"--name=${BADGE_NAME}"
"--label=${BADGE_LABEL}"
"--out=${BADGE_OUT}"
"--github-output=${GITHUB_OUTPUT}"
)
case "${BADGE_THEMES}" in
true) args+=(--themes) ;;
false) ;;
*)
echo "::error::themes must be true or false." >&2
exit 1
;;
esac
python3 "${action_dir}/ai_commits_badge.py" "${args[@]}"
83 changes: 1 addition & 82 deletions actions/open-pr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,85 +177,4 @@ runs:
BODY: ${{ inputs.body }}
LABELS: ${{ inputs.labels }}
DRAFT: ${{ inputs.draft }}
run: |-
set -euo pipefail

# Collect labels from newline-delimited input.
labels=()
while IFS= read -r line; do
trimmed="${line#"${line%%[![:space:]]*}"}"
trimmed="${trimmed%"${trimmed##*[![:space:]]}"}"
[ -n "${trimmed}" ] && labels+=("${trimmed}")
done <<< "${LABELS}"

# `gh pr create --label` fails outright on a label the repo doesn't
# have. Create missing labels first (the Pull requests permission is
# enough); drop one that can't be created with a warning rather than
# failing the whole PR. Check each label directly: a listing is paged
# and can miss labels. Re-check after a failed create, which also
# covers another run creating the label first.
label_exists() {
gh api "repos/{owner}/{repo}/labels/$(jq -rn --arg l "$1" '$l | @uri')" --silent >/dev/null 2>&1
}
label_args=()
add_label_args=()
for label in ${labels[@]+"${labels[@]}"}; do
if ! label_exists "${label}" &&
! gh label create "${label}" >/dev/null 2>&1 &&
! label_exists "${label}"; then
echo "::warning::Label '${label}' does not exist and could not be created; continuing without it."
continue
fi
label_args+=(--label "${label}")
add_label_args+=(--add-label "${label}")
done

draft_args=()
if [ "${DRAFT}" = "true" ]; then
draft_args+=(--draft)
fi

# Try to create. If a PR already exists for `head:branch -> base`,
# `gh pr create` exits non-zero — fall back to looking it up.
if gh pr create \
--base "${BASE}" \
--head "${BRANCH}" \
--title "${TITLE}" \
--body "${BODY}" \
"${label_args[@]}" \
"${draft_args[@]}" \
> /tmp/gh-pr-create.out 2>&1; then
url=$(tail -n1 /tmp/gh-pr-create.out)
number=$(gh pr view "${BRANCH}" --json number --jq '.number')
{
echo "created=true"
echo "pr-url=${url}"
echo "pr-number=${number}"
} >> "${GITHUB_OUTPUT}"
echo "Opened PR #${number}: ${url}"
else
# Surface the original error for debuggability, then try reuse.
cat /tmp/gh-pr-create.out
existing=$(gh pr list \
--base "${BASE}" \
--head "${BRANCH}" \
--state open \
--json number,url \
--jq '.[0]')
if [ -z "${existing}" ] || [ "${existing}" = "null" ]; then
echo "::error::gh pr create failed and no existing open PR found for ${BRANCH} -> ${BASE}." >&2
exit 1
fi
number=$(printf '%s' "${existing}" | jq -r '.number')
url=$(printf '%s' "${existing}" | jq -r '.url')
if [ "${#add_label_args[@]}" -gt 0 ] &&
! gh pr edit "${number}" "${add_label_args[@]}" >/dev/null; then
echo "::warning::Could not add labels to existing PR #${number}."
fi
{
echo "created=false"
echo "pr-url=${url}"
echo "pr-number=${number}"
} >> "${GITHUB_OUTPUT}"
echo "Reused existing PR #${number}: ${url} (its branch holds the new commit)."
fi
run: bash "${GITHUB_ACTION_PATH}/open-pr.sh"
Loading
Loading