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 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}"
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"
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"
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}"
79 echo "ERROR: Unknown mode:'$mode'."
85 if [ "$DRY_RUN" = true ]; then
86 echo "INFO: DRY RUN enabled, skip pushing changes to the repository."
88 echo "INFO: Pushing changes to the repository."
89 git push origin HEAD:refs/meta/config