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
5 changes: 4 additions & 1 deletion .github/workflows/smoke-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,8 @@ jobs:
publish-manifests-result: ${{ needs.publish-manifests.result }}
build-result: ${{ needs.build-container-image.result }}
slack-token: ${{ secrets.SLACK_CONTAINER_IMAGE_TOKEN }}
channel-id: C07UG6JH44F # notifications-container-images
# This tests that the subject is correctly overwritten
message-subject: Build actions/smoke container image
# notifications-container-images
channel-id: C07UG6JH44F
type: container-image-build
2 changes: 2 additions & 0 deletions send-slack-notification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ jobs:
- `build-result` (optional, e.g. `success`)
- `publish-manifests-result` (optional, e.g. `failure`)
- `publish-helm-chart-result` (optional, e.g. `failure`)
- `message-subject` (optional, defaults to `github.workflow` for `container-image-build` and
`github.repository` for `integration-test`)

### Outputs

Expand Down
21 changes: 18 additions & 3 deletions send-slack-notification/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
description: The list (plain text) of failed tests
slack-token:
description: The Slack token
message-subject:
description: |
The main message subject of the notification message. This defaults to github.workflow for
build notifications and github.repository for integration test notifications.
runs:
using: composite
steps:
Expand Down Expand Up @@ -88,11 +92,17 @@ runs:
SLACK_THREAD_YAML: |
${{ steps.retrieve-slack-thread-id.outcome == 'success' && format('thread_ts: "{0}"', env.SLACK_THREAD_ID) || '' }}
CHANNEL_ID: ${{ inputs.channel-id }}
MESSAGE_SUBJECT: ${{ inputs.message-subject }}
shell: bash
run: |
export WORKFLOW_RUN_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/attempts/${GITHUB_RUN_ATTEMPT}"

if [ "$NOTIFICATION_TYPE" == "container-image-build" ]; then
# Only override the message subject with the default value if it is empty
if [ -z "${MESSAGE_SUBJECT:-}" ]; then
export MESSAGE_SUBJECT="$GITHUB_WORKFLOW"
fi

# TODO (@Techassi): Also add success template
if [ "$PUBLISH_MANIFESTS_RESULT" = "failure" ] || [ "$PUBLISH_HELM_CHART_RESULT" = "failure" ] || [ "$BUILD_RESULT" = "failure" ]; then
export MESSAGE_VERB=failed
Expand All @@ -102,19 +112,24 @@ runs:
export MESSAGE_COLOR=10c400
fi

export MESSAGE_TEXT="*$GITHUB_WORKFLOW* $MESSAGE_VERB (attempt $GITHUB_RUN_ATTEMPT)"
export MESSAGE_TEXT="*$MESSAGE_SUBJECT* $MESSAGE_VERB (attempt $GITHUB_RUN_ATTEMPT)"
PAYLOAD=$(envsubst < "${GITHUB_ACTION_PATH}/templates/container-image-build/failure.tpl")
echo -e "PAYLOAD<<EOF\n$PAYLOAD\nEOF" | tee -a "$GITHUB_ENV"
elif [ "$NOTIFICATION_TYPE" == "integration-test" ]; then
# Only override the message subject with the default value if it is empty
if [ -z "${MESSAGE_SUBJECT:-}" ]; then
export MESSAGE_SUBJECT="$GITHUB_REPOSITORY"
fi

export HEALTH_SLACK_EMOJI=$(echo "$TEST_HEALTH" | cut -d ',' -f 1)
export HEALTH_RATE=$(echo "$TEST_HEALTH" | cut -d ',' -f 3)

if [ "$TEST_RESULT" == "failure" ]; then
export MESSAGE_TEXT="The integration test for *`$GITHUB_REPOSITORY`* failed."
export MESSAGE_TEXT="The integration test for *`$MESSAGE_SUBJECT`* failed."
PAYLOAD=$(envsubst < "${GITHUB_ACTION_PATH}/templates/integration-test/failure.tpl")
echo -e "PAYLOAD<<EOF\n$PAYLOAD\nEOF" | tee -a "$GITHUB_ENV"
else
export MESSAGE_TEXT="The integration test for *`$GITHUB_REPOSITORY`* succeeded."
export MESSAGE_TEXT="The integration test for *`$MESSAGE_SUBJECT`* succeeded."
PAYLOAD=$(envsubst < "${GITHUB_ACTION_PATH}/templates/integration-test/success.tpl")
echo -e "PAYLOAD<<EOF\n$PAYLOAD\nEOF" | tee -a "$GITHUB_ENV"
fi
Expand Down
Loading