Rework creating tags & branches from release files
[releng.git] / jjb / releng / releng-release-tagging.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018 The Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 set -e -o pipefail
11
12 GIT_URL=${GIT_URL:-https://gerrit.opnfv.org/gerrit}
13 STREAM=${STREAM:-'nostream'}
14 RELEASE_FILES=$(git diff HEAD^1 --name-only -- "releases/$STREAM")
15
16 echo "--> Verifying $RELEASE_FILES."
17 for release_file in $RELEASE_FILES; do
18
19     # Verify tag for each repo exist and are attached to commits on stable-branch
20     while read -r repo tag ref
21     do
22       echo "--> Cloning $repo"
23       if [ ! -d $repo ]; then
24           git clone $GIT_URL/$repo.git $repo
25       fi
26       pushd $repo &> /dev/null
27
28       echo "--> Checking for tag: $tag"
29       if ! (git tag -l | grep $tag &> /dev/null); then
30           echo "$tag does not exist"
31           TAG_EXISTS=false
32       else
33           git cat-file commit $tag
34           TAG_EXISTS=true
35       fi
36
37       echo "--> Checking if $ref is on stable/$STREAM"
38       if ! (git branch -a --contains $ref | grep "stable/$STREAM"); then
39           echo "--> ERROR: $ref for $repo is not on stable/$STREAM!"
40           # If the tag exists but is on the wrong ref, there's nothing
41           # we can do. But if the tag neither exists nor is on the
42           # correct branch we need to fail the verification.
43           if [ $TAG_EXISTS = false ]; then
44               exit 1
45           fi
46       else
47           if [[ $TAG_EXISTS = false && "$JOB_NAME" =~ "merge" ]]; then
48               # If the tag doesn't exist and we're in a merge job,
49               # everything has been verified up to this point and we
50               # are ready to create the tag.
51               git config --global user.name "jenkins-ci"
52               git config --global user.email "jenkins-opnfv-ci@opnfv.org"
53               echo "--> Creating $tag tag for $repo at $ref"
54               git tag -am "$tag" $tag $ref
55               echo "--> Pushing tag"
56               git push origin $tag
57           else
58               # For non-merge jobs just output the ref info.
59               git show -s --format="%h %s %d" $ref
60           fi
61       fi
62
63       popd &> /dev/null
64       echo "--> Done verifing $repo"
65     done < <(python releases/scripts/repos.py -f $release_file)
66 done