Skip to content

Commit

Permalink
ci(slackbot): clean up slack alerts (#1272)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

- Seems to be a classic case of "smør på flesk" to have both the
pipeline failing slack message and the k6-tests slack message. Won't
give any additional value until we can upload the test result file in
the message and make it sweeter:
slackapi/slack-github-action#92 Removing for
now.
- Tweaked the template a bit for the pipeline slack message
- This is a good start, and we can expand by adding more info on the
slack-message, for now posting a status for each workflow.

<img width="673" alt="image"
src="https://github.com/user-attachments/assets/d2dccb8c-2e1f-44da-add1-dd8a0a9af2f7">

## Related Issue(s)

- #230

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced Slack notifications for pipeline statuses with improved
structure and clarity.
- Introduced a new GitHub Actions workflow for sending CI/CD status
updates to Slack, capturing results from multiple jobs.
- Updated existing Slack message jobs to report on both success and
failure conditions across various environments.

- **Bug Fixes**
- Removed unnecessary Slack message sending on K6 test failures,
streamlining the workflow.

- **Documentation**
- Updated environment variables and job conditions for better clarity
and functionality in CI/CD processes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
arealmaas authored Oct 11, 2024
1 parent 3034372 commit dd4b019
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 107 deletions.
73 changes: 51 additions & 22 deletions .github/slack-templates/pipeline-failed.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*:rotating_light: Pipeline failing for *${{ env.ENVIRONMENT }}* :rotating_light:*\n\nPlease check the workflow for more details."
}
},
{ "type": "divider" },
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Run"
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
"attachments": [
{
"color": "#FF0000",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Github pipeline status",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Environment:* ${{ env.ENVIRONMENT }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Job Status:*\n• Infrastructure: ${{ env.INFRA_STATUS }}\n• Apps: ${{ env.APPS_STATUS }}\n• Slack Notifier: ${{ env.SLACK_NOTIFIER_STATUS }}\n• E2E Tests: ${{ env.E2E_TESTS_STATUS }}\n• Schema NPM: ${{ env.SCHEMA_NPM_STATUS }}\n• Publish: ${{ env.PUBLISH_STATUS }}"
}
]
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Please check the workflow for more details."
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Run"
},
"url": "${{ env.RUN_URL }}"
}
]
}
]
}
]
}
36 changes: 0 additions & 36 deletions .github/workflows/action-run-k6-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ on:
required: true
TOKEN_GENERATOR_PASSWORD:
required: true
SLACK_BOT_TOKEN:
required: true

jobs:
k6-test:
Expand Down Expand Up @@ -57,37 +55,3 @@ jobs:
action_fail: true
files: |
junit.xml
- name: Send Slack message on K6 test failure
if: always() && failure()
uses: slackapi/slack-github-action@v1.27.0
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_K6_TESTS }}
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*:rotating_light: K6 Tests Failed for environment *${{ inputs.environment }}* :rotating_light:*\n\nPlease check the workflow for more details."
}
},
{ "type": "divider" },
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Run"
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
85 changes: 85 additions & 0 deletions .github/workflows/action-send-ci-cd-status-slack-message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Send CI/CD Status Slack Message

on:
workflow_call:
inputs:
environment:
required: true
type: string
infra_status:
type: string
description: "Status of the infrastructure deployment job"
default: "skipped"
apps_status:
type: string
description: "Status of the apps deployment job"
default: "skipped"
slack_notifier_status:
type: string
description: "Status of the Slack notifier deployment job"
default: "skipped"
e2e_tests_status:
type: string
description: "Status of the end-to-end tests job"
default: "skipped"
schema_npm_status:
type: string
description: "Status of the schema npm publishing job"
default: "skipped"
publish_status:
type: string
description: "Status of the docker image publishing job"
default: "skipped"
secrets:
SLACK_BOT_TOKEN:
required: true
SLACK_CHANNEL_ID:
required: true

