Merge "[docs] Limit git submodule recurse to depth 1"
[releng.git] / jjb / releng / releng-release-create-branch.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 -xe
11
12 # Configure the git user/email as we'll be pushing up changes
13 git config --global user.name "jenkins-ci"
14 git config --global user.email "jenkins-opnfv-ci@opnfv.org"
15
16 # Ensure we are able to generate Commit-IDs for new patchsets
17 curl -kLo .git/hooks/commit-msg https://gerrit.opnfv.org/gerrit/tools/hooks/commit-msg
18 chmod +x .git/hooks/commit-msg
19
20 # Activate virtualenv, supressing shellcheck warning
21 # shellcheck source=/dev/null
22 . $WORKSPACE/venv/bin/activate
23 pip install -r releases/scripts/requirements.txt
24
25 STREAM=${STREAM:-'nostream'}
26 RELEASE_FILES=$(git diff HEAD^1 --name-only -- "releases/$STREAM")
27
28 for release_file in $RELEASE_FILES; do
29
30     while read -r repo branch ref; do
31
32         echo "$repo" "$branch" "$ref"
33         branches="$(git ls-remote "https://gerrit.opnfv.org/gerrit/$repo.git" "refs/heads/$branch")"
34
35         if ! [ -z "$branches" ]; then
36             echo "refs/heads/$branch already exists at $ref ($branches)"
37         else
38             ssh -n -f -p 29418 gerrit.opnfv.org gerrit create-branch "$repo" "$branch" "$ref"
39         fi
40
41     done < <(python releases/scripts/repos.py -b -f "$release_file")
42
43     python releases/scripts/create_jobs.py -f $release_file
44     NEW_FILES=$(git status --porcelain --untracked=no | cut -c4-)
45     if [ -n "$NEW_FILES" ]; then
46       git add $NEW_FILES
47       git commit -sm "Create Stable Branch Jobs for $(basename $release_file .yaml)"
48       git push origin HEAD:refs/for/master
49     fi
50 done