-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·87 lines (76 loc) · 2.52 KB
/
entrypoint.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
80
81
82
83
84
85
86
87
#!/bin/bash
# turn on ERREXIT so that the script exits immediately if
# an error is encountered
set -e
# check for the environment variable GITHUB_EVENT_PATH
# if this variable is not zero length, then the entrypoint script is being
# run as a GitHub Action.
#
# GITHUB_EVENT_PATH contiains the path to the JSON data
# for the event that triggered the WorkFlow
#
# set EVENT_DATA_PATH = $GITHUB_EVENT_PATH
#
if [ -n "$GITHUB_EVENT_PATH" ];
then
EVENT_PATH=$GITHUB_EVENT_PATH
#
# If the entrypoint script is not being run as an Action, check for
# a local file with sample data for testing.
#
# set EVENT_DATA_PATH = the local file with sample data
# set LOCAL_TEST = true so a release is not attempted
#
elif [ -f ./sample_push_event.json ];
then
EVENT_PATH='./sample_push_event.json'
LOCAL_TEST=true
#
# If no file is available for processing, exit with an error
#
else
echo "No JSON data to process! :("
exit 1
fi
echo "-----------------------------------------------------------"
echo "Processing $EVENT_PATH"
echo "-----------------------------------------------------------"
env
jq . < $EVENT_PATH
# check for the keyword in the event's commit messages
# use JQ to filter out the messages
# grep for the keyword in the messages found by JQ
# ignore case with `grep -i` and keep things quiet with `-q`
if jq '.commits[].message, .head_commit.message' < $EVENT_PATH | grep -i -q "$*";
then
VERSION=$(date +%F.%s)
DATA="$(printf '{"tag_name":"v%s",' $VERSION)"
DATA="${DATA} $(printf '"target_commitish":"master",')"
DATA="${DATA} $(printf '"name":"v%s",' $VERSION)"
DATA="${DATA} $(printf '"body":"Automated release based on keyword: %s",' "$*")"
DATA="${DATA} $(printf '"draft":false, "prerelease":false}')"
#DATA=$(printf '{"tag_name":"v%s","target_commitish":"master","name":"v%s","body":"Automated release based on keyword: %s","draft":false,"prerelease":false}' "$VERSION" "$VERSION" "$*")
URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/releases?access_token=${GITHUB_TOKEN}"
CMD="echo $DATA | http POST $URL | jq ."
echo "Keyword = $*"
echo
echo "Version = $VERSION"
echo
echo "Data = $DATA"
echo
echo "URL = $URL"
echo
echo "CMD = $CMD"
if [[ "${LOCAL_TEST}" == *"true"* ]];
then
echo
echo "##"
echo "## [TESTING] No release was created."
echo "##"
echo
else
echo $DATA | http POST $URL | jq .
fi
else
echo "Not creating a release because The following keyword was not present: $*"
fi