feat(INDA-383): daily stats.
[ProtonMail-WebClient.git] / applications / storybook / scripts / changelog.sh
blobefddc2c6b9cbd6be41792eddbb0608e433a6d744
1 #!/usr/bin/env bash
2 set -eo pipefail
4 git fetch origin main:main
5 git checkout main
7 # PARENT_DIR relative to location of script of file system
8 PARENT_DIR="$(dirname "${BASH_SOURCE[0]}")"
10 cd "$PARENT_DIR"/..
12 # Notice the "." at the end
13 # We're taking the latest merge commit that affected the current directory
14 # We're skipping one of the merge commits since this script is intended to
15 # trigger on a merge into the main branch and we don't want to compare with
16 # the commit that triggered the script to run in the first place.
17 LATEST_MERGE_COMMIT="$(git log --full-history --skip 1 --merges -n 1 --pretty=format:%H .)"
19 echo "SHA of latest merge commit: $LATEST_MERGE_COMMIT"
21 DIFF="$(git diff "$LATEST_MERGE_COMMIT" HEAD CHANGELOG.md || true)"
23 if ! [[ "$DIFF" =~ ^diff ]]; then
24 echo "No new changelog diffs between latest merge commit and now"
25 exit 0
28 TEXT="$(git diff "$LATEST_MERGE_COMMIT" HEAD CHANGELOG.md | grep -E "^\+" | sed -e 's/^\+//' | tail -n +2 | node scripts/format)"
30 echo "Changelog contains new entries \n\n$TEXT"
32 curl -X POST -H 'Content-type: application/json' --data "{ \"text\": $TEXT }" "${SLACK_WEBHOOK_URL}"