Update Ubuntu docker image
[releng/builder.git] / jjb / autorelease / prepare-release.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2015, 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 # Script to prepare project for release.
12 #
13 # 1) Drop -SNAPSHOT from all versions
14 # 2) Create git patches (diffs of changes)
15 # 3) Create git bundles (byte exact commit objects)
16 # 4) Create tarball for distribution.
17
18 # RELEASE_TAG=Beryllium-SR1  # Example
19
20 echo "---> prepare-release.sh"
21
22 # Set release tag as $STREAM, when no release tag is passed
23 RELEASE_TAG="${RELEASE_TAG:-${STREAM^}}"
24 # Ensure that the first letter of RELEASE_TAG is uppercase.
25 RELEASE_TAG="${RELEASE_TAG^}"
26
27 # Directory to put git format-patches
28 PATCH_DIR="$WORKSPACE/archives/patches"
29 mkdir -p "$PATCH_DIR"
30
31 # Get the current submodule commit hashes.
32 echo autorelease "$(git rev-parse --verify HEAD)" "${RELEASE_TAG}" \
33     | tee -a "$PATCH_DIR/taglist.log"
34 # Disable SC2154 because we want $path to be the submodule parameter not the shell.
35 # shellcheck disable=SC2154
36 git submodule foreach "echo \$path \$(git rev-parse --verify HEAD) ${RELEASE_TAG} \
37     | tee -a $PATCH_DIR/taglist.log"
38
39 echo "$RELEASE_TAG"
40 # Remove this case statement when Carbon is no longer supported.
41 # Nitrogen onwards we do not want to use the release tag so simply need to
42 # strip xml files of -SNAPSHOT tags.
43 case "$RELEASE_TAG" in
44     Carbon*)
45         lftools version release "$RELEASE_TAG"
46         ;;
47     *)
48         find . -name "*.xml" -print0 | xargs -0 sed -i 's/-SNAPSHOT//'
49         ;;
50 esac
51 git submodule foreach "git commit -am \"Release $RELEASE_TAG\" || true"
52 git commit -am "Release $RELEASE_TAG"
53
54 modules=$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -m '//x:modules' -v '//x:module' pom.xml)
55 for module in $modules; do
56     pushd "$module" || exit
57     # TODO: Remove once stable/nitrogen is no longer supported.
58     if [ "$GERRIT_BRANCH" == "stable/nitrogen" ] && [ "$module" == "yangtools" ]; then
59         git format-patch --stdout "origin/v1.2.x" > "$PATCH_DIR/${module//\//-}.patch"
60     else
61         git format-patch --stdout "origin/$GERRIT_BRANCH" > "$PATCH_DIR/${module//\//-}.patch"
62     fi
63     git bundle create "$PATCH_DIR/${module//\//-}.bundle" "origin/master..HEAD"
64     popd || exit
65 done
66
67 tar cvzf "$WORKSPACE/archives/patches.tar.gz" -C "$WORKSPACE/archives" patches
68 rm "$PATCH_DIR"/*.bundle