From a7c8065451c50209914001d80c2ebcdeec3ceb99 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Tue, 19 Nov 2024 15:21:01 +0100 Subject: [PATCH] Flav/imrpove new deployment (#8747) * Add Slack notify composite action * Add .mailmap * Leverage mail map to mention last author --- .github/actions/slack-notify/action.yml | 103 ++++++++++++++++++++++++ .github/workflows/deploy-viz.yml | 23 ++++++ .mailmap | 35 ++++++++ 3 files changed, 161 insertions(+) create mode 100644 .github/actions/slack-notify/action.yml create mode 100644 .mailmap diff --git a/.github/actions/slack-notify/action.yml b/.github/actions/slack-notify/action.yml new file mode 100644 index 000000000000..6f094de20640 --- /dev/null +++ b/.github/actions/slack-notify/action.yml @@ -0,0 +1,103 @@ +name: 'Slack Notification' +description: 'Send deployment notifications to Slack' + +inputs: + step: + description: 'Deployment step (start/build_success/failure)' + required: true + component: + description: 'Component being deployed' + required: true + image_tag: + description: 'Image tag being deployed' + required: true + channel: + description: 'Slack channel' + required: true + thread_ts: + description: 'Slack thread timestamp' + required: false + slack_token: + description: 'Slack bot token' + required: true + +outputs: + thread_ts: + description: "Slack thread timestamp from the initial message" + value: ${{ steps.start_notification.outputs.ts }} + +runs: + using: "composite" + steps: + - name: Get author email + if: inputs.step == 'start' + id: author + shell: bash + run: | + # Get last commit author name and email + AUTHOR_NAME=$(git log -1 --format='%an') + AUTHOR_EMAIL=$(git log -1 --format='%ae') + + if ! CANONICAL=$(git check-mailmap "$AUTHOR_NAME <$AUTHOR_EMAIL>" 2>/dev/null); then + echo "email=$AUTHOR_EMAIL" >> $GITHUB_OUTPUT + echo "name=$AUTHOR_NAME" >> $GITHUB_OUTPUT + exit 0 + fi + + # Extract email and name from canonical form + CANONICAL_EMAIL=$(echo "$CANONICAL" | grep -o '<.*>' | tr -d '<>') + CANONICAL_NAME=$(echo "$CANONICAL" | sed 's/ <.*>//') + + echo "email=$CANONICAL_EMAIL" >> $GITHUB_OUTPUT + echo "name=$CANONICAL_NAME" >> $GITHUB_OUTPUT + + - name: Lookup by email + if: inputs.step == 'start' + id: email + uses: slackapi/slack-github-action@v2.0.0 + with: + errors: true + method: users.lookupByEmail + token: ${{ inputs.slack_token }} + payload: | + email: "${{ steps.author.outputs.email }}" + + - name: Get Slack user ID + if: inputs.step == 'start' && steps.email.outputs.ok == 'true' + id: slack_user + shell: bash + run: | + RESPONSE='${{ steps.email.outputs.response }}' + if ! SLACK_ID=$(echo "$RESPONSE" | jq -r '.user.id'); then + echo "Failed to extract Slack user ID" >&2 + exit 0 + fi + echo "id=$SLACK_ID" >> $GITHUB_OUTPUT + + - name: Notify Build And Deploy Start + if: inputs.step == 'start' + id: start_notification + uses: slackapi/slack-github-action@v2.0.0 + with: + method: chat.postMessage + token: ${{ inputs.slack_token }} + payload: | + channel: ${{ inputs.channel }} + text: | + 🚀 Starting deployment of ${{ inputs.component }} `${{ inputs.image_tag }}` + • Commit: <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ inputs.image_tag }}> + • Workflow: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View build> + • Author: ${{ steps.slack_user.outputs.id != '' && format('<@{0}>', steps.slack_user.outputs.id) || format('`{0}`', steps.author.outputs.name) }} + + - name: Notify Deploy Failure + if: inputs.step == 'failure' + uses: slackapi/slack-github-action@v2.0.0 + with: + method: chat.postMessage + token: ${{ inputs.slack_token }} + payload: | + channel: ${{ inputs.channel }} + thread_ts: "${{ inputs.thread_ts }}" + text: | + ❌ Build pipeline failed + • Check logs: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View details> \ No newline at end of file diff --git a/.github/workflows/deploy-viz.yml b/.github/workflows/deploy-viz.yml index 9d0a0f4eae55..32e20d8b167c 100644 --- a/.github/workflows/deploy-viz.yml +++ b/.github/workflows/deploy-viz.yml @@ -24,6 +24,16 @@ jobs: id: short_sha run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - name: Notify Build And Deploy Start + id: build_message + uses: ./.github/actions/slack-notify + with: + step: "start" + component: "viz" + image_tag: ${{ steps.short_sha.outputs.short_sha }} + channel: ${{ secrets.SLACK_CHANNEL_ID }} + slack_token: ${{ secrets.SLACK_BOT_TOKEN }} + - name: "Authenticate with Google Cloud" uses: "google-github-actions/auth@v1" with: @@ -64,5 +74,18 @@ jobs: regions: 'us-central1', component: 'viz', image_tag: '${{ steps.short_sha.outputs.short_sha }}' + slack_thread_ts: "${{ steps.build_message.outputs.thread_ts }}", + slack_channel: '${{ secrets.SLACK_CHANNEL_ID }}' } }); + + - name: Notify Failure + if: failure() + uses: ./.github/actions/slack-notify + with: + step: "failure" + component: "viz" + image_tag: ${{ steps.short_sha.outputs.short_sha }} + channel: ${{ secrets.SLACK_CHANNEL_ID }} + slack_token: ${{ secrets.SLACK_BOT_TOKEN }} + thread_ts: "${{ steps.build_message.outputs.thread_ts }}" diff --git a/.mailmap b/.mailmap new file mode 100644 index 000000000000..29c0dcfdb38b --- /dev/null +++ b/.mailmap @@ -0,0 +1,35 @@ +Alban Dumouilla +Alban Dumouilla +Alexandre Pinot +Alexandre Pinot <32997243+pinotalexandre@users.noreply.github.com> +Aubin Tchoi +Aubin Tchoi <60398825+aubin-tchoi@users.noreply.github.com> +Aubin Tchoi +Daphné Popin +Daphné Popin +Daphné Popin +Edouard Wautier +Edouard Wautier <4435185+Duncid@users.noreply.github.com> +Flavien David +Flavien David +Gabriel Hubert +Gabriel Hubert +Henry Fontanier +Henry Fontanier +Jules Belveze +Jules Belveze <32683010+JulesBelveze@users.noreply.github.com> +Jules Belveze +Lucas Massemin +Lucas Massemin +Pauline Pham +Pauline Pham <33726902+Yutcam@users.noreply.github.com> +Philippe Rolet +Philippe Rolet +Sebastien Flory +Sebastien Flory +Stanislas Polu +Stanislas Polu +Thibault Martin +Thibault Martin <168569391+thib-martin@users.noreply.github.com> +Thomas Draier +Thomas Draier