From 83b83f4ca1534929268ce325a7cf799e87bdf9dc Mon Sep 17 00:00:00 2001 From: Michal Checinski Date: Thu, 26 Oct 2023 16:11:39 +0200 Subject: [PATCH 1/4] Add Report deployment status to Slack action --- ...test-report-deployment-status-to-slack.yml | 28 ++++++++++ report-deployment-status-to-slack/action.yml | 55 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/test-report-deployment-status-to-slack.yml create mode 100644 report-deployment-status-to-slack/action.yml diff --git a/.github/workflows/test-report-deployment-status-to-slack.yml b/.github/workflows/test-report-deployment-status-to-slack.yml new file mode 100644 index 00000000..c6ea9e04 --- /dev/null +++ b/.github/workflows/test-report-deployment-status-to-slack.yml @@ -0,0 +1,28 @@ +--- +name: Test report-deployment-status-to-slack +on: + pull_request: + paths: + - "./report-deployment-status-to-slack" + - ".github/workflows/test-report-deployment-status-to-slack.yml" + +jobs: + test-report: + uses: ./.github/workflows/_report_status_to_slack.yml + with: + environment: US QA Cloud + tag: test-workflow + slack-channel: devops-alerts + failure: false + AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + + test-report-failure: + uses: ./.github/workflows/_report_status_to_slack.yml + with: + project: Server + environment: US QA Cloud + tag: test-workflow-failure + slack-channel: devops-alerts + failure: true + AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + diff --git a/report-deployment-status-to-slack/action.yml b/report-deployment-status-to-slack/action.yml new file mode 100644 index 00000000..d5cfd2ea --- /dev/null +++ b/report-deployment-status-to-slack/action.yml @@ -0,0 +1,55 @@ +name: "Report deployment status to Slack" +inputs: + project: + description: "The name of the project." + required: true + tag: + description: "The name of the branch or tag." + required: true + environment: + description: "The name of the environment." + required: true + slack-channel: + description: "The name of the slack channel." + required: true + default: team-eng-qa-devops + failure: + description: "If message should be a failure message" + required: false + default: 'false' + AZURE_KV_CI_SERVICE_PRINCIPAL: + description: "The service principal used to authenticate to Azure." + required: true + +runs: + using: "composite" + steps: + - name: Login to Azure - Prod Subscription + uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 + with: + creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + + - name: Retrieve slack secrets + id: retrieve-slack-secrets + uses: bitwarden/gh-actions/get-keyvault-secrets@master + with: + keyvault: bitwarden-ci + secrets: "slack-bot-token" + + - name: Post to a Slack channel on success + if: ${{ inputs.failure == 'false' }} + uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 + with: + channel-id: ${{ inputs.slack-channel }} + slack-message: ":white_check_mark: Updated ${{ inputs.environment }} to `${{ inputs.tag }}` on Server." + env: + SLACK_BOT_TOKEN: ${{ steps.retrieve-slack-secrets.outputs.slack-bot-token }} + + - name: Post to a Slack channel on failure + if: ${{ inputs.failure == 'true' }} + uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 + with: + channel-id: ${{ inputs.slack-channel }} + slack-message: ":x: Failed to update ${{ inputs.environment }} to `${{ inputs.tag }}` on ${{ inputs.project }}.\nPlease retry or contact @devops team." + env: + SLACK_BOT_TOKEN: ${{ steps.retrieve-slack-secrets.outputs.slack-bot-token }} \ No newline at end of file From 3ffb7df88130098b886c75c1e67d63a9489acfb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ch=C4=99ci=C5=84ski?= Date: Thu, 2 Nov 2023 17:36:11 +0100 Subject: [PATCH 2/4] Fix --- ...test-report-deployment-status-to-slack.yml | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test-report-deployment-status-to-slack.yml b/.github/workflows/test-report-deployment-status-to-slack.yml index c6ea9e04..e29237ba 100644 --- a/.github/workflows/test-report-deployment-status-to-slack.yml +++ b/.github/workflows/test-report-deployment-status-to-slack.yml @@ -8,21 +8,27 @@ on: jobs: test-report: - uses: ./.github/workflows/_report_status_to_slack.yml - with: - environment: US QA Cloud - tag: test-workflow - slack-channel: devops-alerts - failure: false - AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + name: Test Slack report failure + runs-on: ubuntu-22.04 + steps: + - uses: ./report-deployment-status-to-slack + with: + environment: US QA Cloud + tag: test-workflow + slack-channel: devops-alerts + failure: false + AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} test-report-failure: - uses: ./.github/workflows/_report_status_to_slack.yml - with: - project: Server - environment: US QA Cloud - tag: test-workflow-failure - slack-channel: devops-alerts - failure: true - AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + name: Test Slack report failure + runs-on: ubuntu-22.04 + steps: + - uses: ./report-deployment-status-to-slack + with: + project: Server + environment: US QA Cloud + tag: test-workflow-failure + slack-channel: devops-alerts + failure: true + AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} From 098a80aa9591790f33ffe97bf240b3ddc468dc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ch=C4=99ci=C5=84ski?= Date: Thu, 2 Nov 2023 17:37:59 +0100 Subject: [PATCH 3/4] fix --- .../workflows/test-report-deployment-status-to-slack.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-report-deployment-status-to-slack.yml b/.github/workflows/test-report-deployment-status-to-slack.yml index e29237ba..2e517c57 100644 --- a/.github/workflows/test-report-deployment-status-to-slack.yml +++ b/.github/workflows/test-report-deployment-status-to-slack.yml @@ -8,9 +8,11 @@ on: jobs: test-report: - name: Test Slack report failure + name: Test Slack report runs-on: ubuntu-22.04 steps: + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: ./report-deployment-status-to-slack with: environment: US QA Cloud @@ -23,6 +25,8 @@ jobs: name: Test Slack report failure runs-on: ubuntu-22.04 steps: + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: ./report-deployment-status-to-slack with: project: Server From 8967f25b79fec7084bba1794c4739c3ee66883c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ch=C4=99ci=C5=84ski?= Date: Thu, 2 Nov 2023 17:41:33 +0100 Subject: [PATCH 4/4] Fix input --- report-deployment-status-to-slack/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/report-deployment-status-to-slack/action.yml b/report-deployment-status-to-slack/action.yml index d5cfd2ea..7b0a0690 100644 --- a/report-deployment-status-to-slack/action.yml +++ b/report-deployment-status-to-slack/action.yml @@ -27,7 +27,7 @@ runs: - name: Login to Azure - Prod Subscription uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 with: - creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + creds: ${{ inputs.AZURE_KV_CI_SERVICE_PRINCIPAL }} - name: Retrieve slack secrets id: retrieve-slack-secrets