Skip to content
Snippets Groups Projects
Commit 346e8fb7 authored by Raphael Defosseux's avatar Raphael Defosseux
Browse files

First draft of the CI scripts

parent 3fd24705
No related branches found
No related tags found
No related merge requests found
// Comments
pipeline {
agent {
label 'bellatrix'
}
options {
disableConcurrentBuilds()
timestamps()
gitLabConnection('OAI GitLab')
//gitlabBuilds(builds: ["Build", "Test"])
}
stages {
stage ("Verify Parameters") {
steps {
echo 'Verify Parameters'
echo "Git URL is ${GIT_URL}"
echo "GitLab Act is ${env.gitlabActionType}"
script {
if ("MERGE".equals(env.gitlabActionType)) {
// GitLab-Jenkins pugin integration is lacking to perform the merge by itself
// Doing it manually --> it may have merge conflicts
sh "./scripts/doGitLabMerge.sh ${env.gitlabSourceBranch} ${env.gitlabMergeRequestLastCommit} ${env.gitlabTargetBranch} ${GIT_COMMIT}"
sh "./scripts/checkCodingFormattingRules.sh ${env.gitlabSourceBranch} ${env.gitlabTargetBranch}"
def res=readFile('./oai_rules_result.txt').trim();
if ("0".equals(res)) {
addGitLabMRComment comment: "All Changed files in Merge Request follow OAI Formatting Rules"
} else {
addGitLabMRComment comment: "Some Changed files in Merge Request DO NOT follow OAI Formatting Rules"
}
} else {
echo "Git Branch is ${GIT_BRANCH}"
echo "Git Commit is ${GIT_COMMIT}"
sh "./scripts/checkCodingFormattingRules.sh"
}
}
}
}
}
post {
always {
}
success {
script {
def message = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ")"
if ("MERGE".equals(env.gitlabActionType)) {
echo "This is a MERGE event"
addGitLabMRComment comment: message
def message2 = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
slackSend channel: 'ci-enb', color: 'good', message: message2
} else {
slackSend channel: 'ci-enb', color: 'good', message: message
}
}
}
failure {
script {
def message = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ")"
if ("MERGE".equals(env.gitlabActionType)) {
echo "This is a MERGE event"
addGitLabMRComment comment: message
def message2 = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
slackSend channel: 'ci-enb', color: 'danger', message: message2
} else {
slackSend channel: 'ci-enb', color: 'danger', message: message
}
}
}
}
}
# OAI is using a style that is similar to the Google style
--style=google
# long options can be written without the preceding '--'
# Convert tabs to spaces
convert-tabs
# Indentation is 2 spaces
indent=spaces=2
# Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block.
indent-switches
# Indent C++ comments beginning in column one.
indent-col1-comments
# Pad empty lines around header blocks
break-blocks
delete-empty-lines
# Attach a pointer or reference operator (*, &, or ^) to the variable name (right)
align-pointer=name
# The code line length is 200 characters/columns
max-code-length=200
break-after-logical
lineend=linux
#!/bin/bash
if [ $# -eq 0 ]
then
NB_FILES_TO_FORMAT=`astyle --dry-run --options=scripts/astyle-options.txt --recursive *.c *.h | grep -c Formatted `
echo "Nb Files that do NOT follow OAI rules: $NB_FILES_TO_FORMAT"
exit 0
fi
if [ $# -eq 2 ]
then
# Merge request scenario
SOURCE_BRANCH=$1
echo "Source Branch is : $SOURCE_BRANCH"
TARGET_BRANCH=$2
echo "Target Branch is : $TARGET_BRANCH"
MERGE_COMMMIT=`git log -n1 | grep commit | sed -e "s@commit @@"`
echo "Merged Commit is : $MERGE_COMMMIT"
TARGET_INIT_COMMIT=`cat .git/refs/remotes/origin/$TARGET_BRANCH`
echo "Target Init is : $TARGET_INIT_COMMIT"
# Retrieve the list of modified files since the latest develop commit
MODIFIED_FILES=`git log $TARGET_INIT_COMMIT..$MERGE_COMMMIT --oneline --name-status | egrep "^M|^A" | sed -e "s@^M\t*@@" -e "s@^A\t*@@" | sort | uniq`
NB_TO_FORMAT=0
for FULLFILE in $MODIFIED_FILES
do
echo $FULLFILE
filename=$(basename -- "$FULLFILE")
EXT="${filename##*.}"
if [ $EXT = "c" ] || [ $EXT = "h" ] || [ $EXT = "cpp" ] || [ $EXT = "hpp" ]
then
TO_FORMAT=`astyle --dry-run --options=scripts/astyle-options.txt $FULLFILE | grep -c Formatted `
NB_TO_FORMAT=$((NB_TO_FORMAT + TO_FORMAT))
fi
done
echo "Nb Files that do NOT follow OAI rules: $NB_TO_FORMAT"
echo $NB_TO_FORMAT > ./oai_rules_result.txt
exit 0
fi
if [ $# -ne 0 ] || [ $# -ne 2 ]
then
echo "Syntax error: $0 without any option will check all files in repository"
echo " or: $0 source-branch target-branch"
echo " will only check files that are pushed for a merge-request"
exit 1
fi
#!/bin/bash
if [ $# -ne 4 ]
then
echo "Syntax Error: $0 src-branch src-commit-id dest-branch dest-commit-id"
exit 1
fi
SOURCE_BRANCH=$1
echo "Source Branch is : $SOURCE_BRANCH"
SOURCE_COMMIT_ID=$2
echo "Source Commit ID is : $SOURCE_COMMIT_ID"
TARGET_BRANCH=$3
echo "Target Branch is : $TARGET_BRANCH"
TARGET_COMMIT_ID=$4
echo "Target Commit ID is : $TARGET_COMMIT_ID"
git config user.email "jenkins@openairinterface.org"
git config user.name "OAI Jenkins"
git checkout -f $SOURCE_COMMIT_ID
git merge --ff $TARGET_COMMIT_ID -m "Temporary merge for CI"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment