-
Notifications
You must be signed in to change notification settings - Fork 3
/
release.sh
executable file
·79 lines (62 loc) · 2.34 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
shopt -s nocasematch
# you can add variables like this to test locally. Just run ./release.sh. Note that to run on MAC, you must install bash 5.x.
# Then, to run the script you must do: /usr/local/bin/bash ./release.sh
# TAG="1.2.3"
TEAMS_WEBHOOK_URL="https://prod-34.westeurope.logic.azure.com:443/workflows/31b656992447483d9697ba3ab594f23c/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=OdGkZRZvMUJjiy7Ex6K2CCgeG5LUsYXTxXo-7CKAJTw"
# Would like to use this, but can't get it to work in curl command
#export COMMON_CURL_HEADER=`printf -- '-H "PRIVATE-TOKEN:${GIT_API_TOKEN}" -H "Accept:application/json" -H "Content-Type:application/json"'`
export H_ACCEPT="Accept:application/json"
export H_CONTENT="Content-Type:application/json"
export H_TOKEN="PRIVATE-TOKEN:${GIT_API_TOKEN}"
# validate all of the required variables
check_required_variables() {
echo "Validating the required environment variables..."
[ -z "${TEAMS_WEBHOOK_URL}" ] && echo "TEAMS_WEBHOOK_URL variable not set" && exit 1
[ -z "${TAG}" ] && echo "TAG variable not set" && exit 1
[ -z "${SDK}" ] && echo "SDK variable not set" && exit 1
pat='v[0-9]+\.[0-9]+\.[0-9]'
if [[ ! ${TAG} =~ $pat ]]; then
echo "TAG variable must be of the form vX.X.X"
exit 1
fi
return 0
}
get_sdk_version()
{
# pull out the SDK version from go.mod
ver=$(grep 'github.com/Axway/agent-sdk v' ./go.mod)
# Set space as the delimiter
IFS=' '
# Read the split words into an array
read -a strarr <<< $ver
export SDK=${strarr[1]}
}
post_to_teams() {
# don't post if this is a pre-release tag
pat='[0-9]+\.[0-9]+\.[0-9]+-'
if [[ ${TAG} =~ $pat ]]; then
echo "This is an interim release... skipping the post to Teams"
return 0
fi
JSON="{
\"info\": \"${1}\"
}"
curl -v ${TEAMS_WEBHOOK_URL} -H 'Content-Type: application/json' -d "${JSON}" &> /dev/null
}
main() {
# validate required variables
get_sdk_version
check_required_variables
if [ $? -eq 1 ]; then
echo "No release info being generated."
exit 1
fi
# gather stats
releaseStats="- Mulesoft agents version: ${TAG}\n"
releaseStats+="- SDK version: ${SDK}\n"
echo -e "Full Release Info:\n"${releaseStats}
post_to_teams "${releaseStats}"
exit 0
}
main $@