tf-a-commitlint: add commitlint job
commitlint is being introduced into the TF-A prerequisites, and will
dictate the style of commit messages going into the project. This job
runs commitlint to validate commit messages between a given commit and
its merge base, and is triggered by the Gerrit level one job.
Presently, this job will only verify patches that have been submitted
by @arm.com addresses. This will be rolled out to everybody upon the
next release.
Signed-off-by: Chris Kay <chris.kay@arm.com>
Change-Id: I6c81dd60c97afa07ff1e80ed968b7ac896099912
diff --git a/tf-a-commitlint/Jenkinsfile b/tf-a-commitlint/Jenkinsfile
new file mode 100644
index 0000000..96d7a02
--- /dev/null
+++ b/tf-a-commitlint/Jenkinsfile
@@ -0,0 +1,62 @@
+pipeline {
+ agent {
+ label 'docker-amd64-tf-a-bionic'
+ }
+
+ parameters {
+ string(
+ name: 'URL',
+ defaultValue: 'https://review.trustedfirmware.org/TF-A/trusted-firmware-a',
+ description: 'Repository URL.')
+
+ string(
+ name: 'REFSPEC',
+ defaultValue: '+refs/heads/*:refs/remotes/origin/*',
+ description: 'Git refspec used when fetching.')
+
+ string(
+ name: 'REFNAME',
+ defaultValue: 'origin/master',
+ description: 'Git refname of the last commit to lint.')
+
+ string(
+ name: 'REFNAME_BASE',
+ defaultValue: 'origin/master',
+ description: 'Git refname of the parent of the first commit to lint.')
+ }
+
+ stages {
+ stage('Checkout') {
+ steps {
+ checkout([$class: 'GitSCM',
+ branches: [[name: params.REFNAME]],
+ userRemoteConfigs: [[
+ url: params.URL,
+ refspec: params.REFSPEC]]])
+
+ script {
+ author = sh(
+ returnStdout: true,
+ script: 'git log --format="%ae" -1').trim()
+
+ mergeBase = sh(
+ returnStdout: true,
+ script: "git merge-base ${params.REFNAME_BASE} HEAD").trim()
+ }
+ }
+ }
+
+ stage('Lint') {
+ when {
+ expression {
+ author.endsWith('@arm.com')
+ }
+ }
+
+ steps {
+ sh "BASH_ENV=$NVM_DIR/nvm.sh bash -c 'npm install --no-save commitlint'"
+ sh "BASH_ENV=$NVM_DIR/nvm.sh bash -c 'npx commitlint --from=${mergeBase}'"
+ }
+ }
+ }
+}