-
Notifications
You must be signed in to change notification settings - Fork 51
/
retag-for-jenkins
executable file
·38 lines (35 loc) · 1.57 KB
/
retag-for-jenkins
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
#!/bin/bash
set -euo pipefail
if [ $# -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 TAG"
echo "Rebases the free-standing git tag <TAG> on the current branch"
echo "(make sure you don't have any uncommited local changes)"
echo "E.g., after a Jenkins build 'alpha-9999.99.99-mytest' was started based on"
echo "the scripts branch 'mybranch' and you have new changes on the branch,"
echo "check out your branch and run"
echo " $0 alpha-9999.99.99-mytest"
echo
echo "This is required when testing 'scripts' changes with Jenkins and a leaf job fails,"
echo "so that instead of restarting the whole build from the 'packages' job, you can"
echo "restart the leaf job after retagging. Note: Just starting a leaf job with your"
echo "branch as reference is not valid because it would overwrite the nightly build"
echo "artifacts!"
exit 1
fi
TAG="$1"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
git fetch --force --tags origin
BUILD_PATCH=$(git format-patch --output=/dev/stdout "${TAG}~1..${TAG}")
git checkout --recurse-submodules "${TAG}"
git reset --hard "${BRANCH}"
echo "${BUILD_PATCH}" | git am -3 || {
git checkout "${TAG}" -- sdk_container/.repo/manifests/version.txt
git add sdk_container/.repo/manifests/version.txt
git am --continue
# This does not handle submodule conflicts: It should use the one
# from the TAG (similar to version.txt) unless an explicit new
# reference was specified
} || { echo "Failed to resolve conflict, continue manually" >&2 ; exit 1 ; }
git tag -d "${TAG}"
git tag "${TAG}"
git push --force origin "${TAG}"