Skip to content

ci: automatically send a slack message for new releases #1356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
46 changes: 46 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ orbs:
android: circleci/android@2.5.0
advanced-checkout: vsco/advanced-checkout@1.1.0
node: circleci/node@5.2.0
slack: circleci/slack@5.1.1

references:
release_dependencies: &release_dependencies
Expand Down Expand Up @@ -161,6 +162,38 @@ commands:
name: Post comment on GitHub
command: ./scripts/notify-github.sh "<< parameters.data >>"

notify_slack_with_release:
steps:
- slack/notify:
channel: C8PDY2Q8H
event: pass
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":react: React Native `v$(./scripts/releases/get_sdk_version.sh)` is released by <@$(./scripts/releases/get_job_approver.sh)> 🚀"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "$(./scripts/releases/get_release_notes.sh)"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "cc: <@U5697F4EL> @support_team <@ULDFCC09J>"
}
}
]
}

jobs:
danger:
executor:
Expand Down Expand Up @@ -494,6 +527,13 @@ jobs:
- notify_github:
data: "$(jq -Rcs '{ body: . }' scripts/snapshot-comment.md)"

release_slack_notification:
docker:
- image: cimg/base:current
steps:
- advanced-checkout/shallow-checkout
- notify_slack_with_release

workflows:
publish:
jobs:
Expand Down Expand Up @@ -582,6 +622,12 @@ workflows:
android_package: injazat
api_endpoint: st001013mec1.instabug.com

- release_slack_notification:
requires:
- publish
- publish_new_namespace
context: slack-app

# Dream11 tests
- hold_test_dream11:
type: approval
Expand Down
9 changes: 9 additions & 0 deletions scripts/releases/changelog_to_slack_formatter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
input=$(cat)

input=$(sed -E \
-e 's/\[([^]]+)\]\(([^)]+)\)/<\2|\1>/g' \
-e 's/^#{1,6}[[:space:]]*([^[:space:]].*)$/\*\1\*/' \
-e 's/^- /• /' <<< "$input")

echo "$input"
17 changes: 17 additions & 0 deletions scripts/releases/get_job_approver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
jobsJson=$(curl -s -X GET "https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/job" --header "Circle-Token: $CIRCLE_TOKEN")

job=$(jq '.items[] | select(.name == "hold_release_slack_notification")' <<< "$jobsJson")

approver_id=$(jq '.approved_by' <<< "$job")

approver_id=$(tr -d '"' <<< "$approver_id")

user=$(curl -s -X GET "https://circleci.com/api/v2/user/$approver_id" --header "Circle-Token: $CIRCLE_TOKEN")

username=$(jq '.login' <<< "$user")

username=$(tr -d '"' <<< "$username")

slack_id=$(./scripts/releases/get_slack_id_from_username.sh "$username")

echo "$slack_id"
22 changes: 22 additions & 0 deletions scripts/releases/get_release_notes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
latest_release=""
capturing=false

while IFS= read -r line; do
if [[ "$line" == "## ["* ]]; then
if $capturing; then
break
fi
fi

if [[ "$line" == "### "* ]]; then
capturing=true
fi

if $capturing; then
line=$(./scripts/releases/changelog_to_slack_formatter.sh <<< "$line")
latest_release+="$line\n"
fi
done < CHANGELOG.md

echo "$latest_release"
5 changes: 5 additions & 0 deletions scripts/releases/get_sdk_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sdk_version=$(grep -i 'version' package.json) #"version": "xx.x.x+x",
sdk_version=$(cut -f2 -d' ' <<< $sdk_version | tr -d '" ,') #xx.x.x+x,
sdk_version=$(cut -f1 -d'+' <<< $sdk_version) #xx.x.x

echo "$sdk_version"
24 changes: 24 additions & 0 deletions scripts/releases/get_slack_id_from_username.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
github_username=$1

case $github_username in
'mzelzoghbi')
sid='U5697F4EL'
;;
'AndrewAminInstabug')
sid='U06JVRNMKE1'
;;
'ahmedAlaaInstabug')
sid='U06AE2G1161'
;;
'kholood-ea')
sid='U06SU2QR280'
;;
'AyaMahmoud148')
sid='U07GZSURC8K'
;;
'MoKamall')
sid='U06JHDS3JJK'
;;
*)
esac
echo "$sid"