f8cf9c8ea9e7206745def273694d1fec198f5ebd
[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     # Verify the release file schema
19     python releases/scripts/verify_schema.py \
20     -s releases/schema.yaml \
21     -y $release_file
22
23     # Verify tag for each repo exist and are attached to commits on stable-branch
24     while read -r repo tag ref
25     do
26       echo "--> Cloning $repo"
27       if [ ! -d $repo ]; then
28           git clone $GIT_URL/$repo.git $repo
29       fi
30       pushd $repo &> /dev/null
31
32       echo "--> Checking for tag: $tag"
33       if ! (git tag -l | grep $tag &> /dev/null); then
34           echo "$tag does not exist"
35           TAG_EXISTS=false
36       else
37           git cat-file commit $tag
38           TAG_EXISTS=true
39       fi
40
41       echo "--> Checking if $ref is on stable/$STREAM"
42       if ! (git branch -a --contains $ref | grep "stable/$STREAM"); then
43           echo "--> ERROR: $ref for $repo is not on stable/$STREAM!"
44           # If the tag exists but is on the wrong ref, there's nothing
45           # we can do. But if the tag neither exists nor is on the
46           # correct branch we need to fail the verification.
47           if [ $TAG_EXISTS = false ]; then
48               exit 1
49           fi
50       else
51           if [[ $TAG_EXISTS = false && "$JOB_NAME" =~ "merge" ]]; then
52               # If the tag doesn't exist and we're in a merge job,
53               # everything has been verified up to this point and we
54               # are ready to create the tag.
55               git config --global user.name "jenkins-ci"
56               git config --global user.email "jenkins-opnfv-ci@opnfv.org"
57               echo "--> Creating $tag tag for $repo at $ref"
58               git tag -am "$tag" $tag $ref
59               echo "--> Pushing tag"
60               git push origin $tag
61           else
62               # For non-merge jobs just output the ref info.
63               git show -s --format="%h %s %d" $ref
64           fi
65       fi
66
67       popd &> /dev/null
68       echo "--> Done verifing $repo"
69     done < <(python releases/scripts/repos.py -f $release_file)
70 done