diff --git a/.github/workflows/release-dispatch.yml b/.github/workflows/release-dispatch.yml index 05fdfd3..62ee30c 100644 --- a/.github/workflows/release-dispatch.yml +++ b/.github/workflows/release-dispatch.yml @@ -40,7 +40,10 @@ jobs: go-version: '1.24' - name: Create and push release tag - run: ./scripts/release-version.sh "${{ inputs.bump }}" --push + id: release_tag + run: | + ./scripts/release-version.sh "${{ inputs.bump }}" --push + echo "tag=$(git describe --tags --exact-match)" >> "${GITHUB_OUTPUT}" # Run GoReleaser in the SAME job rather than relying on the tag push to # trigger release.yml. The tag above is pushed with the default @@ -57,3 +60,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }} + + - name: Notify Slack + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_ALERTS_WEBHOOK_URL }} + run: ./scripts/notify-slack-release.sh "${{ steps.release_tag.outputs.tag }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 95143b5..870b6ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,3 +38,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }} + + - name: Notify Slack + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_ALERTS_WEBHOOK_URL }} + run: ./scripts/notify-slack-release.sh "${{ github.ref_name }}" diff --git a/scripts/notify-slack-release.sh b/scripts/notify-slack-release.sh new file mode 100755 index 0000000..0840547 --- /dev/null +++ b/scripts/notify-slack-release.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +set -euo pipefail + +TAG="${1:-}" +WEBHOOK_URL="${SLACK_WEBHOOK_URL:-}" +REPOSITORY="${GITHUB_REPOSITORY:-hostodo/odo-cli}" +SERVER_URL="${GITHUB_SERVER_URL:-https://github.com}" + +if [[ ! "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: release tag must use vMAJOR.MINOR.PATCH format." >&2 + exit 1 +fi + +if [[ -z "${WEBHOOK_URL}" ]]; then + echo "Error: SLACK_WEBHOOK_URL is not configured." >&2 + exit 1 +fi + +RELEASE_URL="${SERVER_URL}/${REPOSITORY}/releases/tag/${TAG}" +PAYLOAD="$(jq -n \ + --arg title "odo CLI ${TAG} released" \ + --arg url "${RELEASE_URL}" \ + '{ + text: $title, + blocks: [ + { + type: "header", + text: {type: "plain_text", text: $title} + }, + { + type: "section", + text: { + type: "plain_text", + text: "New macOS, Linux, and Windows builds are available." + } + }, + { + type: "actions", + elements: [ + { + type: "button", + text: {type: "plain_text", text: "View release"}, + url: $url, + action_id: "view_odo_cli_release" + } + ] + } + ] + }')" + +curl \ + --fail-with-body \ + --silent \ + --show-error \ + --retry 3 \ + --retry-all-errors \ + --header 'Content-Type: application/json' \ + --data-binary "${PAYLOAD}" \ + "${WEBHOOK_URL}" + +echo +echo "Slack release notification sent for ${TAG}."