MON-490 handle update when version already exists
This commit is contained in:
parent
5f11270aa9
commit
2f693dc4a4
@ -4,6 +4,11 @@ set -euo pipefail
|
||||
source "$(dirname $0)/utils.sh"
|
||||
goto_root
|
||||
|
||||
## Check parameters and environment variables
|
||||
# PARAMETER: The next version to release (i.e. v3.0.0)
|
||||
# JIRA_API_TOKEN: the user api token to login jira
|
||||
# JIRA_LOGIN: the user email to login on jira
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Target tag is required as parameter"
|
||||
exit 1
|
||||
@ -31,30 +36,38 @@ SAVEIFS=$IFS
|
||||
IFS=$(echo -en "\n\b")
|
||||
TMP=$(mktemp -d)
|
||||
|
||||
# Clean when exit
|
||||
err() {
|
||||
rm -fr ${TMP}
|
||||
IFS=$SAVEIFS
|
||||
}
|
||||
trap 'err $LINENO' ERR TERM EXIT INT
|
||||
|
||||
# Create the go-jira template with issue, status and summary as CSV
|
||||
mkdir -p ${HOME}/.jira.d/templates
|
||||
cat > ${HOME}/.jira.d/templates/changelog <<EOF
|
||||
{{ .fields.issuetype.name }};{{ .key }};{{if .fields.status -}}{{ .fields.status.name }}{{end -}};{{ .fields.summary }}
|
||||
EOF
|
||||
|
||||
# List all issues in commits from previous tag
|
||||
TMP_ISSUES=$TMP/issues.txt
|
||||
for commit in $(git log $(git describe --tags --abbrev=0)..HEAD --oneline); do
|
||||
[[ $commit =~ ^.*(MON-[0-9]+).*$ ]] && echo "${BASH_REMATCH[1]}"
|
||||
done | sort -u > $TMP_ISSUES
|
||||
|
||||
TMP_CHANGELOG=${TMP}/changelog.md
|
||||
# init changelog for next version
|
||||
echo -e "\n# $TAG_TARGET ($(LANG=eng date +"%B %d, %Y"))" >> $TMP_CHANGELOG
|
||||
for issue in $(cat $TMP_ISSUES); do
|
||||
# retrieve jira information from go-jira template
|
||||
IFS=';' read -r type issue status summary < <(jira --endpoint=${JIRA_ENDPOINT} --login=${JIRA_LOGIN} view $issue --template=changelog)
|
||||
# Ignore if issue is not in required status
|
||||
if [[ "$JIRA_STATUS" == *"$status"* ]]; then
|
||||
# add line for type only once
|
||||
if ! grep -q "^## $type" $TMP_CHANGELOG; then
|
||||
echo -e "\n## $type\n" >> $TMP_CHANGELOG
|
||||
fi
|
||||
# add jira issue line to changelog
|
||||
echo "* [[$issue](${JIRA_ENDPOINT}/browse/${issue})] - $summary" >> $TMP_CHANGELOG
|
||||
else
|
||||
echo "Ignore $issue with status \"$status\" not in [$JIRA_STATUS] ($summary)"
|
||||
@ -62,8 +75,17 @@ for issue in $(cat $TMP_ISSUES); do
|
||||
done
|
||||
|
||||
cat $TMP_CHANGELOG
|
||||
read -p 'Add this to CHANGELOG.md ? (y/n): ' -r answer
|
||||
# Ask for confirmation to update changelog
|
||||
read -p 'Update CHANGELOG.md with this ? (y/n): ' -r answer
|
||||
if [[ "$answer" == "y" ]]; then
|
||||
echo -e "$(cat $TMP_CHANGELOG)\n$(cat CHANGELOG.md)" > CHANGELOG.md
|
||||
separator='\n'
|
||||
# Remove target tag changelog if already exist
|
||||
if grep -q $TAG_TARGET CHANGELOG.md; then
|
||||
prev_tag=$(grep '^# v' CHANGELOG.md | sed -n 2p)
|
||||
sed -i "/${prev_tag}/,\$!d" CHANGELOG.md
|
||||
separator="${separator}\n"
|
||||
fi
|
||||
# Add target tag changelog to final changelog
|
||||
echo -e "$(cat $TMP_CHANGELOG)${separator}$(cat CHANGELOG.md)" > CHANGELOG.md
|
||||
fi
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user