Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

ci(release): announce completed GitHub Releases in Slack (#3607)

JD Davis7f44a64490bc
diff --git a/.github/act/release-published.json b/.github/act/release-published.json
index d46063432..df5d22c30 100644
--- a/.github/act/release-published.json
+++ b/.github/act/release-published.json
@@ -3,6 +3,7 @@
"release": {
"tag_name": "v0.9.2",
"name": "Release v0.9.2",
+ "html_url": "https://github.com/headroomlabs-ai/headroom/releases/tag/v0.9.2",
"draft": false,
"prerelease": false,
"body": "## What's Changed\n\n* fix: example change for act dry-run simulation"
diff --git a/.github/act/release-slack-notification.yml b/.github/act/release-slack-notification.yml
new file mode 100644
index 000000000..bcc9854e8
--- /dev/null
+++ b/.github/act/release-slack-notification.yml
@@ -0,0 +1,21 @@
+name: Release Slack notification smoke
+
+on:
+ workflow_dispatch:
+
+jobs:
+ smoke:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v7
+ - name: Exercise production notification component
+ uses: ./.github/actions/release-slack-notification
+ with:
+ release-name: Release v0.9.2
+ tag: v0.9.2
+ url: https://github.com/headroomlabs-ai/headroom/releases/tag/v0.9.2
+ repository: headroomlabs-ai/headroom
+ actor: act-release-smoke
+ # Delivery is guarded by ACT=true. A deliberately invalid URL makes
+ # accidental network delivery fail closed instead of reaching Slack.
+ webhook-url: https://invalid.example/act-must-not-send
diff --git a/.github/actions/release-slack-notification/action.yml b/.github/actions/release-slack-notification/action.yml
new file mode 100644
index 000000000..212d9a66c
--- /dev/null
+++ b/.github/actions/release-slack-notification/action.yml
@@ -0,0 +1,68 @@
+name: Build and post release notification
+description: Announce a completed GitHub Release asset publication through Slack
+
+inputs:
+ release-name:
+ description: Human-readable GitHub Release name
+ required: true
+ tag:
+ description: Exact GitHub Release tag
+ required: true
+ url:
+ description: GitHub Release URL
+ required: true
+ repository:
+ description: Repository in owner/name form
+ required: true
+ actor:
+ description: GitHub actor who triggered the release workflow
+ required: true
+ webhook-url:
+ description: Incoming webhook bound to the Slack release channel
+ required: true
+
+runs:
+ using: composite
+ steps:
+ - name: Build Slack release payload
+ shell: bash
+ env:
+ RELEASE_NAME: ${{ inputs.release-name }}
+ RELEASE_TAG: ${{ inputs.tag }}
+ RELEASE_URL: ${{ inputs.url }}
+ RELEASE_REPOSITORY: ${{ inputs.repository }}
+ RELEASE_ACTOR: ${{ inputs.actor }}
+ run: |
+ python "$GITHUB_ACTION_PATH/build_payload.py" \
+ --release-name "$RELEASE_NAME" \
+ --tag "$RELEASE_TAG" \
+ --url "$RELEASE_URL" \
+ --repository "$RELEASE_REPOSITORY" \
+ --actor "$RELEASE_ACTOR" \
+ --output "$RUNNER_TEMP/slack-release-payload.json"
+ python -m json.tool "$RUNNER_TEMP/slack-release-payload.json"
+
+ # act documents ACT=true as its guard for external side effects. Payload
+ # construction still executes so the exact hosted-run JSON is validated.
+ - name: Post release to Slack
+ if: ${{ !env.ACT }}
+ shell: bash
+ env:
+ SLACK_RELEASES_WEBHOOK_URL: ${{ inputs.webhook-url }}
+ run: |
+ if [ -z "$SLACK_RELEASES_WEBHOOK_URL" ]; then
+ echo "::error::SLACK_RELEASES_WEBHOOK_URL is not configured"
+ exit 1
+ fi
+
+ response="$(curl \
+ --silent \
+ --show-error \
+ --fail-with-body \
+ --header 'Content-Type: application/json' \
+ --data-binary @"$RUNNER_TEMP/slack-release-payload.json" \
+ "$SLACK_RELEASES_WEBHOOK_URL")"
+ if [ "$response" != "ok" ]; then
+ echo "::error::Slack incoming webhook returned an unexpected response"
+ exit 1
+ fi
diff --git a/.github/actions/release-slack-notification/build_payload.py b/.github/actions/release-slack-notification/build_payload.py
new file mode 100644
index 000000000..639cbeef7
--- /dev/null
+++ b/.github/actions/release-slack-notification/build_payload.py
@@ -0,0 +1,108 @@
+"""Build the Slack payload for a completed GitHub Release asset publication."""
+
+from __future__ import annotations
+
+import argparse
+import html
+import json
+from pathlib import Path
+from urllib.parse import urlparse
+
+
+def _nonempty(value: str, label: str) -> str:
+ normalized = value.strip()
+ if not normalized:
+ raise ValueError(f"{label} must not be empty")
+ return normalized
+
+
+def _slack_text(value: str) -> str:
+ """Escape characters Slack reserves in mrkdwn text."""
+ return html.escape(value, quote=False)
+
+
+def build_payload(
+ *, release_name: str, tag: str, url: str, repository: str, actor: str
+) -> dict[str, object]:
+ tag = _nonempty(tag, "tag")
+ url = _nonempty(url, "url")
+ repository = _nonempty(repository, "repository")
+ actor = _nonempty(actor, "actor")
+ release_name = release_name.strip() or tag
+
+ parsed_url = urlparse(url)
+ if parsed_url.scheme != "https" or parsed_url.netloc != "github.com":
+ raise ValueError("url must be an https://github.com release URL")
+
+ header = f"{release_name} is ready"
+ if len(header) > 150:
+ raise ValueError("release name is too long for a Slack header block")
+
+ return {
+ "text": (
+ f"{_slack_text(release_name)} ({_slack_text(tag)}) "
+ f"GitHub Release assets are ready: {_slack_text(url)}"
+ ),
+ "blocks": [
+ {
+ "type": "header",
+ "text": {"type": "plain_text", "text": header, "emoji": True},
+ },
+ {
+ "type": "section",
+ "fields": [
+ {"type": "mrkdwn", "text": f"*Tag*\n`{_slack_text(tag)}`"},
+ {
+ "type": "mrkdwn",
+ "text": f"*Repository*\n`{_slack_text(repository)}`",
+ },
+ ],
+ },
+ {
+ "type": "section",
+ "text": {
+ "type": "mrkdwn",
+ "text": (
+ "GitHub Release assets are ready. "
+ f"<{_slack_text(url)}|View release notes and downloads>"
+ ),
+ },
+ },
+ {
+ "type": "context",
+ "elements": [
+ {
+ "type": "mrkdwn",
+ "text": (
+ f"Published by `{_slack_text(actor)}` after the release asset job "
+ "completed."
+ ),
+ }
+ ],
+ },
+ ],
+ }
+
+
+def main() -> None:
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--release-name", required=True)
+ parser.add_argument("--tag", required=True)
+ parser.add_argument("--url", required=True)
+ parser.add_argument("--repository", required=True)
+ parser.add_argument("--actor", required=True)
+ parser.add_argument("--output", type=Path, required=True)
+ args = parser.parse_args()
+
+ payload = build_payload(
+ release_name=args.release_name,
+ tag=args.tag,
+ url=args.url,
+ repository=args.repository,
+ actor=args.actor,
+ )
+ args.output.write_text(json.dumps(payload, ensure_ascii=False) + "\n", encoding="utf-8")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b468b70b0..d6ad34145 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1075,3 +1075,29 @@ jobs:
run: |
TAG="v${{ needs.detect-version.outputs.version }}"
gh release upload "$TAG" release-assets/*.tgz --clobber
+
+ notify-release:
+ # This boundary intentionally means "the GitHub Release and its assets are
+ # ready", not "every registry publish succeeded". create-release owns that
+ # narrower contract and only runs after the release build/smoke gates.
+ needs: create-release
+ if: >-
+ ${{
+ github.event_name == 'release' &&
+ github.event.action == 'published' &&
+ needs.create-release.result == 'success'
+ }}
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ steps:
+ - uses: actions/checkout@v7
+ - name: Announce completed GitHub Release assets
+ uses: ./.github/actions/release-slack-notification
+ with:
+ release-name: ${{ github.event.release.name }}
+ tag: ${{ github.event.release.tag_name }}
+ url: ${{ github.event.release.html_url }}
+ repository: ${{ github.repository }}
+ actor: ${{ github.actor }}
+ webhook-url: ${{ secrets.SLACK_RELEASES_WEBHOOK_URL }}
diff --git a/tests/test_release_workflows.py b/tests/test_release_workflows.py
index 18aba1756..eeb9066f4 100644
--- a/tests/test_release_workflows.py
+++ b/tests/test_release_workflows.py
@@ -2,7 +2,10 @@
from __future__ import annotations
+import json
import re
+import subprocess
+import sys
from pathlib import Path
import pytest
@@ -17,6 +20,115 @@ except ModuleNotFoundError: # pragma: no cover - Python 3.10 fallback
ROOT = Path(__file__).resolve().parent.parent
+def test_release_slack_payload_reports_the_completed_github_release(tmp_path: Path) -> None:
+ """A release notification must identify the exact published artifact boundary."""
+ output = tmp_path / "payload.json"
+
+ subprocess.run(
+ [
+ sys.executable,
+ str(ROOT / ".github" / "actions" / "release-slack-notification" / "build_payload.py"),
+ "--release-name",
+ "Headroom 1.2.3",
+ "--tag",
+ "v1.2.3",
+ "--url",
+ "https://github.com/headroomlabs-ai/headroom/releases/tag/v1.2.3",
+ "--repository",
+ "headroomlabs-ai/headroom",
+ "--actor",
+ "release<bot>",
+ "--output",
+ str(output),
+ ],
+ check=True,
+ )
+
+ payload = json.loads(output.read_text(encoding="utf-8"))
+ assert payload["text"] == (
+ "Headroom 1.2.3 (v1.2.3) GitHub Release assets are ready: "
+ "https://github.com/headroomlabs-ai/headroom/releases/tag/v1.2.3"
+ )
+ assert payload["blocks"] == [
+ {
+ "type": "header",
+ "text": {"type": "plain_text", "text": "Headroom 1.2.3 is ready", "emoji": True},
+ },
+ {
+ "type": "section",
+ "fields": [
+ {"type": "mrkdwn", "text": "*Tag*\n`v1.2.3`"},
+ {"type": "mrkdwn", "text": "*Repository*\n`headroomlabs-ai/headroom`"},
+ ],
+ },
+ {
+ "type": "section",
+ "text": {
+ "type": "mrkdwn",
+ "text": (
+ "GitHub Release assets are ready. "
+ "<https://github.com/headroomlabs-ai/headroom/releases/tag/v1.2.3|"
+ "View release notes and downloads>"
+ ),
+ },
+ },
+ {
+ "type": "context",
+ "elements": [
+ {
+ "type": "mrkdwn",
+ "text": "Published by `release&lt;bot&gt;` after the release asset job completed.",
+ }
+ ],
+ },
+ ]
+
+
+def test_release_workflow_notifies_slack_only_after_github_release_assets_are_ready() -> None:
+ """PR/manual runs and failed asset publication must never reach Slack delivery."""
+ workflow = yaml.safe_load(
+ (ROOT / ".github" / "workflows" / "release.yml").read_text(encoding="utf-8")
+ )
+ job = workflow["jobs"]["notify-release"]
+
+ assert job["needs"] == "create-release"
+ condition = str(job["if"])
+ assert "github.event_name == 'release'" in condition
+ assert "github.event.action == 'published'" in condition
+ assert "needs.create-release.result == 'success'" in condition
+
+ notify_step = next(
+ step
+ for step in job["steps"]
+ if step.get("uses") == "./.github/actions/release-slack-notification"
+ )
+ assert notify_step["with"]["url"] == "${{ github.event.release.html_url }}"
+ assert notify_step["with"]["tag"] == "${{ github.event.release.tag_name }}"
+ assert notify_step["with"]["webhook-url"] == "${{ secrets.SLACK_RELEASES_WEBHOOK_URL }}"
+
+ action = yaml.safe_load(
+ (ROOT / ".github" / "actions" / "release-slack-notification" / "action.yml").read_text(
+ encoding="utf-8"
+ )
+ )
+ build_step = next(
+ step
+ for step in action["runs"]["steps"]
+ if step.get("name") == "Build Slack release payload"
+ )
+ assert "build_payload.py" in build_step["run"]
+ assert build_step["env"]["RELEASE_URL"] == "${{ inputs.url }}"
+
+ post_step = next(
+ step for step in action["runs"]["steps"] if step.get("name") == "Post release to Slack"
+ )
+ assert str(post_step["if"]) == "${{ !env.ACT }}"
+ assert post_step["env"] == {"SLACK_RELEASES_WEBHOOK_URL": "${{ inputs.webhook-url }}"}
+ assert '--data-binary @"$RUNNER_TEMP/slack-release-payload.json"' in post_step["run"]
+ assert "--fail-with-body" in post_step["run"]
+ assert "webhook-url" not in str(build_step)
+
+
def test_every_published_docker_variant_includes_bedrock_auth_dependencies() -> None:
"""Every image that advertises ``--backend bedrock`` must ship botocore.