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
78 changes: 78 additions & 0 deletions .github/actions/slack-notify/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Vendored from renderorange/.github:.github/actions/slack-notify
# Required because chute is a public repository and a public repository cannot
# consume actions from a private one. Keep this byte-identical to the source
# except for this header, and update the source first.
name: slack-notify
description: Post a pipeline or develop message to Slack via incoming webhook
inputs:
template:
description: message shape - job | review | pr-event
required: true
status:
description: pr-event status word - opened | merged | closed | assigned
required: false
default: ""
job:
description: job or workflow name for job/review templates
required: false
default: ""
conclusion:
description: job.status at end - success | failure | cancelled
required: false
default: success
summary:
description: optional suffix, e.g. findings count
required: false
default: ""
repo:
description: full name owner/name
required: false
default: ""
run-id:
description: github.run_id
required: false
default: ""
pr-number:
description: github.event.pull_request.number
required: false
default: ""
pr-title:
description: github.event.pull_request.title
required: false
default: ""
author:
description: PR author login
required: false
default: ""
sha:
description: full commit sha; defaults to GITHUB_SHA (7-char preview in message)
required: false
default: ""
branch:
description: branch name; defaults to GITHUB_HEAD_REF then GITHUB_REF_NAME
required: false
default: ""
dry-run:
description: print payload instead of posting
required: false
default: "false"
runs:
using: composite
steps:
- name: Post to Slack
shell: bash
env:
IN_TEMPLATE: ${{ inputs.template }}
IN_STATUS: ${{ inputs.status }}
IN_JOB: ${{ inputs.job }}
IN_CONCLUSION: ${{ inputs.conclusion }}
IN_SUMMARY: ${{ inputs.summary }}
IN_REPO: ${{ inputs.repo }}
IN_RUN_ID: ${{ inputs.run-id }}
IN_PR_NUMBER: ${{ inputs.pr-number }}
IN_PR_TITLE: ${{ inputs.pr-title }}
IN_AUTHOR: ${{ inputs.author }}
IN_SHA: ${{ inputs.sha }}
IN_BRANCH: ${{ inputs.branch }}
IN_DRY_RUN: ${{ inputs.dry-run }}
run: bash "${{ github.action_path }}/run.sh"
74 changes: 74 additions & 0 deletions .github/actions/slack-notify/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash
# Vendored from renderorange/.github:.github/actions/slack-notify/run.sh
# Public repositories cannot use actions from private repositories, so chute
# carries its own copy. Keep it identical to the source and update there first.
set -euo pipefail

if [ -z "${SLACK_WEBHOOK_URL:-}" ]; then
echo "::error::SLACK_WEBHOOK_URL is empty; caller job must set it from a secret"
exit 1
fi

text=""
repo="${IN_REPO:-${GITHUB_REPOSITORY:-}}"
if [ -z "$repo" ]; then
echo "::error::repo is empty; caller must pass repo or GITHUB_REPOSITORY must be set"
exit 1
fi
branch="${IN_BRANCH:-${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}}"
sha_raw="${IN_SHA:-${GITHUB_SHA:-}}"
short_sha="${sha_raw:0:7}"
[ -n "$short_sha" ] || short_sha="unknown"
case "$IN_TEMPLATE" in
pr-event)
pr_url="https://github.com/${repo}/pull/${IN_PR_NUMBER}"
head="[${repo}] PR #${IN_PR_NUMBER} ${IN_STATUS} · ${IN_PR_TITLE} by ${IN_AUTHOR}"
text=$(jq -n \
--arg h "$head" --arg b "$branch" --arg c "$short_sha" --arg u "$pr_url" \
'if $b != "" and $c != "unknown" then [$h, ("branch: " + $b), ("commit: " + $c), $u] else [$h, $u] end | join("\n")')
;;
review)
run_url="https://github.com/${repo}/actions/runs/${IN_RUN_ID}"
verdict="failed"
[ "$IN_CONCLUSION" = "success" ] && verdict="succeeded"
head="[${repo}] review ${verdict}"
if [ "$IN_CONCLUSION" = "success" ] && [ -n "$IN_SUMMARY" ]; then
head="${head} · ${IN_SUMMARY}"
fi
text=$(jq -n --arg h "$head" --arg c "$short_sha" --arg b "$branch" --arg u "$run_url" \
'if $b != "" then [$h, ("branch: " + $b), ("commit: " + $c), $u] else [$h, ("commit: " + $c), $u] end | join("\n")')
;;
job)
run_url="https://github.com/${repo}/actions/runs/${IN_RUN_ID}"
verdict=$(printf '%s' "$IN_CONCLUSION" | tr '[:upper:]' '[:lower:]')
case "$IN_CONCLUSION" in
success) verdict="succeeded" ;;
failure) verdict="failed" ;;
cancelled) verdict="cancelled" ;;
timed_out) verdict="timed out" ;;
esac
head="[${repo}] ${IN_JOB} ${verdict}"
[ -n "$IN_SUMMARY" ] && head="${head} · ${IN_SUMMARY}"
text=$(jq -n --arg h "$head" --arg c "$short_sha" --arg b "$branch" --arg u "$run_url" \
'if $b != "" then [$h, ("branch: " + $b), ("commit: " + $c), $u] else [$h, ("commit: " + $c), $u] end | join("\n")')
;;
*)
echo "::error::unknown template '${IN_TEMPLATE}'"
exit 1
;;
esac

