-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathupversionAndRelease.sh
executable file
·163 lines (131 loc) · 5.42 KB
/
upversionAndRelease.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
#!/bin/sh
repoOwnerAndName=redhat-developer/intellij-rsp
curBranch=`git rev-parse --abbrev-ref HEAD`
ghtoken=`cat ~/.keys/gh_access_token`
argsPassed=$#
echo "args: " $argsPassed
if [ "$argsPassed" -eq 1 ]; then
debug=1
echo "YOU ARE IN DEBUG MODE. Changes will NOT be pushed upstream"
else
echo "The script is live. All changes will be pushed, deployed, etc. Live."
debug=0
fi
read -p "Press enter to continue"
apiStatus=`git status -s | wc -l`
if [ $apiStatus -ne 0 ]; then
echo "This repository has changes and we won't be able to auto upversion. Please commit or stash your changes and try again"
exit 1
fi
oldver=`cat gradle.properties | grep "projectVersion=" | cut -f 2 -d "="`
charLen=`echo $oldver | grep -i snapshot | wc -c`
if [[ $charLen -eq "0" ]]
then
echo "Current version is not a snapshot. Are you SURE it's time to upversion??"
echo "You will have to do this one manually"
exit 1
fi
echo ""
echo "These are the commits for the release"
commits=`git lg | grep -n -m 1 "Upversion to " |sed 's/\([0-9]*\).*/\1/' | tail -n 1`
commitMsgs=`git log --color --pretty=format:'%h - %s' --abbrev-commit | head -n $commits`
echo "$commitMsgs"
read -p "Press enter to continue"
cleanVer=`echo $oldver | sed 's/-SNAPSHOT//g'`
finalVer=$cleanVer.Final
cat gradle.properties | sed "s/$oldver/$finalVer/g" > gradle.properties2;
mv gradle.properties2 gradle.properties
commits=`git lg | grep -n -m 1 "Upversion to " |sed 's/\([0-9]*\).*/\1/' | tail -n 1`
fixesString=`git log --color --graph --pretty=format:'%s' --abbrev-commit | head -n $commits | grep -i "fixes #" | cut -c 1-2 --complement | sed 's/#\([0-9]*\)/\<a href="https:\/\/github.com\/redhat-developer\/intellij-rsp\/issues\/\1"\>#\1\<\/a\>/g' | awk '{ print " <li>" $0 "</li>";}'`
changelogString=" <h3>$finalVer</h3>\n <ul>\n$fixesString\n</ul>\n"
cat src/main/resources/META-INF/plugin.xml | head -n 11 > tmpPluginXml
printf "$changelogString" >> tmpPluginXml
cat src/main/resources/META-INF/plugin.xml | tail -n +12 >> tmpPluginXml
mv tmpPluginXml src/main/resources/META-INF/plugin.xml
echo "Committing and pushing to master"
git commit -a -m "Upversion to $finalVer for release" --signoff
if [ "$debug" -eq 0 ]; then
git push origin $curBranch
else
echo git push origin $curBranch
fi
echo "Need to run a build"
read -p "Press enter to continue"
./gradlew buildPlugin
echo "Did it succeed?"
read -p "Press enter to continue"
echo ""
echo "Tagging and pushing to origin"
git tag v$finalVer
if [ "$debug" -eq 0 ]; then
git push origin v$finalVer
else
echo git push origin v$finalVer
fi
echo ""
echo "It's time to go kick a real build"
read -p "Press enter to continue"
echo "Now build again with release flag"
read -p "Press enter to continue"
echo "Time to do github release"
read -p "Press enter to continue"
echo "Making a release on github for $finalVer"
git log --color --pretty=format:'%s' --abbrev-commit | head -n $commits | awk '{ print " zzz " $0;}' | awk '{printf "%s\\\\n", $0}' | sed 's/"/\\"/g' > tmp1.txt
cat tmp1.txt | sed 's/zzz/\*/g' > tmp2.txt
commitMsgsClean="$(<tmp2.txt)"
rm tmp1.txt
rm tmp2.txt
createReleasePayload="{\"tag_name\":\"v$finalVer\",\"target_commitish\":\"$curBranch\",\"name\":\"$finalVer\",\"body\":\"Release of $finalVer:\n\n"$commitMsgsClean"\",\"draft\":false,\"prerelease\":false,\"generate_release_notes\":false}"
if [ "$debug" -eq 0 ]; then
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ghtoken"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$repoOwnerAndName/releases \
-d "$createReleasePayload" | tee createReleaseResponse.json
else
echo curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ghtoken"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$repoOwnerAndName/releases \
-d "$createReleasePayload"
fi
echo "Please go verify the release looks correct. We will add the asset next"
read -p "Press enter to continue"
assetUrl=`cat createReleaseResponse.json | grep assets_url | cut -c 1-17 --complement | rev | cut -c3- | rev | sed 's/api.github.com/uploads.github.com/g'`
rm createReleaseResponse.json
zipFileName=`ls -t -1 build/distributions/ | grep ".zip$" | head -n 1`
zipFileNameSafe=`echo $zipFileName | sed 's/ /_/g'`
zipLoc=build/distributions/$zipFileName
echo "Running command to add artifact to release: "
echo curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ghtoken"\
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$assetUrl?name=$zipFileNameSafe" \
--data-binary "@$zipLoc"
if [ "$debug" -eq 0 ]; then
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ghtoken"\
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$assetUrl?name=$zipFileNameSafe" \
--data-binary "@$zipLoc"
fi
echo ""
echo "Please go verify the release looks correct and the distribution was added correctly."
read -p "Press enter to continue"
newLastSegment=`echo $finalVer | cut -f 3 -d "." | awk '{ print $0 + 1;}' | bc`
newverPrefix=`echo $finalVer | cut -f 1,2 -d "."`
newver=$newverPrefix.$newLastSegment-SNAPSHOT
cat gradle.properties | sed "s/$finalVer/$newver/g" > gradle.properties2;
mv gradle.properties2 gradle.properties
git commit -a -m "Move to $newver" --signoff
git push origin master