Skip to content
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

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

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
24e281c
ci: add a job to send release notes based on changelog to slack
MoKamall Mar 2, 2025
f8ebddd
ci: add a workflow to test the slack message job on test slack channel
MoKamall Mar 2, 2025
77484d8
ci: change job image from macos to base
MoKamall Mar 4, 2025
9fd3312
fix: correctly indented brackets in config.yml file
MoKamall Mar 5, 2025
2d7ed13
fix: split notification job into two jobs; approval, and notification
MoKamall Mar 5, 2025
4e2b72d
fix: add missing slack orb
MoKamall Mar 5, 2025
6560e32
fix: add checkout step before notification command
MoKamall Mar 5, 2025
0fdeb5d
fix: correct case-sensitive naming for .sh script
MoKamall Mar 5, 2025
0c74b84
fix: grant correct run permissions to all scripts in .scripts/*
MoKamall Mar 5, 2025
1ec3dcd
fix: change curl command format, change jq selector name to match cur…
MoKamall Mar 5, 2025
628b019
fix: retrieve workflow ID dynamically from circleci
MoKamall Mar 5, 2025
c305b35
ci: add debugging prints in get_job_approver.sh
MoKamall Mar 5, 2025
8a3a583
ci: add more debugging statements
MoKamall Mar 5, 2025
21e9de3
ci: change curl command format for retrieving user
MoKamall Mar 6, 2025
174c0d2
chore: test get_release_notes script alone
MoKamall Mar 6, 2025
18a0bcf
chore: remove comments from message block
MoKamall Mar 6, 2025
16d38eb
chore: test get_sdk_version script alone
MoKamall Mar 6, 2025
80f7ee2
fix: add another block to the message body
MoKamall Mar 6, 2025
5c7c935
chore: test get_job_approver script alone
MoKamall Mar 6, 2025
fa720ff
ci: disable verbose logging for curl commands
MoKamall Mar 6, 2025
571759f
chore: add some clean-up logic to json outputs
MoKamall Mar 6, 2025
6fc314c
ci: change slack job environment to macos
MoKamall Mar 6, 2025
0e4581b
ci: add install jq to job
MoKamall Mar 6, 2025
62ec228
chore: enable debug mode for slack job
MoKamall Mar 6, 2025
a58b0a1
chore: remove all inner echo statements and switch to here-string (<<…
MoKamall Mar 6, 2025
5cf8b87
chore: change slack job environment back to default, test get_release…
MoKamall Mar 6, 2025
5149eae
fix: add a shebang on top of the changelog_to_slack_formatter script
MoKamall Mar 6, 2025
587ca72
chore: enable debug mode for slack/notify, add shebang on top of get_…
MoKamall Mar 6, 2025
db5e650
chore: directly format message inside get_release_notes
MoKamall Mar 6, 2025
d91110a
fix: format message in seperate script again, and output correct slac…
MoKamall Mar 6, 2025
5dd7637
fix: remove angular brackets from release notes body
MoKamall Mar 6, 2025
0b7f3aa
fix: show correct sdk version
MoKamall Mar 9, 2025
2bde506
chore: add mentions section
MoKamall Mar 9, 2025
74d358b
ci: change channel id to planning_releases, send message on successfu…
MoKamall Mar 9, 2025
f690c32
chore: remove commented code from shell scripts
MoKamall Mar 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ orbs:
flutter: circleci/[email protected]
node: circleci/[email protected]
advanced-checkout: vsco/[email protected]
slack: circleci/[email protected]

commands:
setup_flutter:
Expand Down Expand Up @@ -103,6 +104,37 @@ commands:
- run:
name: Build Pigeons
command: dart run build_runner build --delete-conflicting-outputs
notify_slack_with_release:
steps:
- slack/notify:
channel: C8PDY2Q8H
event: pass
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":flutter: Flutter `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:
Expand Down Expand Up @@ -278,6 +310,13 @@ jobs:
working_directory: project
command: Escape flutter publish

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

workflows:
version: 2
build-test-and-approval-deploy:
Expand Down Expand Up @@ -324,4 +363,8 @@ workflows:
- hold_release
filters:
branches:
only: master
only: master
- release_slack_notification:
requires:
- release
context: slack-app
Empty file modified scripts/pigeon.sh
100644 → 100755
Empty file.
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' pubspec.yaml) #version: xx.x.x+x
sdk_version=$(cut -f2 -d' ' <<< $sdk_version) #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"