-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·145 lines (121 loc) · 4.23 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh
set -e
tmpFilePath=changelog.tmp
changelogPath=${INPUT_CHANGELOG_FILE}
urlPrefix=${INPUT_TICKET_URL_PREFIX}
version=${INPUT_VERSION}
fullDate=$(date +"%F")
branchName=${INPUT_BRANCH_NAME}
change_md=""
if [ -z ${version} ]; then
echo "Adding changes to Unreleased Section."
echo "branchName passed in value: ${branchName}"
if [ -z ${branchName} ]; then
# This is a workaround for a security fix in git that prevents a user from accessing an untrusted workspace
git config --global --add safe.directory /github/workspace
branchName=$(git rev-parse --abbrev-ref HEAD)
fi
echo "Using branch name: ${branchName}"
ticket=$(echo "${branchName}" | awk -F'/' '{print($1)}')
changeType=$(echo "${branchName}" | awk -F'/' '{print($2)}')
message=$(echo "${branchName}" | awk -F'/' '{print($3)}' | tr '_' ' ')
if echo "${changeType}" | grep -Eq '(Added|Changed|Deprecated|Removed|Fixed|Security)'; then
echo "ChangeType: ${changeType}"
else
echo "Invalid ChangeType: ${changeType}"
exit 1
fi
if [ -z "${message}" ]; then
echo "Could not parse branchName: ${branchName}"
exit 1
fi
ticketLine=""
if [ -n ${urlPrefix} ]; then
case "${ticket}" in
NOJIRA|NoJira|HOTFIX|Hotfix) ;;
*) ticketLine="- [${ticket}](${urlPrefix}${ticket})"
esac
else
ticketLine="- ${ticket}"
fi
# Check if file exists, if not, create blank template.
if [ -e "${changelogPath}" ]; then
echo "File exists, appending..."
else
echo "# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
This changelog was generated by [action-update-changelog](https://github.com/KrogerWalt/action-update-changelog/).
## [Unreleased]
## End of Changelog
" > "$changelogPath"
fi
change_md="### ${changeType}
- Merged \"${message}\"
### Referenced Issues
${ticketLine}"
changeTypeFound="false"
inUnreleasedSection="false"
seekingReferencedIssuesSection="false"
# Read template and insert data to create temp file
while read data; do
if [ "${data}" = "## [Unreleased]" ]; then
echo "Entering Unreleased section..."
export inUnreleasedSection="true"
echo "$data" >> "${tmpFilePath}"
elif [ "${data:0:4}" = "## [" ]; then
if [ "${inUnreleasedSection}" = "true" ]; then
echo "Leaving Unreleased section..."
fi
export inUnreleasedSection="false"
echo "$data" >> "${tmpFilePath}"
elif [ "${inUnreleasedSection}" = "true" ] && [ "${data}" = "### ${changeType}" ]; then
echo "Adding data to ${changeType} section..."
export changeTypeFound="true"
export seekingReferencedIssuesSection="true"
echo "${data}
- Merged \"${message}\"" >> ${tmpFilePath}
elif [ "${seekingReferencedIssuesSection}" = "true" ] && [ "${data}" = "### Referenced Issues" ]; then
export seekingReferencedIssuesSection="false"
echo "Adding referenced issue..."
echo "${data}
${ticketLine}" >> "${tmpFilePath}"
else
echo "$data" >> "${tmpFilePath}"
fi
done < "${changelogPath}"
# Check to see if change was inserted.
if [ "${changeTypeFound}" = "false" ]; then
echo "Did not find a ${changeType} section..."
rm "${tmpFilePath}"
while read data; do
if [ "${data}" = "## [Unreleased]" ]; then
echo "Adding ${changeType} section to Unreleased..."
echo "${data}
${change_md}" >> "${tmpFilePath}"
else
echo "$data" >> "${tmpFilePath}"
fi
done < "${changelogPath}"
fi
echo "Modifications complete."
# End of Unreleased Code Path
else
echo "Moving Unreleased changes to Version ${version}"
change_md="## [${version}] - ${fullDate}"
#Read template and insert data to create temp file
while read data; do
if [ "${data}" = "## [Unreleased]" ]; then
echo "${data}
${change_md}" >> ${tmpFilePath}
else
echo "$data" >> ${tmpFilePath}
fi
done < "${changelogPath}"
fi
# delete orig and rename temp file.
echo "Replacing original file with temp file."
rm "${changelogPath}"
mv "${tmpFilePath}" "${changelogPath}"
echo "change_md=${change_md}" >> $GITHUB_OUTPUT