mirror of
https://github.com/bitwarden/android.git
synced 2026-08-09 13:44:26 -05:00
89 lines
3.6 KiB
YAML
89 lines
3.6 KiB
YAML
name: Send Slack Notification
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
commit:
|
|
description: "Commit SHA to build the test notification"
|
|
required: true
|
|
type: string
|
|
push:
|
|
branches:
|
|
- release/**/*
|
|
|
|
permissions:
|
|
contents: read
|
|
id-token: write
|
|
|
|
jobs:
|
|
send_notification:
|
|
name: Send Slack Notification
|
|
runs-on: ubuntu-24.04
|
|
# Only run on pushes that carry new commits (or a manual dispatch);
|
|
# skip bare branch-creation pushes that have no commits
|
|
if: ${{ github.event_name != 'push' || github.event.head_commit != null }}
|
|
steps:
|
|
- name: Log in to Azure
|
|
uses: bitwarden/gh-actions/azure-login@main
|
|
with:
|
|
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
|
|
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
|
|
client_id: ${{ secrets.AZURE_CLIENT_ID }}
|
|
|
|
- name: Retrieve Slack secrets
|
|
id: retrieve-slack-secrets
|
|
uses: bitwarden/gh-actions/get-keyvault-secrets@main
|
|
with:
|
|
keyvault: gh-android
|
|
secrets: "SLACK-WEBHOOK-TEAM-ENG-MOBILE,SLACK-WEBHOOK-AUTOMATIONS-TEST-CHANNEL"
|
|
|
|
- name: Log out from Azure
|
|
uses: bitwarden/gh-actions/azure-logout@main
|
|
|
|
- name: Build message
|
|
id: msg
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
EVENT_NAME: ${{ github.event_name }}
|
|
INPUT_COMMIT: ${{ github.event.inputs.commit }}
|
|
REPO: ${{ github.repository }}
|
|
REPO_NAME: ${{ github.event.repository.name }}
|
|
COMMIT_URL: ${{ github.event.head_commit.url }}
|
|
COMMIT_SHA: ${{ github.event.head_commit.id }}
|
|
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
|
|
COMMIT_AUTHOR: ${{ github.event.head_commit.author.name }}
|
|
REPO_URL: ${{ github.event.repository.html_url }}
|
|
run: |
|
|
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
|
|
COMMIT_SHA="$INPUT_COMMIT"
|
|
REPO_URL="${GITHUB_SERVER_URL}/${REPO}"
|
|
COMMIT_URL="${REPO_URL}/commit/${COMMIT_SHA}"
|
|
COMMIT_JSON="$(gh api "repos/${REPO}/commits/${COMMIT_SHA}")"
|
|
COMMIT_MESSAGE="$(jq -r '.commit.message' <<< "$COMMIT_JSON")"
|
|
COMMIT_AUTHOR="$(jq -r '.commit.author.name' <<< "$COMMIT_JSON")"
|
|
fi
|
|
COMMIT_SUBJECT="$(printf '%s' "$COMMIT_MESSAGE" | head -n1)"
|
|
PR_NUMBER=$(printf '%s' "$COMMIT_MESSAGE" | head -n1 | grep -oE '#[0-9]+' | tail -n1 | tr -d '#' || true)
|
|
PR_LINE=""
|
|
if [ -n "$PR_NUMBER" ]; then
|
|
PR_LINE="<${REPO_URL}/pull/${PR_NUMBER}|${REPO_NAME}#${PR_NUMBER}> *${COMMIT_SUBJECT}* by *${COMMIT_AUTHOR}*"
|
|
else
|
|
PR_LINE="*${COMMIT_SUBJECT}* by *${COMMIT_AUTHOR}*"
|
|
fi
|
|
SHORT_SHA="${COMMIT_SHA:0:8}"
|
|
COMMIT_LINE="<${COMMIT_URL}|${REPO_NAME}/${GITHUB_REF_NAME}@${SHORT_SHA}>"
|
|
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
|
|
CC_LINE="[slack users]"
|
|
else
|
|
CC_LINE="<!subteam^S0BG74ZATUM> <@U06538MSPJP>"
|
|
fi
|
|
echo "text=:cherry-pick: ${PR_LINE}\n:bricks: commit: ${COMMIT_LINE}\n:bitwarden-love: ${CC_LINE}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Send slack notification
|
|
uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
|
|
with:
|
|
webhook: ${{ github.event_name == 'workflow_dispatch' && steps.retrieve-slack-secrets.outputs.SLACK-WEBHOOK-AUTOMATIONS-TEST-CHANNEL || steps.retrieve-slack-secrets.outputs.SLACK-WEBHOOK-TEAM-ENG-MOBILE }}
|
|
webhook-type: incoming-webhook
|
|
payload: |
|
|
text: "${{ steps.msg.outputs.text }}"
|