-
Notifications
You must be signed in to change notification settings - Fork 146
/
release.sh
executable file
·181 lines (140 loc) · 4.84 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env bash
set -e
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Ex: 0.0.0
OLD_VERSION=$1
# Ex: 0.1.0
NEW_VERSION=$2
# Ex: 0.2.0
NEXT_VERSION=$3
ECLIPSE_CS_DIR="/tmp/eclipse-cs"
CONTRIBUTION_DIR="/tmp/checkstyle.contribution"
GITHUB_PROJECT="sevntu-checkstyle/sevntu.checkstyle"
# https://github.com/settings/tokens
# SEVNTU_GITHUB_TOKEN=""
if [[ -z "$OLD_VERSION" || -z "$NEW_VERSION" || -z "$NEXT_VERSION" ]]
then
echo "Old and New and Next version needs to be specified in the arguments"
exit 1
fi
if [[ -z "$SEVNTU_GITHUB_TOKEN" ]]
then
echo "Github token needs to be specified in the script or as an "
echo "environment variable 'SEVNTU_GITHUB_TOKEN'"
exit 1
fi
# require git, xmlstarlet (xml parsing) and jq (json parsing)
if ! [ -x "$(command -v git)" ]; then
echo "Error: git is not installed"
exit 1
fi
if ! [ -x "$(command -v xmlstarlet)" ]; then
echo "Error: xmlstarlet is not installed"
exit 1
fi
if ! [ -x "$(command -v jq)" ]; then
echo "Error: jq is not installed"
exit 1
fi
# fetch latest origin from server
echo "Resetting repository to origin"
git fetch origin
git reset --hard HEAD
git clean -f -d
git checkout origin/master
cd sevntu-checks
ECLIPSE_CS_VERSION=$(mvn -e --no-transfer-progress -q -Dexec.executable='echo' \
-Dexec.args='${checkstyle.eclipse-cs.version}' --non-recursive \
org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
cd ..
# bring in and run release notes builder
echo "Cloning and installing ReleaseNotes builder"
if [ ! -d $CONTRIBUTION_DIR ]; then
mkdir $CONTRIBUTION_DIR
fi
cd $CONTRIBUTION_DIR
if [ ! -d "$CONTRIBUTION_DIR/contribution/.git" ]; then
git clone https://github.com/checkstyle/contribution.git
cd contribution
else
cd contribution
git fetch origin
fi
git reset --hard HEAD
git clean -f -d
git checkout origin/master
cd releasenotes-builder
mvn -e --no-transfer-progress package -DskipTests
cd target
java -jar releasenotes-builder-1.0-all.jar -localRepoPath $CURRENT_DIR \
-remoteRepoPath $GITHUB_PROJECT -startRef $OLD_VERSION -releaseNumber $NEW_VERSION \
-githubAuthToken $SEVNTU_GITHUB_TOKEN -generateXdoc -xdocTemplate \
$CURRENT_DIR/sevntu_xdoc_freemarker.template
# bring in eclipse-cs version in-use
echo "Cloning and installing Eclipse CS version $ECLIPSE_CS_VERSION"
if [ ! -d $ECLIPSE_CS_DIR ]; then
mkdir $ECLIPSE_CS_DIR
fi
cd $ECLIPSE_CS_DIR
if [ ! -d "$ECLIPSE_CS_DIR/eclipse-cs/.git" ]; then
git clone https://github.com/checkstyle/eclipse-cs.git
cd eclipse-cs
else
cd eclipse-cs
git fetch origin
fi
git reset --hard HEAD
git clean -f -d
git checkout tags/$ECLIPSE_CS_VERSION.0
mvn -e --no-transfer-progress clean install
# update versions in all files
echo "Bumping all versions from $OLD_VERSION to $NEW_VERSION"
cd $CURRENT_DIR
./pom-version-bump.sh $OLD_VERSION $NEW_VERSION
# test and prepare for deployment
echo "Prepare for deployment"
$CURRENT_DIR/deploy-all.sh
cd $CURRENT_DIR
echo ""
read -p "Press enter to continue before committing"
# commit version bump
echo "Committing version bump"
git add .
git commit -m "config: version bump to $NEW_VERSION"
CURRENT_COMMIT=$(git rev-parse HEAD)
git push origin $CURRENT_COMMIT:master
# create new release tag
echo "Pushing new tag $NEW_VERSION"
git tag -a $NEW_VERSION -m "release $NEW_VERSION"
git push --tags
# deploy gh-pages
echo "Updating gh-pages"
$CURRENT_DIR/deploy.sh --gh-pages $NEW_VERSION \
$CONTRIBUTION_DIR/contribution/releasenotes-builder/target/xdoc.xml
# deploy to maven central
echo "Deploying to maven central"
$CURRENT_DIR/deploy.sh --maven-central
# dropped support for gh-pages/sevntu-checkstyle-default-configuration.xml
# retrieve old milestone number
# https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
OLD_MILESTONE_NUMBER=$(curl --fail-with-body --silent --show-error --fail \
-H "Authorization: token $SEVNTU_GITHUB_TOKEN" \
https://api.github.com/repos/$GITHUB_PROJECT/milestones?state=open \
| jq '.[0].number')
echo ""
read -p "Press enter to continue before closing and creating new milestone"
# close old milestone
# https://developer.github.com/v3/issues/milestones/#update-a-milestone
echo "Closing old milestone $OLD_MILESTONE_NUMBER"
curl --fail-with-body --silent --show-error --fail -H "Authorization: token $SEVNTU_GITHUB_TOKEN" \
-d "{ \"state\": \"closed\" }" \
-X PATCH https://api.github.com/repos/$GITHUB_PROJECT/milestones/$OLD_MILESTONE_NUMBER
# create new milestone
# https://developer.github.com/v3/issues/milestones/#create-a-milestone
echo "Creating new milestone for $NEXT_VERSION"
curl --fail-with-body --silent --show-error --fail -H "Authorization: token $SEVNTU_GITHUB_TOKEN" \
-d "{ \"title\": \"$NEXT_VERSION\", \
\"state\": \"open\", \
\"description\": \"\" }" \
-X POST https://api.github.com/repos/$GITHUB_PROJECT/milestones
echo "Done"