diff --git a/.github/workflows/test-report-deployment-status-to-slack.yml b/.github/workflows/test-report-deployment-status-to-slack.yml index a390bd44..44191dd0 100644 --- a/.github/workflows/test-report-deployment-status-to-slack.yml +++ b/.github/workflows/test-report-deployment-status-to-slack.yml @@ -8,12 +8,13 @@ on: jobs: test-report-start: - name: Test Slack report start + name: Test Slack report runs-on: ubuntu-22.04 steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - uses: ./report-deployment-status-to-slack + - name: Start + uses: ./report-deployment-status-to-slack with: project: Server environment: US QA Cloud @@ -24,13 +25,8 @@ jobs: url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - test-report: - name: Test Slack report - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - - uses: ./report-deployment-status-to-slack + - name: Success + uses: ./report-deployment-status-to-slack with: project: Server environment: US QA Cloud @@ -41,13 +37,8 @@ jobs: url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - test-report-failure: - name: Test Slack report failure - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - - uses: ./report-deployment-status-to-slack + - name: Failure + uses: ./report-deployment-status-to-slack with: project: Server environment: US QA Cloud @@ -64,7 +55,7 @@ jobs: steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - name: Slack report with DB migration true on main + - name: With DB migration true on main uses: ./report-deployment-status-to-slack with: project: Server @@ -77,7 +68,7 @@ jobs: url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - - name: Slack report with DB migration false on main + - name: With DB migration false on main uses: ./report-deployment-status-to-slack with: project: Server @@ -90,28 +81,28 @@ jobs: url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - - name: Slack report with DB migration true on test branch + - name: With DB migration true on test branch uses: ./report-deployment-status-to-slack with: project: Server environment: US QA Cloud - tag: test-branch + tag: test-branch-failure slack-channel: devops-alerts-test event: 'failure' commit-sha: ${{ github.sha }} - db_migration_detected: true + db_migration_detected: false url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - - name: Slack report with DB migration false on test branch + - name: With DB migration false on test branch uses: ./report-deployment-status-to-slack with: project: Server environment: US QA Cloud - tag: test-branch + tag: test-branch-success slack-channel: devops-alerts-test event: 'success' commit-sha: ${{ github.sha }} - db_migration_detected: false + db_migration_detected: true url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} 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 index 35fbf15b..1c8e1eaa 100644 --- a/report-deployment-status-to-slack/action.yml +++ b/report-deployment-status-to-slack/action.yml @@ -60,64 +60,48 @@ runs: id: setup shell: bash run: | - if [[ ${{ inputs.db_migration_detected }} == true ]]; then - case "${{ inputs.event }}" in - start) - SLACK_MESSAGE=":loading: Updating ${{ inputs.environment }} to \`${{ inputs.tag }}\` on ${{ inputs.project }}. - ${{ inputs.url }} - SHA: \`${{ inputs.commit-sha }}\` - :red_siren: This branch has database migration changes." - ;; - - success) - SLACK_MESSAGE=":white_check_mark: Updated ${{ inputs.environment }} to \`${{ inputs.tag }}\` on ${{ inputs.project }}. - ${{ inputs.url }} - SHA: \`${{ inputs.commit-sha }}\` - :red_siren: This branch has database migration changes." - ;; - - failure) - SLACK_MESSAGE=":x: Failed to update ${{ inputs.environment }} to \`${{ inputs.tag }}\` on ${{ inputs.project }}. - ${{ inputs.url }} - SHA: \`${{ inputs.commit-sha }}\` - Please retry or contact @devops team. - :red_siren: This branch has database migration changes." - ;; + function slack_message_fn () { + local event=$1 + local environment=$2 + local tag=$3 + local project=$4 + local url=$5 + local commit_sha=$6 - cancelled) - SLACK_MESSAGE=":hand: Cancelled update of ${{ inputs.environment }} to \`${{ inputs.tag }}\` on ${{ inputs.project }}. - ${{ inputs.url }} - SHA: \`${{ inputs.commit-sha }}\` - :red_siren: This branch has database migration changes." - ;; - esac - else - case "${{ inputs.event }}" in + case $event in start) - SLACK_MESSAGE=":loading: Updating ${{ inputs.environment }} to \`${{ inputs.tag }}\` on ${{ inputs.project }}. - ${{ inputs.url }} - SHA: \`${{ inputs.commit-sha }}\`" + SLACK_MESSAGE=":loading: Updating $environment to \`$tag\` on $project. + $url + SHA: \`$commit_sha\`" ;; success) - SLACK_MESSAGE=":white_check_mark: Updated ${{ inputs.environment }} to \`${{ inputs.tag }}\` on ${{ inputs.project }}. - ${{ inputs.url }} - SHA: \`${{ inputs.commit-sha }}\`" + SLACK_MESSAGE=":white_check_mark: Updated $environment to \`$3\` on $project. + $url + SHA: \`$commit_sha\`" ;; failure) - SLACK_MESSAGE=":x: Failed to update ${{ inputs.environment }} to \`${{ inputs.tag }}\` on ${{ inputs.project }}. - ${{ inputs.url }} - SHA: \`${{ inputs.commit-sha }}\` + SLACK_MESSAGE=":x: Failed to update $environment to \`$3\` on $project. + $url + SHA: \`$commit_sha\` Please retry or contact @devops team." ;; cancelled) - SLACK_MESSAGE=":hand: Cancelled update of ${{ inputs.environment }} to \`${{ inputs.tag }}\` on ${{ inputs.project }}. - ${{ inputs.url }} - SHA: \`${{ inputs.commit-sha }}\`" + SLACK_MESSAGE=":hand: Cancelled update of $environment to \`$3\` on $project. + $url + SHA: \`$commit_sha\`" ;; esac + } + + if [[ ${{ inputs.db_migration_detected }} == true && ${{ inputs.tag }} != main && ${{ inputs.tag }} != rc && ${{ inputs.tag }} != hotfix-rc ]]; then + slack_message_fn "${{ inputs.event }}" "${{ inputs.environment }}" "${{ inputs.tag }}" "${{ inputs.project }}" "${{ inputs.url }}" "${{ inputs.commit-sha }}" + SLACK_MESSAGE="$SLACK_MESSAGE + :red_siren: This branch has new database migration changes." + else + slack_message_fn "${{ inputs.event }}" "${{ inputs.environment }}" "${{ inputs.tag }}" "${{ inputs.project }}" "${{ inputs.url }}" "${{ inputs.commit-sha }}" fi echo 'slack_message<> $GITHUB_OUTPUT