Skip to content

Commit

Permalink
[ DEVOPS-1733] - Slack Report Test Case Test (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeebru authored Feb 16, 2024
1 parent 6613980 commit 1592595
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 68 deletions.
39 changes: 15 additions & 24 deletions .github/workflows/test-report-deployment-status-to-slack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }}
72 changes: 28 additions & 44 deletions report-deployment-status-to-slack/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF' >> $GITHUB_OUTPUT
Expand Down

0 comments on commit 1592595

Please sign in to comment.