CI: Add AR jobs for JDK17
[releng/builder.git] / jjb / autorelease / autorelease-gerrit-branch-lock.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2022 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 echo "---> autorelease-gerrit-branch-lock.sh"
12 # The script lock's/unlock's a Gerrit branch for code-freeze or release work
13 # or enable/disable supercommitters rights.
14
15 # Ensure we fail the job if any steps fail.
16 set -eu -o pipefail
17
18 mkdir -p "${WORKSPACE}/archives"
19
20 git clone "ssh://jenkins-releng@git.opendaylight.org:29418/All-Projects"
21
22 cd "${WORKSPACE}/All-Projects"
23 git config user.name "jenkins-releng"
24 git config user.email "releng+jenkins-releng@linuxfoundation.org"
25 git fetch origin refs/meta/config:config
26 git checkout config
27
28 # backup copy of the previous state of project.config
29 cp project.config "${WORKSPACE}/archives"
30
31 install_gerrit_hook() {
32     ssh_url=$(git remote show origin | grep Fetch | grep 'ssh://' \
33         | awk -F'/' '{print $3}' | awk -F':' '{print $1}')
34     ssh_port=$(git remote show origin | grep Fetch | grep 'ssh://' \
35         | awk -F'/' '{print $3}' | awk -F':' '{print $2}')
36
37     if [ -z "$ssh_url" ]; then
38         echo "ERROR: Gerrit SSH URL not found."
39         exit 1
40     fi
41
42     scp -p -P "$ssh_port" "$ssh_url":hooks/commit-msg .git/hooks/
43     chmod u+x .git/hooks/commit-msg
44 }
45 install_gerrit_hook
46
47 mode="${GERRIT_ACCESS_MODE}"
48
49 case $mode in
50     supercommitters)
51         echo "INFO: Locking branch for MRI: ${GERRIT_BRANCH}"
52         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.exclusiveGroupPermissions" "submit"
53         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.submit" "group Release Engineering Team"
54         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.removeReviewer" "group Release Engineering Team"
55         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Code-Review" "-2..+2 group Release Engineering Team"
56         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Verified" "-1..+1 group Release Engineering Team"
57         git commit -asm "Chore: Grant supercommitters rights ${GERRIT_BRANCH}"
58         ;;
59     code-freeze)
60         echo "INFO: Locking branch for code-freeze: ${GERRIT_BRANCH}"
61         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.exclusiveGroupPermissions" "submit"
62         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.submit" "block group Registered Users"
63         git commit -asm "Chore: Lock ${GERRIT_BRANCH} for code-freeze"
64         ;;
65     release-prep)
66         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.exclusiveGroupPermissions" "submit"
67         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.submit" "block group Registered Users"
68         git config -f project.config --add "access.refs/heads/${GERRIT_BRANCH}.submit" "group Release Engineering Team"
69         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Code-Review" "-2..+2 group Release Engineering Team"
70         git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Verified" "-1..+1 group Release Engineering Team"
71         git commit -asm "Chore: Lock ${GERRIT_BRANCH} for Release Work"
72         ;;
73     unlock)
74         echo "INFO: Unlocking branch: ${GERRIT_BRANCH}"
75         git config -f project.config --remove-section "access.refs/heads/${GERRIT_BRANCH}" || true
76         git commit -asm "Chore: Unlock branch ${GERRIT_BRANCH}"
77         ;;
78     *)
79         echo "ERROR: Unknown mode:'$mode'."
80         exit 1
81         ;;
82 esac
83
84 git diff HEAD~1
85 if [ "$DRY_RUN" = true ]; then
86     echo "INFO: DRY RUN enabled, skip pushing changes to the repository."
87 else
88     echo "INFO: Pushing changes to the repository."
89     git push origin HEAD:refs/meta/config
90 fi