2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2022 The Linux Foundation and others.
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.
15 # Ensure we fail the job if any steps fail.
18 mkdir -p "${WORKSPACE}/archives"
20 git clone "ssh://jenkins-releng@git.opendaylight.org:29418/All-Projects"
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
28 # backup copy of the previous state of project.config
29 cp project.config "${WORKSPACE}/archives"
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}')
37 if [ -z "$ssh_url" ]; then
38 echo "ERROR: Gerrit SSH URL not found."
42 scp -p -P "$ssh_port" "$ssh_url":hooks/commit-msg .git/hooks/
43 chmod u+x .git/hooks/commit-msg
47 mode="${GERRIT_ACCESS_MODE}"
51 if [ "${GERRIT_BRANCH}" == "master" ] && [[ "${GERRIT_BRANCH_NEXT}" =~ stable ]]; then
52 echo "INFO: Locking branch for new branch cutting: ${GERRIT_BRANCH_NEXT}"
53 git config -f project.config "access.refs/for/refs/heads/${GERRIT_BRANCH_NEXT}.exclusiveGroupPermissions" "create"
54 git config -f project.config "access.refs/for/refs/heads/${GERRIT_BRANCH_NEXT}.create" "block group Registered Users"
55 git config -f project.config --add "access.refs/for/refs/heads/${GERRIT_BRANCH_NEXT}.create" "group Release Engineering Team"
56 git config -f project.config "access.refs/heads/${GERRIT_BRANCH_NEXT}.label-Code-Review" "-2..+2 group Release Engineering Team"
57 git config -f project.config "access.refs/heads/${GERRIT_BRANCH_NEXT}.label-Verified" "-1..+1 group Release Engineering Team"
58 git config -f project.config "access.refs/heads/${GERRIT_BRANCH_NEXT}.submit" "block group Registered Users"
59 git config -f project.config --add "access.refs/heads/${GERRIT_BRANCH_NEXT}.submit" "group Release Engineering Team"
60 git config -f project.config "access.refs/heads/${GERRIT_BRANCH_NEXT}.exclusiveGroupPermissions" "submit"
61 git config -f project.config --add "access.refs/heads/*.create" "group Release Engineering Team"
62 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Code-Review" "-2..+2 group Release Engineering Team"
63 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Verified" "-1..+1 group Release Engineering Team"
64 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.submit" "block group Registered Users"
65 git config -f project.config --add "access.refs/heads/${GERRIT_BRANCH}.submit" "group Release Engineering Team"
66 git commit -asm "Chore: Lock for new branch cutting: ${GERRIT_BRANCH_NEXT}"
68 echo "ERROR: Cannot perform branch cutting on non-master branch."
69 echo "ERROR: stable branch should be ex: stable/sulfur"
74 echo "INFO: Locking branch for MRI: ${GERRIT_BRANCH}"
75 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.exclusiveGroupPermissions" "submit"
76 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.submit" "group Release Engineering Team"
77 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.removeReviewer" "group Release Engineering Team"
78 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Code-Review" "-2..+2 group Release Engineering Team"
79 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Verified" "-1..+1 group Release Engineering Team"
80 git commit -asm "Chore: Grant supercommitters rights ${GERRIT_BRANCH}"
83 echo "INFO: Locking branch for code-freeze: ${GERRIT_BRANCH}"
84 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.exclusiveGroupPermissions" "submit"
85 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.submit" "block group Registered Users"
86 git commit -asm "Chore: Lock ${GERRIT_BRANCH} for code-freeze"
89 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.exclusiveGroupPermissions" "submit"
90 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.submit" "block group Registered Users"
91 git config -f project.config --add "access.refs/heads/${GERRIT_BRANCH}.submit" "group Release Engineering Team"
92 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Code-Review" "-2..+2 group Release Engineering Team"
93 git config -f project.config "access.refs/heads/${GERRIT_BRANCH}.label-Verified" "-1..+1 group Release Engineering Team"
94 git commit -asm "Chore: Lock ${GERRIT_BRANCH} for Release Work"
97 echo "INFO: Unlocking branch: ${GERRIT_BRANCH}"
98 git config -f project.config --remove-section "access.refs/heads/${GERRIT_BRANCH}" || true
99 git commit -asm "Chore: Unlock branch ${GERRIT_BRANCH}"
102 echo "ERROR: Unknown mode:'$mode'."
108 if [ "$DRY_RUN" = true ]; then
109 echo "INFO: DRY RUN enabled, skip pushing changes to the repository."
111 echo "INFO: Pushing changes to the repository."
112 git push origin HEAD:refs/meta/config