-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease.sh
executable file
·74 lines (57 loc) · 2.38 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
#!/bin/bash
updateReadme() {
releaseVersion=$1
NEW_README_FILE=README.md.new
OLD_README_FILE=README.md
MAVEN_VERSION_REGEXP="(.*<version>)(.*)(</version>)"
GRADLE_VERSION_REGEXP="(.*compile group: \"com.github.fabriziocucci\", name:\"yacl4j-core\", version: \")(.*)(\")"
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ $line =~ $MAVEN_VERSION_REGEXP ]]; then
mavenVersionPrefix=${BASH_REMATCH[1]}
mavenVersionSuffix=${BASH_REMATCH[3]}
echo "$mavenVersionPrefix$releaseVersion$mavenVersionSuffix" >> $NEW_README_FILE
elif [[ $line =~ $GRADLE_VERSION_REGEXP ]]; then
gradleVersionPrefix=${BASH_REMATCH[1]}
gradleVersionSuffix=${BASH_REMATCH[3]}
echo "$gradleVersionPrefix$releaseVersion$gradleVersionSuffix" >> $NEW_README_FILE
else
echo "$line" >> $NEW_README_FILE
fi
done < README.md
rm $OLD_README_FILE
mv $NEW_README_FILE $OLD_README_FILE
}
updateChangelog() {
releaseVersion=$1
previousVersion=
NEW_CHANGELOG_FILE=CHANGELOG.md.new
OLD_CHANGELOG_FILE=CHANGELOG.md
UNRELEASED_REGEXP="(\#\# \[Unreleased\]\(https://github.com/fabriziocucci/yacl4j/compare/yacl4j-)(.*)(...HEAD\))"
touch $NEW_CHANGELOG_FILE
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ $line =~ $UNRELEASED_REGEXP ]]; then
unreleasedPrefix=${BASH_REMATCH[1]}
previousVersion=${BASH_REMATCH[2]}
unreleasedSuffix=${BASH_REMATCH[3]}
echo "$unreleasedPrefix$releaseVersion$unreleasedSuffix" >> $NEW_CHANGELOG_FILE
echo "" >> $NEW_CHANGELOG_FILE
echo "## [$releaseVersion](https://github.com/fabriziocucci/yacl4j/compare/yacl4j-$previousVersion...yacl4j-$releaseVersion)" >> $NEW_CHANGELOG_FILE
else
echo "$line" >> $NEW_CHANGELOG_FILE
fi
done < CHANGELOG.md
rm $OLD_CHANGELOG_FILE
mv $NEW_CHANGELOG_FILE $OLD_CHANGELOG_FILE
}
USAGE="No release version specified. Please try again like this: $0 <releaseVersion>"
if [ "$#" == "0" ]; then
echo "$USAGE"
exit 1
fi
releaseVersion=$1
updateReadme $releaseVersion && \
updateChangelog $releaseVersion && \
git add README.md CHANGELOG.md && \
git commit -m "Updated README.md and CHANGELOG.md before release" && \
git push && \
./mvnw --batch-mode release:clean release:prepare release:perform -DreleaseVersion=${releaseVersion} -P release