-
Notifications
You must be signed in to change notification settings - Fork 4
/
zanata-pom-set-version
executable file
·114 lines (101 loc) · 3.25 KB
/
zanata-pom-set-version
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
#!/bin/bash
### NAME
### zanata-pom-set-version - Set pom version
###
### SYNOPSIS
### zanata-pom-set-version [options] <Version> <Projects>
###
### DESCRIPTION
### This script
### 1. sets the version in pom
### 2. then commit with corresponding message.
### 3. tag the commit if version is not SNAPSHOT
###
### Note that this script assume you are already in correct directory and
### checkout correct branch.
###
### ARGUMENTS
### Version
### Version like 4.4.0 or 4.5.0-SNAPSHOT
### Note that final version and SNAPSHOT will have different commit message
###
### Projects
### Comma-delimited list of specified reactor projects, it will be passed as
### parameter of mvn -pl
export LC_ALL=C
set -eu
ScriptDir=$(dirname $(readlink -q -f $0))
FunctionScriptFile=${ScriptDir}/zanata-functions
source "$FunctionScriptFile"
trap exit_print_error EXIT
RepoName=$(repo_name_get)
ArtifactId=$(get_artifact_id $RepoName)
## chooses projects whose versions should be changed
## eg: -pl build-tools,parent
ParentProject=$(get_artifact_var_value $ArtifactId MAVEN_PARENT_PROJECT )
## Tag message refers to release notes if release-notes is not empty
ReleaseNotesFile=$(get_artifact_var_value $ArtifactId RELEASE_NOTES_FILE )
## default variables
Projects=$ParentProject
###
### OPTIONS
while getopts "h" opt;do
case $opt in
### -h: Show detail help
h )
zanata_script_help $0
exit ${EXIT_OK}
;;
* )
failed ${EXIT_FATAL_INVALID_OPTIONS} "$opt"
;;
esac
done
shift $((OPTIND-1))
if [[ $# -lt 1 ]]; then
zanata_script_help_short $0
exit ${EXIT_FATAL_INVALID_ARGUMENTS}
fi
Version=$1
shift
if [[ $Version =~ -SNAPSHOT$ ]]; then
SnapshotMode=1
CommitMessage="chore(version): new snapshot version ${Version}"
ScmTag="HEAD"
else
SnapshotMode=0
CommitMessage="chore(version): set version ${Version}"
ScmTag="$ArtifactId-$Version"
fi
[[ -n ${1:-} ]] && Projects="$1"
if [[ -n $Projects && $Projects != 'null' ]]; then
ProjectOpts="-pl $Projects"
elif [[ -n $ParentProject ]]; then
ProjectOpts="-pl $Projects"
else
ProjectOpts=""
fi
run_command sed -i -e 's|<tag>.*</tag>|<tag>'$ScmTag'</tag>|' $(find . -name pom.xml | xargs )
run_command ./mvnw ${MAVEN_COMMON_OPTIONS:-} $ProjectOpts versions:set -DnewVersion=$Version -DprocessAllModules
run_command git commit -a -m "$CommitMessage"
if [[ $SnapshotMode -eq 0 ]]; then
## Tag for non Snapshot version
if [[ -n $ReleaseNotesFile ]]; then
## Only refer release-notes if Repo has one
ReleaseNoteVersion=${Version%%-*}
if [[ $Version = $ReleaseNoteVersion ]]; then
## Final version
## Anchor in Read the doc. version 4.4.0 become 440
ReadTheDocAnchorVersion=$(sed -e 's/\.//g' <<<$ReleaseNoteVersion)
TagMessage="http://docs.zanata.org/en/release/release-notes/#$ReadTheDocAnchorVersion"
## Tag before release, so the git description looks correct
else
## Alpha, Beta, RC
TagMessage="tag ${ScmTag}"
fi
else
## No release notes
TagMessage="tag ${ScmTag}"
fi
run_command git tag -a -m "$TagMessage" $ScmTag
fi