i18n: Upgrade translations from crowdin (a80a6511). (vpn-settings)
[ProtonMail-WebClient.git] / packages / pass / scripts / slack-notify.sh
blob6e84285bb11ee1be44461a8d08985f6017968662
1 #!/usr/bin/env bash
2 # Usage: ./slack-notify.sh {title} ({description}:{job_id})...
4 # Determine the current state based on whether we are triggered
5 # from a tag, commit, or manually for testing purposes. If there
6 # is no CI_COMMIT_TAG, then use the latest commit in the pipeline.
7 CURRENT_STATE=${CI_COMMIT_TAG:-${CI_COMMIT_SHORT_SHA:-$(git rev-parse --short HEAD)}}
9 # Notification header
10 BLOCKS="[
12 \"type\": \"header\",
13 \"text\": {
14 \"type\": \"plain_text\",
15 \"emoji\": true,
16 \"text\": \":protonpass: $1 [$CURRENT_STATE]\"
20 # Notification body
21 for arg in "${@:2}"; do # Skip first {title} argument
22 IFS=':' read -r description jobid <<<"$arg"
24 # Add a section block for each job
25 BLOCKS="$BLOCKS,
27 \"type\": \"section\",
28 \"text\": {
29 \"type\": \"mrkdwn\",
30 \"text\": \"*${description}*: <${CI_PROJECT_URL}/-/jobs/${jobid}/artifacts/download|Download> (expires in 1 week)\"
33 done
35 BLOCKS="$BLOCKS]"
37 SLACK_POST_BODY=$(echo "{
38 \"channel\": \"$PASS_EXTENSION_BUILD_SLACK_CHANNEL_ID\",
39 \"blocks\": $BLOCKS
40 }" | jq -r '.')
42 curl \
43 -X POST https://slack.com/api/chat.postMessage \
44 -H "Content-type: application/json; charset=utf-8" \
45 -H "Authorization: Bearer ${SIMPLE_LOGIN_SLACK_BOT_TOKEN}" \
46 --data-raw "$SLACK_POST_BODY"