Skip to content

Commit

Permalink
Flav/imrpove new deployment (#8747)
Browse files Browse the repository at this point in the history
* Add Slack notify composite action

* Add .mailmap

* Leverage mail map to mention last author
  • Loading branch information
flvndvd authored Nov 19, 2024
1 parent 56cba90 commit a7c8065
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
103 changes: 103 additions & 0 deletions .github/actions/slack-notify/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
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/[email protected]
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>
23 changes: 23 additions & 0 deletions .github/workflows/deploy-viz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}"
35 changes: 35 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Alban Dumouilla <[email protected]>
Alban Dumouilla <[email protected]> <[email protected]>
Alexandre Pinot <[email protected]>
Alexandre Pinot <[email protected]> <[email protected]>
Aubin Tchoi <[email protected]>
Aubin Tchoi <[email protected]> <[email protected]>
Aubin Tchoi <[email protected]> <[email protected]>
Daphné Popin <[email protected]>
Daphné Popin <[email protected]> <[email protected]>
Daphné Popin <[email protected]> <[email protected]>
Edouard Wautier <[email protected]>
Edouard Wautier <[email protected]> <[email protected]>
Flavien David <[email protected]>
Flavien David <[email protected]> <[email protected]>
Gabriel Hubert <[email protected]>
Gabriel Hubert <[email protected]> <[email protected]>
Henry Fontanier <[email protected]>
Henry Fontanier <[email protected]> <[email protected]>
Jules Belveze <[email protected]>
Jules Belveze <[email protected]> <[email protected]>
Jules Belveze <[email protected]> <[email protected]>
Lucas Massemin <[email protected]>
Lucas Massemin <[email protected]> <[email protected]>
Pauline Pham <[email protected]>
Pauline Pham <[email protected]> <[email protected]>
Philippe Rolet <[email protected]>
Philippe Rolet <[email protected]> <[email protected]>
Sebastien Flory <[email protected]>
Sebastien Flory <[email protected]> <[email protected]>
Stanislas Polu <[email protected]>
Stanislas Polu <[email protected]> <[email protected]>
Thibault Martin <[email protected]>
Thibault Martin <[email protected]> <[email protected]>
Thomas Draier <[email protected]>
Thomas Draier <[email protected]> <[email protected]>

0 comments on commit a7c8065

Please sign in to comment.