if [ "$IN_DRY_RUN" = "true" ]; then
echo "DRY_RUN payload: $text"
exit 0
fi

resp=$(curl -sS -o /tmp/slack_response.$$ -w '%{http_code}' -X POST \
-H 'Content-type: application/json' \
--data "{\"text\": $text}" "$SLACK_WEBHOOK_URL")
rm -f /tmp/slack_response.$$
if ! echo "$resp" | grep -q '^200$'; then
echo "::error::slack webhook returned HTTP $resp"
exit 1
fi
echo "slack notified: $IN_TEMPLATE"
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concurrency:
jobs:
test:
name: Test
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

Expand All @@ -41,7 +41,7 @@ jobs:

- name: Notify Slack
if: always()
uses: renderorange/.github/.github/actions/slack-notify@main
uses: ./.github/actions/slack-notify
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PIPELINE_WEBHOOK_URL }}
with:
Expand All @@ -54,7 +54,7 @@ jobs:

lint:
name: Lint
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

Expand All @@ -72,7 +72,7 @@ jobs:

- name: Notify Slack
if: always()
uses: renderorange/.github/.github/actions/slack-notify@main
uses: ./.github/actions/slack-notify
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PIPELINE_WEBHOOK_URL }}
with:
Expand All @@ -85,7 +85,7 @@ jobs:

build:
name: Build
runs-on: self-hosted
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand All @@ -112,7 +112,7 @@ jobs:

- name: Notify Slack
if: always()
uses: renderorange/.github/.github/actions/slack-notify@main
uses: ./.github/actions/slack-notify
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PIPELINE_WEBHOOK_URL }}
with:
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/pr-events.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Vendored from renderorange/.github:.github/workflows/pr-events.yml
# Public repositories cannot call reusable workflows in private repositories, so
# chute carries its own copy and calls it as a local workflow. Runs on a
# GitHub-hosted runner: the message needs nothing from the self-hosted box.
name: pr-events

on:
workflow_call:
secrets:
SLACK_DEVELOPMENT_WEBHOOK_URL:
required: false

jobs:
notify:
runs-on: ubuntu-latest
steps:
# A reusable workflow gets no checkout of its own, and a local action
# cannot be resolved without one.
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Post PR event to develop channel
uses: ./.github/actions/slack-notify
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEVELOPMENT_WEBHOOK_URL }}
with:
template: pr-event
status: >-
${{
github.event.action == 'closed' &&
(github.event.pull_request.merged && 'merged' || 'closed') ||
github.event.action
}}
repo: ${{ github.repository }}
pr-number: ${{ github.event.pull_request.number }}
pr-title: ${{ github.event.pull_request.title }}
author: ${{ github.event.pull_request.user.login }}
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concurrency:
jobs:
test:
name: Test
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

Expand All @@ -41,7 +41,7 @@ jobs:

- name: Notify Slack
if: always()
uses: renderorange/.github/.github/actions/slack-notify@main
uses: ./.github/actions/slack-notify
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PIPELINE_WEBHOOK_URL }}
with:
Expand All @@ -54,7 +54,7 @@ jobs:
# differ by seconds and the four binaries of one release must share a tag.
version:
name: Version
runs-on: self-hosted
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
Expand All @@ -64,7 +64,7 @@ jobs:

build:
name: Build ${{ matrix.goos }}-${{ matrix.goarch }}
runs-on: self-hosted
runs-on: ubuntu-latest
needs: [test, version]
strategy:
fail-fast: false
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:

- name: Notify Slack
if: always()
uses: renderorange/.github/.github/actions/slack-notify@main
uses: ./.github/actions/slack-notify
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PIPELINE_WEBHOOK_URL }}
with:
Expand All @@ -127,7 +127,7 @@ jobs:

release:
name: Release
runs-on: self-hosted
runs-on: ubuntu-latest
needs: [version, build]
permissions:
contents: write
Expand All @@ -154,7 +154,7 @@ jobs:

- name: Notify Slack
if: always()
uses: renderorange/.github/.github/actions/slack-notify@main
uses: ./.github/actions/slack-notify
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PIPELINE_WEBHOOK_URL }}
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/slack-pr-events.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: slack-pr-events

# Posts PR lifecycle events (opened / merged / closed / assigned) to the develop
# channel. The message shape and the webhook live in renderorange/.github; this
# file is the thin caller documented in that repo's README.
# channel. The workflow and the action are vendored into this repo because chute
# is public and cannot use them from the private renderorange/.github.
on:
pull_request:
types: [opened, closed, assigned]

jobs:
notify:
uses: renderorange/.github/.github/workflows/pr-events.yml@main
uses: ./.github/workflows/pr-events.yml
secrets: inherit
Loading