jobs:
send-slack-message:
name: Send Slack message
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Determine status emojis
id: status-emojis
run: |
determine_emoji() {
local -A emoji_map=(
[success]=":white_check_mark:"
[failure]=":x:"
[cancelled]=":warning:"
[skipped]=":ballot_box_with_check:"
)
echo "${emoji_map[$1]:-Invalid status: $1}"
}
{
echo "INFRA_EMOJI=$(determine_emoji "${{ inputs.infra_status }}")"
echo "APPS_EMOJI=$(determine_emoji "${{ inputs.apps_status }}")"
echo "SLACK_NOTIFIER_EMOJI=$(determine_emoji "${{ inputs.slack_notifier_status }}")"
echo "E2E_TESTS_EMOJI=$(determine_emoji "${{ inputs.e2e_tests_status }}")"
echo "SCHEMA_NPM_EMOJI=$(determine_emoji "${{ inputs.schema_npm_status }}")"
echo "PUBLISH_EMOJI=$(determine_emoji "${{ inputs.publish_status }}")"
} >> "$GITHUB_OUTPUT"
- name: Send GitHub slack message
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
ENVIRONMENT: ${{ inputs.environment }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
# statuses
INFRA_STATUS: "${{ steps.status-emojis.outputs.INFRA_EMOJI }}"
APPS_STATUS: "${{ steps.status-emojis.outputs.APPS_EMOJI }}"
SLACK_NOTIFIER_STATUS: "${{ steps.status-emojis.outputs.SLACK_NOTIFIER_EMOJI }}"
E2E_TESTS_STATUS: "${{ steps.status-emojis.outputs.E2E_TESTS_EMOJI }}"
SCHEMA_NPM_STATUS: "${{ steps.status-emojis.outputs.SCHEMA_NPM_EMOJI }}"
PUBLISH_STATUS: "${{ steps.status-emojis.outputs.PUBLISH_EMOJI }}"
uses: slackapi/slack-github-action@v1.27.0
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
payload-file-path: "./.github/slack-templates/pipeline-failed.json"
30 changes: 14 additions & 16 deletions .github/workflows/ci-cd-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ jobs:
secrets:
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
environment: test
apiVersion: v1
Expand All @@ -151,20 +150,19 @@ jobs:
checks: write
pull-requests: write

send-slack-message:
send-slack-message-on-failure:
name: Send Slack message on failure
needs: [deploy-infra-test, deploy-apps-test, deploy-slack-notifier-test, run-e2e-tests, publish-schema-npm]
runs-on: ubuntu-latest
needs: [deploy-infra-test, deploy-apps-test, deploy-slack-notifier-test, run-e2e-tests, publish-schema-npm, publish]
if: ${{ always() && failure() && !cancelled() }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Send GitHub slack message
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
ENVIRONMENT: test
uses: slackapi/slack-github-action@v1.27.0
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
payload-file-path: "./.github/slack-templates/pipeline-failed.json"
uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml
with:
environment: test
infra_status: ${{ needs.deploy-infra-test.result }}
apps_status: ${{ needs.deploy-apps-test.result }}
slack_notifier_status: ${{ needs.deploy-slack-notifier-test.result }}
e2e_tests_status: ${{ needs.run-e2e-tests.result }}
schema_npm_status: ${{ needs.publish-schema-npm.result }}
publish_status: ${{ needs.publish.result }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }}
25 changes: 10 additions & 15 deletions .github/workflows/ci-cd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ jobs:
# secrets:
# TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
# TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
# SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
# with:
# environment: prod
# apiVersion: v1
Expand All @@ -136,20 +135,16 @@ jobs:
# checks: write
# pull-requests: write

send-slack-message:
send-slack-message-on-failure:
name: Send Slack message on failure
needs: [deploy-infra-prod, deploy-apps-prod, deploy-slack-notifier-prod]
runs-on: ubuntu-latest
if: ${{ always() && failure() && !cancelled() }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Send GitHub slack message
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
ENVIRONMENT: prod
uses: slackapi/slack-github-action@v1.27.0
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
payload-file-path: "./.github/slack-templates/pipeline-failed.json"
uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml
with:
environment: prod
infra_status: ${{ needs.deploy-infra-prod.result }}
apps_status: ${{ needs.deploy-apps-prod.result }}
slack_notifier_status: ${{ needs.deploy-slack-notifier-prod.result }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }}
2 changes: 0 additions & 2 deletions .github/workflows/ci-cd-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ jobs:
dryRun: true
version: ${{ needs.get-current-version.outputs.version }}-${{ needs.generate-git-short-sha.outputs.gitShortSha }}


dry-run-deploy-apps:
name: Dry run deploy apps
needs:
Expand Down Expand Up @@ -90,7 +89,6 @@ jobs:
runMigration: ${{ needs.check-for-changes.outputs.hasMigrationChanges == 'true' }}
dryRun: true


delete-github-deployments:
name: Delete GitHub deployments
uses: ./.github/workflows/action-delete-deployments.yml
Expand Down
30 changes: 14 additions & 16 deletions .github/workflows/ci-cd-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ jobs:
secrets:
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
environment: staging
apiVersion: v1
Expand All @@ -115,20 +114,19 @@ jobs:
checks: write
pull-requests: write

send-slack-message:
send-slack-message-on-failure:
name: Send Slack message on failure
needs: [deploy-infra-staging, deploy-apps-staging, deploy-slack-notifier-staging, run-e2e-tests, publish-schema-npm]
runs-on: ubuntu-latest
needs: [deploy-infra-staging, deploy-apps-staging, deploy-slack-notifier-staging, run-e2e-tests, publish-schema-npm, publish]
if: ${{ always() && failure() && !cancelled() }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Send GitHub slack message
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
ENVIRONMENT: staging
uses: slackapi/slack-github-action@v1.27.0
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
payload-file-path: "./.github/slack-templates/pipeline-failed.json"
uses: ./.github/workflows/action-send-ci-cd-status-slack-message.yml
with:
environment: staging
infra_status: ${{ needs.deploy-infra-staging.result }}
apps_status: ${{ needs.deploy-apps-staging.result }}
slack_notifier_status: ${{ needs.deploy-slack-notifier-staging.result }}
e2e_tests_status: ${{ needs.run-e2e-tests.result }}
schema_npm_status: ${{ needs.publish-schema-npm.result }}
publish_status: ${{ needs.publish.result }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }}

0 comments on commit dd4b019

Please sign in to comment.