From 638a3ea2014396a97b1702ec62653b176b3895ec Mon Sep 17 00:00:00 2001 From: Andy Pixley <3723676+pixman20@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:16:56 -0500 Subject: [PATCH] BRE-265-slack-commit-link (#340) * [BRE-265] Updating slack tag and commit hash to links * [BRE-265] Updating slack tag and commit hash to links * [BRE-265] Updating slack tag and commit hash to links * [BRE-265] Updating slack tag and commit hash to links * [BRE-265] Updating slack tag and commit hash to links (Updating test) * [BRE-265] Updating slack tag and commit hash to links (Updating test) --- ...test-report-deployment-status-to-slack.yml | 36 ++++++++++-------- report-deployment-status-to-slack/action.yml | 37 +++++++++++++------ 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test-report-deployment-status-to-slack.yml b/.github/workflows/test-report-deployment-status-to-slack.yml index c2bec968..6c7ce8b2 100644 --- a/.github/workflows/test-report-deployment-status-to-slack.yml +++ b/.github/workflows/test-report-deployment-status-to-slack.yml @@ -5,6 +5,10 @@ on: - "report-deployment-status-to-slack/**" - ".github/workflows/test-report-deployment-status-to-slack.yml" +env: + TEST_REPORT_PROJECT: Server + TEST_REPORT_COMMIT_SHA: "50f7fa03dbc0f18a641206ab1a92fb11a1131572" # Use a valid commit in Server (TEST_REPORT_PROJECT) to validate the links + jobs: test-report-start: name: Test Slack report @@ -15,48 +19,48 @@ jobs: - name: Start uses: ./report-deployment-status-to-slack with: - project: Server + project: $TEST_REPORT_PROJECT environment: EU-QA Cloud slack-channel: bre-alerts-test tag: test-workflow-start event: 'start' - commit-sha: ${{ github.sha }} + commit-sha: $TEST_REPORT_COMMIT_SHA url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - name: Success uses: ./report-deployment-status-to-slack with: - project: Server + project: $TEST_REPORT_PROJECT environment: US-QA Cloud slack-channel: bre-alerts-test tag: test-workflow-success event: 'success' - commit-sha: ${{ github.sha }} + commit-sha: $TEST_REPORT_COMMIT_SHA url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - name: Failure uses: ./report-deployment-status-to-slack with: - project: Server + project: $TEST_REPORT_PROJECT environment: US-QA Cloud slack-channel: bre-alerts-test tag: test-workflow-failure event: 'failure' - commit-sha: ${{ github.sha }} + commit-sha: $TEST_REPORT_COMMIT_SHA url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - name: No Changes uses: ./report-deployment-status-to-slack with: - project: Server + project: $TEST_REPORT_PROJECT environment: EU-QA Cloud slack-channel: bre-alerts-test tag: test-workflow-failure event: 'no-changes' - commit-sha: ${{ github.sha }} + commit-sha: $TEST_REPORT_COMMIT_SHA url: https://github.com/bitwarden/gh-actions/actions/runs/${{ github.run_id }} AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} @@ -69,12 +73,12 @@ jobs: - name: With DB migration true on main uses: ./report-deployment-status-to-slack with: - project: Server + project: $TEST_REPORT_PROJECT environment: EU-QA Cloud slack-channel: bre-alerts-test tag: main event: 'success' - commit-sha: ${{ github.sha }} + commit-sha: $TEST_REPORT_COMMIT_SHA 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 }} @@ -82,12 +86,12 @@ jobs: - name: With DB migration false on main uses: ./report-deployment-status-to-slack with: - project: Server + project: $TEST_REPORT_PROJECT environment: US-QA Cloud slack-channel: bre-alerts-test tag: main event: 'failure' - commit-sha: ${{ github.sha }} + commit-sha: $TEST_REPORT_COMMIT_SHA 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 }} @@ -95,12 +99,12 @@ jobs: - name: With DB migration true on test branch uses: ./report-deployment-status-to-slack with: - project: Server + project: $TEST_REPORT_PROJECT environment: EU-QA Cloud slack-channel: bre-alerts-test tag: test-branch-failure event: 'failure' - commit-sha: ${{ github.sha }} + commit-sha: $TEST_REPORT_COMMIT_SHA 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 }} @@ -108,12 +112,12 @@ jobs: - name: With DB migration false on test branch uses: ./report-deployment-status-to-slack with: - project: Server + project: $TEST_REPORT_PROJECT environment: US-QA Cloud slack-channel: bre-alerts-test tag: test-branch-success event: 'success' - commit-sha: ${{ github.sha }} + commit-sha: $TEST_REPORT_COMMIT_SHA 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 a996efb4..57567535 100644 --- a/report-deployment-status-to-slack/action.yml +++ b/report-deployment-status-to-slack/action.yml @@ -4,6 +4,10 @@ inputs: project: description: "The name of the project." required: true + project_owner: + description: "The owner/org of the project" + required: false + default: bitwarden tag: description: "The name of the branch or tag." required: true @@ -27,7 +31,7 @@ inputs: description: "Deployment event type. Possible values are start, success, or failure." required: true url: - description: "Deployment event type. Possible values are start, success, or failure." + description: "URL of the deployment action run" required: false default: ${{ github.event.deployment_status.target_url }} AZURE_KV_CI_SERVICE_PRINCIPAL: @@ -65,39 +69,50 @@ runs: local environment="${{ inputs.environment }}" local tag="${{ inputs.tag }}" local project="${{ inputs.project }}" + local project_owner="${{ inputs.project_owner }}" local url="${{ inputs.url }}" local commit_sha="${{ inputs.commit-sha }}" + # This action can be called from other repositories with external refs/shas, so use the passed in project rather than github.repository + local repository_url="${{ github.server_url }}/$project_owner/$project" + + local commit_url="$repository_url/commit/$commit_sha" + local tag_url="$repository_url/tree/$tag" + + # Slack link format: https://api.slack.com/reference/surfaces/formatting + local commit_link="<$commit_url|$commit_sha>" + local tag_link="<$tag_url|$tag>" + case $event in start) - SLACK_MESSAGE=":loading: Deploying \`$tag\` to $environment on $project. + SLACK_MESSAGE=":loading: Deploying $tag_link to $environment on $project. $url - SHA: \`$commit_sha\`" + SHA: $commit_link" ;; success) - SLACK_MESSAGE=":white_check_mark: Deployed \`$tag\` to $environment on $project. + SLACK_MESSAGE=":white_check_mark: Deployed $tag_link to $environment on $project. $url - SHA: \`$commit_sha\`" + SHA: $commit_link" ;; failure) - SLACK_MESSAGE=":x: Failed to deploy \`$tag\` to $environment on $project. + SLACK_MESSAGE=":x: Failed to deploy $tag_link to $environment on $project. $url - SHA: \`$commit_sha\` + SHA: $commit_link Please retry. If the issue persists, share this message in the #team-eng-bre channel for support." ;; cancelled) - SLACK_MESSAGE=":hand: Cancelled deploy of \`$tag\` to $environment on $project. + SLACK_MESSAGE=":hand: Cancelled deploy of $tag_link to $environment on $project. $url - SHA: \`$commit_sha\`" + SHA: $commit_link" ;; no-changes) - SLACK_MESSAGE=":heavy_minus_sign: No changes were made for \`$tag\` deployment to $environment on $project. + SLACK_MESSAGE=":heavy_minus_sign: No changes were made for $tag_link deployment to $environment on $project. $url - SHA: \`$commit_sha\`" + SHA: $commit_link" ;; esac }