mirror of
https://gitlab.eurecom.fr/oai/openairinterface5g.git
synced 2026-07-13 04:30:28 +00:00
ci: validate for signed MR commits in the CI
- Add a new script to validate for signed commits - Post a GitLab MR Warning comment listing the unsigned commit details Signed-off-by: Shubhika Garg <shubhika.garg@openairinterface.org>
This commit is contained in:
committed by
Robert Schmidt
parent
13963ba70d
commit
3cbf0927be
@@ -89,6 +89,19 @@ pipeline {
|
||||
echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
|
||||
// GitLab-Jenkins plugin integration is lacking to perform the merge by itself
|
||||
// Doing it manually --> it may have merge conflicts
|
||||
|
||||
// Validate MR commits: checks for missing Signed-off-by and merge commits
|
||||
def mrValidationLog = "signedCommit_${env.BUILD_NUMBER}.log"
|
||||
def mrValidationExitCode = sh(
|
||||
script: "bash ./ci-scripts/pre-ci-check.sh -s origin/${env.gitlabSourceBranch} -t origin/${env.gitlabTargetBranch} > ${mrValidationLog} 2>&1",
|
||||
returnStatus: true
|
||||
)
|
||||
def mrValidationMessage = readFile(mrValidationLog).trim()
|
||||
sh "rm -f ${mrValidationLog}"
|
||||
addGitLabMRComment comment: "${mrValidationMessage}"
|
||||
if (mrValidationExitCode >= 2) {
|
||||
error("${mrValidationMessage}")
|
||||
}
|
||||
sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
|
||||
} else {
|
||||
echo "Git Branch is ${GIT_BRANCH}"
|
||||
|
||||
94
ci-scripts/pre-ci-check.sh
Executable file
94
ci-scripts/pre-ci-check.sh
Executable file
@@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
# SPDX-License-Identifier: LicenseRef-CSSL-1.0
|
||||
|
||||
function usage {
|
||||
echo "OAI GitLab MR validation script (Signed-off-by and merge commits)"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo "------"
|
||||
echo " $0 -s <source-branch> -t <target-branch>"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo "--------"
|
||||
echo " -s"
|
||||
echo " The source branch of the merge request. Default value is current Git Branch (HEAD)"
|
||||
echo ""
|
||||
echo " -t"
|
||||
echo " The target branch of the merge request. Default value is develop"
|
||||
echo ""
|
||||
echo " -h"
|
||||
echo " Print this help message."
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Parse arguments properly
|
||||
SOURCE_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
TARGET_BRANCH="origin/develop"
|
||||
|
||||
git fetch --quiet
|
||||
|
||||
while getopts ":s:t:h" opt; do
|
||||
case "$opt" in
|
||||
s)
|
||||
SOURCE_BRANCH="$OPTARG"
|
||||
;;
|
||||
t)
|
||||
TARGET_BRANCH="$OPTARG"
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
:)
|
||||
echo "Error: Option -$OPTARG requires a value."
|
||||
echo ""
|
||||
usage
|
||||
exit 2
|
||||
;;
|
||||
\?)
|
||||
echo "Error: Invalid option -$OPTARG"
|
||||
echo ""
|
||||
usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ----------------------------
|
||||
# Merged commits
|
||||
# ----------------------------
|
||||
mergeCommits=$(git rev-list --merges --abbrev-commit "$TARGET_BRANCH".."$SOURCE_BRANCH")
|
||||
if [[ -n "$mergeCommits" ]]; then
|
||||
message="> ERROR: Following merge commits are found in the source branch history. Please rebase your branch.\n>\n"
|
||||
message+="> $(echo "$mergeCommits" | paste -sd ',' -)\n"
|
||||
echo -e "$message"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# ----------------------------
|
||||
# Check unsigned commits
|
||||
# ----------------------------
|
||||
unsignedCommits=$(
|
||||
for c in $(git rev-list "$TARGET_BRANCH".."$SOURCE_BRANCH"); do
|
||||
if ! git log -1 --format=%B "$c" | grep -q "Signed-off-by:"; then
|
||||
git log -1 --format='%h' "$c"
|
||||
fi
|
||||
done | paste -sd ","
|
||||
)
|
||||
|
||||
# ----------------------------
|
||||
# Report unsigned commits
|
||||
# ----------------------------
|
||||
message=""
|
||||
|
||||
if [ -n "$unsignedCommits" ]; then
|
||||
message="> WARNING: The following commit(s) are missing a Signed-off-by:\n>\n> $unsignedCommits\n>\n"
|
||||
message+="> Please use 'git commit -s' to sign your commits.\n>\n"
|
||||
message+="> For detailed instructions, refer to the CONTRIBUTING file at the root of this repository."
|
||||
echo -e "$message"
|
||||
exit 1
|
||||
else
|
||||
message="> All commits are signed off using 'git commit -s'."
|
||||
echo -e "$message"
|
||||
exit 0
|
||||
fi
|
||||
Reference in New Issue
Block a user