Skip to content

Commit 69548c4

Browse files
GHA-210 Send release summary to the Slack channel. (#117)
Co-authored-by: Nils Werner <64034005+nils-werner-sonarsource@users.noreply.github.com>
1 parent 93bd557 commit 69548c4

4 files changed

Lines changed: 124 additions & 34 deletions

File tree

.github/workflows/automated-release.yml

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ jobs:
698698
# This step summarizes the results of the entire release process.
699699
# It checks the outcomes of all previous steps and generates a summary indicating whether the release was
700700
# successful or failed, along with relevant links and information.
701-
summarize_release:
701+
summarize-release:
702702
name: Release Results
703703
runs-on: ${{ inputs.runner-environment }}
704704
if: always()
@@ -714,11 +714,14 @@ jobs:
714714
- create-integration-tickets
715715
- update-analyzers
716716
env:
717-
RELEASE_PROCESS: ${{ inputs.release-process != '' && inputs.release-process || 'https://xtranet-sonarsource.atlassian.net/wiki/spaces/CSD/pages/4325048388/Release+Instructions+-+Cloud+Security' }}
717+
RELEASE_PROCESS: ${{ inputs.release-process }}
718718
steps:
719-
- name: Post Summary to Workflow
719+
720+
- name: Create Message
721+
id: create-message
720722
shell: bash
721723
env:
724+
PROJECT_NAME: ${{ inputs.project-name }}
722725
RELEASE_VERSION: ${{ needs.prepare-release.outputs.release-version }}
723726
NEW_VERSION: ${{ needs.release-in-jira.outputs.new-version || 'not created' }}
724727
JIRA_RELEASE_URL: ${{ needs.prepare-release.outputs.jira-release-url || 'not resolved' }}
@@ -734,44 +737,68 @@ jobs:
734737
RESULT_PUBLISH_GITHUB_RELEASE: ${{ needs.publish-github-release.result }}
735738
RESULT_CREATE_RELEASE_TICKET: ${{ needs.create-release-ticket.result }}
736739
RESULT_RELEASE_IN_JIRA: ${{ needs.release-in-jira.result }}
740+
RESULT_BUMP_VERSION: ${{ needs.bump-version.result }}
737741
RESULT_CREATE_INTEGRATION_TICKETS: ${{ needs.create-integration-tickets.result }}
738742
RESULT_UPDATE_ANALYZERS: ${{ needs.update-analyzers.result }}
739743
run: |
740744
ALL_SUCCESS=true
741-
for result in "$RESULT_CHECK_RELEASABILITY" "$RESULT_PREPARE_RELEASE" "$RESULT_PUBLISH_GITHUB_RELEASE" "$RESULT_CREATE_RELEASE_TICKET" "$RESULT_RELEASE_IN_JIRA" "$RESULT_CREATE_INTEGRATION_TICKETS" "$RESULT_UPDATE_ANALYZERS"; do
745+
for result in "$RESULT_CHECK_RELEASABILITY" "$RESULT_PREPARE_RELEASE" "$RESULT_PUBLISH_GITHUB_RELEASE" "$RESULT_CREATE_RELEASE_TICKET" "$RESULT_RELEASE_IN_JIRA" "$RESULT_CREATE_INTEGRATION_TICKETS" "$RESULT_UPDATE_ANALYZERS" "$RESULT_BUMP_VERSION"; do
742746
if [[ "$result" != "success" && "$result" != "skipped" ]]; then
743747
ALL_SUCCESS=false
744748
break
745749
fi
746750
done
747-
748-
if [[ "$ALL_SUCCESS" == "true" ]]; then
749-
echo "# 🎉 Release Successful" >> $GITHUB_STEP_SUMMARY
750-
echo "The automated release completed without errors. Below is a consolidated overview of the run." >> $GITHUB_STEP_SUMMARY
751-
else
752-
echo "# ❌ Release Failed" >> $GITHUB_STEP_SUMMARY
753-
echo "One or more jobs failed. Review the job logs and links below." >> $GITHUB_STEP_SUMMARY
754-
fi
755-
echo "" >> $GITHUB_STEP_SUMMARY
756751
757-
cat <<EOF >> $GITHUB_STEP_SUMMARY
758-
- Released Version: \`$RELEASE_VERSION\`
759-
- New Version: \`$NEW_VERSION\`
760-
- Jira Release: $JIRA_RELEASE_URL
761-
- Release Ticket: $RELEASE_TICKET_URL
762-
- GitHub Release: $GITHUB_RELEASE_URL
763-
- SQS Integration Ticket: $SQS_TICKET_URL
764-
- SQC Integration Ticket: $SQC_TICKET_URL
765-
- SQS Analyzer PR: $SQS_PR_URL
766-
- SQC Analyzer PR: $SQC_PR_URL
767-
- Bump Version PR: $BUMP_VERSION_PR_URL
768-
EOF
769-
770-
echo "## Guidance" >> $GITHUB_STEP_SUMMARY
771-
if [[ "$ALL_SUCCESS" == "true" ]]; then
772-
echo "- Review and merge the bump version, SQS and SQC PRs." >> $GITHUB_STEP_SUMMARY
773-
echo "- Update integration ticket statuses (ensure SQS ticket fix versions are set)." >> $GITHUB_STEP_SUMMARY
774-
else
775-
echo "- Check failed jobs for error messages and re-run as needed." >> $GITHUB_STEP_SUMMARY
776-
fi
777-
echo "- Reference: $RELEASE_PROCESS" >> $GITHUB_STEP_SUMMARY
752+
{
753+
echo "message<<ENDOFMESSAGE"
754+
755+
if [[ "$USE_JIRA_SANDBOX" == "true" ]]; then
756+
echo "# DRY RUN (NOT A REAL RELEASE)"
757+
fi
758+
759+
if [[ "$ALL_SUCCESS" == "true" ]]; then
760+
echo "# 🎉 ${PROJECT_NAME}: Release Successful"
761+
echo "The automated release completed without errors. Below is a consolidated overview of the run."
762+
else
763+
echo "# ❌ ${PROJECT_NAME}: Release Failed"
764+
echo "One or more jobs failed. Review the job logs and links below."
765+
fi
766+
echo ""
767+
768+
echo " - Released Version: \`$RELEASE_VERSION\`"
769+
echo " - Next Iteration Version: \`$NEW_VERSION\`"
770+
echo " - Jira Release: $JIRA_RELEASE_URL"
771+
echo " - Release Ticket: $RELEASE_TICKET_URL"
772+
echo " - GitHub Release: $GITHUB_RELEASE_URL"
773+
echo " - GitHub Action Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
774+
echo " - SQS Integration Ticket: $SQS_TICKET_URL"
775+
echo " - SQC Integration Ticket: $SQC_TICKET_URL"
776+
echo " - SQS Analyzer PR: $SQS_PR_URL"
777+
echo " - SQC Analyzer PR: $SQC_PR_URL"
778+
echo " - Bump Version PR: $BUMP_VERSION_PR_URL"
779+
780+
echo "## Guidance"
781+
if [[ "$ALL_SUCCESS" == "true" ]]; then
782+
echo "- Review and merge the bump version, SQS and SQC PRs."
783+
echo "- Update integration ticket statuses (ensure SQS ticket fix versions are set)."
784+
else
785+
echo "- Check failed jobs for error messages and re-run as needed."
786+
fi
787+
echo "- Reference: $RELEASE_PROCESS"
788+
echo "ENDOFMESSAGE"
789+
} >> $GITHUB_OUTPUT
790+
791+
- name: Post Summary to Workflow
792+
id: summary
793+
shell: bash
794+
env:
795+
MESSAGE: ${{ steps.create-message.outputs.message }}
796+
run: |
797+
echo "${MESSAGE}" >> $GITHUB_STEP_SUMMARY
798+
799+
- name: Post Summary to Slack
800+
if: ${{ inputs.slack-channel != '' }}
801+
uses: SonarSource/release-github-actions/slack-message@v1
802+
with:
803+
channel: ${{ inputs.slack-channel }}
804+
message-markdown: ${{ steps.create-message.outputs.message }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ A centralized collection of reusable GitHub Actions designed to streamline and a
1717
| [Get Release Version](get-release-version/README.md) | Extracts the release version from the repox status on a specified branch |
1818
| [Lock Branch](lock-branch/README.md) | Locks or unlocks a branch by modifying the `lock_branch` setting in branch protection rules |
1919
| [Notify Slack on Failure](notify-slack/README.md) | Sends a Slack notification when a job fails |
20+
| [Send Slack Message](slack-message/README.md) | Sends a markdown message to a Slack channel |
2021
| [Publish GitHub Release](publish-github-release/README.md) | Publishes a GitHub Release with notes fetched from Jira or provided directly |
2122
| [Release Jira Version](release-jira-version/README.md) | Releases a Jira version and creates the next one |
2223
| [Sonar Update Center Release](sonar-update-center-release/README.md) | Updates a plugin entry in sonar-update-center-properties and creates a pull request |

slack-message/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Send Slack Message Action
2+
3+
Sends a markdown message to a Slack channel.
4+
5+
Unlike `rtCamp/action-slack-notify`, this action uses `slackapi/slack-github-action` and does not require Docker.
6+
7+
## Inputs
8+
9+
| Input | Description | Required |
10+
|--------------------|-------------------------------------------------------|----------|
11+
| `channel` | Slack channel (without `#`) to post the message into. | Yes |
12+
| `message-markdown` | The message to send, in markdown format. | Yes |
13+
14+
## Implementation Details
15+
16+
This action depends on:
17+
18+
- [LoveToKnow/slackify-markdown-action](https://github.com/LoveToKnow/slackify-markdown-action) to convert markdown to Slack's mrkdwn format
19+
- [slackapi/slack-github-action](https://github.com/slackapi/slack-github-action) to send the message via `chat.postMessage`

slack-message/action.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'Send Slack Message'
2+
description: 'Sends a markdown message to a Slack channel.'
3+
4+
inputs:
5+
channel:
6+
description: 'The Slack channel to send the message to (without #).'
7+
required: true
8+
message-markdown:
9+
description: 'The message to send, in markdown format.'
10+
required: true
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Vault Secrets
16+
id: secrets
17+
uses: SonarSource/vault-action-wrapper@v3
18+
with:
19+
secrets: |
20+
development/kv/data/slack token | SLACK_TOKEN;
21+
22+
- name: Convert Markdown to Slack
23+
id: slackify
24+
uses: LoveToKnow/slackify-markdown-action@698a1d4d0ff1794152a93c03ee8ca5e03a310d4e # v1.1.1
25+
with:
26+
text: ${{ inputs.message-markdown }}
27+
28+
- name: Build Payload
29+
id: payload
30+
shell: bash
31+
env:
32+
CHANNEL: ${{ inputs.channel }}
33+
MESSAGE: ${{ steps.slackify.outputs.text }}
34+
run: |
35+
PAYLOAD=$(jq -cn --arg channel "$CHANNEL" --arg text "$MESSAGE" '{channel: $channel, text: $text}')
36+
echo "json=$PAYLOAD" >> $GITHUB_OUTPUT
37+
38+
- name: Send Slack Message
39+
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
40+
with:
41+
method: chat.postMessage
42+
token: ${{ fromJSON(steps.secrets.outputs.vault).SLACK_TOKEN }}
43+
payload: ${{ steps.payload.outputs.json }}

0 commit comments

Comments
 (0)