forked from adoptium/mirror-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skaraMirror.sh
executable file
·319 lines (276 loc) · 11.3 KB
/
skaraMirror.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -euxo pipefail
# Make sure we're in a valid dir as a workspace
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
mkdir -p $SCRIPT_DIR/workspace
WORKSPACE=$SCRIPT_DIR/workspace
PATCHES=$SCRIPT_DIR/patches/
# TODO generalise this for the non adoptium build farm case
function checkArgs() {
if [ "$1" -lt 1 ]; then
echo Usage: "$0" '[jdk8u|jdk17u]'
echo "Skara Repo supplied should match a repository in https://github.com/openjdk/"
echo "For example, to mirror https://github.com/openjdk/jdk17u"
echo "e.g. $0 jdk17u"
exit 1
fi
}
function cloneGitHubRepo() {
cd "$WORKSPACE" || exit 1
# If we don't have a $GITHUB_REPO locally then clone it from adoptium/$GITHUB_REPO.git
if [ ! -d "$GITHUB_REPO" ] ; then
git clone "$REPO" "$GITHUB_REPO" || exit 1
fi
}
function addSkaralUpstream() {
cd "$WORKSPACE/$GITHUB_REPO" || exit 1
git fetch --all
if ! git checkout -f "$BRANCH" ; then
if ! git rev-parse -q --verify "origin/$BRANCH" ; then
git checkout -b "$BRANCH" || exit 1
else
git checkout -b "$BRANCH" origin/"$BRANCH" || exit 1
fi
else
git reset --hard origin/"$BRANCH" || echo "Not resetting as no upstream exists"
fi
# shellcheck disable=SC2143
if [ -z "$(git remote -v | grep 'skara')" ] ; then
echo "Initial setup of $SKARA_REPO"
git remote add skara "$SKARA_REPO"
fi
}
function performMergeFromSkaraIntoGit() {
git fetch skara --tags
git rebase "skara/$BRANCH" "$BRANCH"
git push -u origin "$BRANCH" || exit 1
git push origin "$BRANCH" --tags || exit 1
}
# Merge master(New tagged builds only) into release branch as we build
# off release branch at the Adoptium JDK Build farm for release builds
# release branch contains patches that Adoptium JDK has beyond upstream OpenJDK tagged builds
function performMergeIntoReleaseFromMaster() {
# Abort existing merge
git merge --abort || true
git reset --hard || true
# Fetch latest and get latest master build tag
git fetch --all --tags
buildTags=$(git tag --merged origin/"$BRANCH" $TAG_SEARCH || exit 1)
sortedBuildTags=$(echo "$buildTags" | eval "$jdk_sort_tags_cmd" || exit 1)
if ! git checkout -f release ; then
if ! git rev-parse -q --verify "origin/release" ; then
currentBuildTag=$(echo "$buildTags" | eval "$jdk_sort_tags_cmd" | tail -1 || exit 1)
git checkout -b release $currentBuildTag || exit 1
else
git checkout -b release origin/release || exit 1
fi
else
git reset --hard origin/release || echo "Not resetting as no upstream exists"
fi
# Apply our patches to release branch
echo "Checking if patches need to be applied for $GITHUB_REPO"
# actions ignore branch patch is for > jdk11u
if [[ "$GITHUB_REPO" != "jdk8u" ]] && [[ "$GITHUB_REPO" != "aarch32-port-jdk8u" ]] && [[ "$GITHUB_REPO" != "jdk11u" ]]; then
# check to see if patch has already been applied
if ! grep -q "\\- dev" "$WORKSPACE/$GITHUB_REPO/.github/workflows/main.yml"; then
echo "Applying actions-ignore-branches.patch"
git am $PATCHES/actions-ignore-branches.patch
fi
fi
# Find the latest release tag that is not in releaseTagExcludeList
releaseTags=$(git tag --merged release $TAG_SEARCH || exit 1)
sortedReleaseTags=$(echo "$releaseTags" | eval "$jdk_sort_tags_cmd" || exit 1)
currentReleaseTag=""
for tag in $sortedReleaseTags; do
skipThisTag=false
# Check if tag is in the releaseTagExcludeList, if so it can't be the current tag
if [ -n "${releaseTagExcludeList-}" ] ; then
for skipTag in $releaseTagExcludeList; do
if [ "x$tag" == "x$skipTag" ]; then
echo "Skipping excluded tag $tag from current list"
skipThisTag=true
fi
done
fi
if [[ "$tag" == *\-b00 ]] || [[ "$tag" == *\+0 ]]; then
echo "Skipping fork point tag $tag from current list"
skipThisTag=true
fi
if [[ "$skipThisTag" == false ]]; then
currentReleaseTag="$tag"
fi
done
echo "Current release build tag: $currentReleaseTag"
# Merge any new builds since current release build tag
foundCurrentReleaseTag=false
newAdoptTags=""
for tag in $sortedBuildTags; do
if [[ "$foundCurrentReleaseTag" == false ]]; then
if [ "x$tag" == "x$currentReleaseTag" ]; then
foundCurrentReleaseTag=true
fi
else
mergeTag=true
# Check if tag is in the releaseTagExcludeList, if so do not bring it into the release branch
# and do not create an _adopt tag
if [ -n "${releaseTagExcludeList-}" ] ; then
for skipTag in $releaseTagExcludeList; do
if [ "x$tag" == "x$skipTag" ]; then
mergeTag=false
echo "Skipping merge of excluded tag $tag"
fi
done
fi
if [[ "$tag" == *\-b00 ]] || [[ "$tag" == *\+0 ]]; then
echo "Skipping merge of fork point tag $tag"
mergeTag=false
fi
if [[ "$mergeTag" == true ]]; then
echo "Merging build tag $tag into release branch"
git merge -m"Merging $tag into release" $tag || exit 1
git tag -a "${tag}_adopt" -m "Merged $tag into release" || exit 1
newAdoptTags="${newAdoptTags} ${tag}_adopt"
fi
fi
done
if git rev-parse -q --verify "origin/release" ; then
git --no-pager log --oneline origin/release..release
fi
# Find the latest and previous release tags that is not in releaseTagExcludeList
releaseTags=$(git tag --merged release $TAG_SEARCH || exit 1)
sortedReleaseTags=$(echo "$releaseTags" | eval "$jdk_sort_tags_cmd" || exit 1)
prevReleaseTag=""
currentReleaseTag=""
for tag in $sortedReleaseTags; do
skipThisTag=false
# Check if tag is in the releaseTagExcludeList, if so it can't be the current tag
if [ -n "${releaseTagExcludeList-}" ] ; then
for skipTag in $releaseTagExcludeList; do
if [ "x$tag" == "x$skipTag" ]; then
echo "Skipping excluded tag $tag from current list"
skipThisTag=true
fi
done
fi
if [[ "$tag" == *\-b00 ]] || [[ "$tag" == *\+0 ]]; then
echo "Skipping fork point tag $tag from current list"
skipThisTag=true
fi
if [[ "$skipThisTag" == false ]]; then
prevReleaseTag="${currentReleaseTag}"
currentReleaseTag="$tag"
fi
done
echo "New release build tag: $currentReleaseTag"
git push --tags origin release || exit 1
# Check if the last two build tags are the same commit, and ensure we have tagged both _adopt tags
if [ "x$prevReleaseTag" != "x" ]; then
prevCommit=$(git rev-list -n 1 ${prevReleaseTag})
currentCommit=$(git rev-list -n 1 ${currentReleaseTag})
if [ "${prevCommit}" == "${currentCommit}" ] ; then
echo "Current build tag commit is same as previous build tag commit: ${prevReleaseTag} == ${currentReleaseTag}"
prevReleaseAdoptTag="${prevReleaseTag}_adopt"
currentReleaseAdoptTag="${currentReleaseTag}_adopt"
if [ "$(git tag -l "$prevReleaseAdoptTag")" != "" ]; then
if [ "$(git tag -l "$currentReleaseAdoptTag")" == "" ]; then
echo "Tagging new current release tag ${currentReleaseAdoptTag} which is same commit as the previous ${prevReleaseAdoptTag}"
git tag -a "${currentReleaseAdoptTag}" -m "Merged ${currentReleaseTag} into release" || exit 1
newAdoptTags="${newAdoptTags} ${currentReleaseAdoptTag}"
fi
fi
fi
fi
# Ensure all new _adopt tags are pushed in case no new commits were pushed, eg.multiple tags on same commit
for tag in $newAdoptTags; do
echo "Pushing new tag: ${tag}"
git push origin ${tag} || exit 1
done
}
# Merge master(HEAD) into dev as we build off dev at the Adoptium JDK Build farm for Nightlies
# dev contains patches that Adoptium JDK has beyond upstream OpenJDK
function performMergeIntoDevFromMaster() {
# Abort existing merge
git merge --abort || true
git reset --hard || true
# Fetch latest and get latest master build tag
git fetch --all --tags
if ! git checkout -f dev ; then
if ! git rev-parse -q --verify "origin/dev" ; then
git checkout -b dev || exit 1
else
git checkout -b dev origin/dev || exit 1
fi
else
git reset --hard origin/dev || echo "Not resetting as no upstream exists"
fi
devTags=$(git tag --merged dev $TAG_SEARCH || exit 1)
currentDevTag=$(echo "$devTags" | eval "$jdk_sort_tags_cmd" | tail -1 || exit 1)
echo "Current dev build tag: $currentDevTag"
# Merge master "HEAD"
echo "Merging origin/$BRANCH HEAD into dev branch"
git merge -m"Merging origin/$BRANCH HEAD into dev" origin/"$BRANCH" || exit 1
# Merge latest patches from "release" branch
git merge -m"Merging latest patches from release branch" origin/release || exit 1
if git rev-parse -q --verify "origin/dev" ; then
git --no-pager log --oneline origin/dev..dev
fi
devTags=$(git tag --merged dev $TAG_SEARCH || exit 1)
currentDevTag=$(echo "$devTags" | eval "$jdk_sort_tags_cmd" | tail -1 || exit 1)
echo "New dev build tag: $currentDevTag"
git push origin dev || exit 1
}
checkArgs $#
SKARA_REPO="https://github.com/openjdk/$1"
GITHUB_REPO="$1"
REPO=${2:-"git@github.com:adoptium/$GITHUB_REPO"}
BRANCH="master"
GITHUB_REPO_REMOVE_aarch32=${GITHUB_REPO#"aarch32"}
VERSION=${GITHUB_REPO_REMOVE_aarch32//[!0-9]/}
# Regex expands aarch32-jdk8u as 328
if [[ "${VERSION}" == "8" ]]; then
TAG_SEARCH="jdk${VERSION}*-*"
else
TAG_SEARCH="jdk-${VERSION}*+*"
fi
# JDK11+ tag sorting:
# We use sort and tail to choose the latest tag in case more than one refers the same commit.
# Versions tags are formatted: jdk-V[.W[.X[.P]]]+B; with V, W, X, P, B being numeric.
# Transform "-" to "." in tag so we can sort as: "jdk.V[.W[.X[.P]]]+B"
# Transform "+" to ".0.+" during the sort so that .P (patch) is defaulted to "0" for those
# that don't have one, and the trailing "." to terminate the 5th field from the +
# First, sort on build number (B):
jdk11plus_tag_sort1="sort -t+ -k2,2n"
# Second, (stable) sort on (V), (W), (X), (P): P(Patch) is optional and defaulted to "0"
jdk11plus_tag_sort2="sort -t. -k2,2n -k3,3n -k4,4n -k5,5n"
jdk11plus_sort_tags_cmd="grep -v _adopt | sed 's/jdk-/jdk./g' | sed 's/+/.0.0+/g' | $jdk11plus_tag_sort1 | nl -n rz | $jdk11plus_tag_sort2 | sed 's/\.0\.0+/+/g' | cut -f2- | sed 's/jdk./jdk-/g'"
# JDK8 tag sorting:
# We use sort and tail to choose the latest tag in case more than one refers the same commit.
# Versions tags are formatted: jdkVu[.W]-bB; with V, W, B being numeric.
# First, sort on build number (B):
jdk8_tag_sort1="sort -tb -k2,2n"
# Second, (stable) sort on (V), (W)
jdk8_tag_sort2="sort -tu -k2,2n"
jdk8_sort_tags_cmd="grep -v _adopt | $jdk8_tag_sort1 | nl -n rz | $jdk8_tag_sort2 | cut -f2-"
if [[ "${VERSION}" == "8" ]]; then
jdk_sort_tags_cmd="${jdk8_sort_tags_cmd}"
else
jdk_sort_tags_cmd="${jdk11plus_sort_tags_cmd}"
fi
cloneGitHubRepo
addSkaralUpstream
performMergeFromSkaraIntoGit
performMergeIntoReleaseFromMaster
performMergeIntoDevFromMaster