Skip to content

Commit

Permalink
chore(teams): update script to send a release message on teams channel (
Browse files Browse the repository at this point in the history
#272)

DSY-2732
  • Loading branch information
Davi Mattos authored May 3, 2022
1 parent 3c8c291 commit 06c8f8d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
66 changes: 41 additions & 25 deletions scripts/message_teams.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,58 @@
#!/bin/bash

# create new file to edit
# create new message teams template file
cp ./scripts/message_teams.json ./scripts/updated_message_teams.json

# get last version at package
LAST_VERSION=$(cat ./scripts/updated_package_version.json \
| grep last_version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[", ]//g')

# get and update version at message
NEW_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g')
| sed 's/[", ]//g')

if [ "$NEW_VERSION" != "$LAST_VERSION" ]; then
echo 'New version found! updating message...'

# create a version template file
cp ./scripts/package_version.json ./scripts/updated_package_version.json

echo "New version: $NEW_VERSION"
# update the last version
sed -i '' "s/LASTVERSIONVALUE/$NEW_VERSION/g" ./scripts/updated_package_version.json
# update the new version in teams message
sed -i '' "s/VERSIONVALUE/$NEW_VERSION/g" ./scripts/updated_message_teams.json

sed -i '' "s/VERSIONVALUE/$NEW_VERSION/g" ./scripts/updated_message_teams.json
releaselinecontent='https://github.com/natura-cosmeticos/natds-rn/compare/'
major=`echo $NEW_VERSION | cut -d. -f1`
minor=`echo $NEW_VERSION | cut -d. -f2`
patch=`echo $NEW_VERSION | cut -d. -f3`
rgxversion="$major\.$minor\.$patch" # regex for new version

releaselinecontent='https://github.com/natura-cosmeticos/natds-rn/compare/'
major=`echo $NEW_VERSION | cut -d. -f1`
minor=`echo $NEW_VERSION | cut -d. -f2`
patch=`echo $NEW_VERSION | cut -d. -f3`
rgxversion="$major\.$minor\.$patch" # regex for new version
# save last version output to file
awk 's{print $0 > "./scripts/message_release.txt"}; $0~v {print $0 > "./scripts/message_release.txt"; s=1; next}; (!($0~v) && $0~l) {s=0};' RS= v=$rgxversion l=$releaselinecontent CHANGELOG.md
# erase last line of file
sed -i '' -e '$ d' ./scripts/message_release.txt

# save last version output to file
awk 's{print $0 > "./scripts/message_release.txt"}; $0~v {print $0 > "./scripts/message_release.txt"; s=1; next}; (!($0~v) && $0~l) {s=0};' RS= v=$rgxversion l=$releaselinecontent CHANGELOG.md
# erase last line of file
sed -i '' -e '$ d' ./scripts/message_release.txt
# write release message with line breaks
awk '{printf "%s\\\n ",$0 > "./scripts/message_text.txt"} END {print ""}' ./scripts/message_release.txt

# write release message with line breaks
awk '{printf "%s\\\n ",$0 > "./scripts/message_text.txt"} END {print ""}' ./scripts/message_release.txt
# update release message at json
CHANGELOG_UPDATES=`cat ./scripts/message_text.txt`
sed -i '' "s|CHANGELOGMESSAGE|$CHANGELOG_UPDATES|g" ./scripts/updated_message_teams.json

# update release message at json
CHANGELOG_UPDATES=`cat ./scripts/message_text.txt`
sed -i '' "s|CHANGELOGMESSAGE|$CHANGELOG_UPDATES|g" ./scripts/updated_message_teams.json
# send message
message=`cat ./scripts/updated_message_teams.json`
curl -H 'Content-Type: application/json' -d "$message" "$TEAMS_RELEASE_WEBHOOK"

# send message
message=`cat ./scripts/updated_message_teams.json`
curl -H 'Content-Type: application/json' -d "$message" "$TEAMS_RELEASE_WEBHOOK"
# remove helper files
rm ./scripts/updated_message_teams.json
rm ./scripts/message_release.txt
rm ./scripts/message_text.txt

# remove helper files
rm ./scripts/updated_message_teams.json
rm ./scripts/message_release.txt
rm ./scripts/message_text.txt
fi
3 changes: 3 additions & 0 deletions scripts/package_version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"last_version": "LASTVERSIONVALUE"
}
3 changes: 3 additions & 0 deletions scripts/updated_package_version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"last_version": "7.26.7"
}

0 comments on commit 06c8f8d

Please sign in to comment.