Feat: Add new job gerrit-go-verify 56/69356/13 v0.72.0
authorKevin Sandi <ksandi@contractor.linuxfoundation.org>
Wed, 8 Dec 2021 22:27:32 +0000 (16:27 -0600)
committerKevin Sandi <ksandi@contractor.linuxfoundation.org>
Fri, 17 Dec 2021 16:24:22 +0000 (10:24 -0600)
This job adds support for running unit tests on Go projects

Issue-ID: RELENG-4055
Change-Id: I6c4d8bfbaf131837ba91aa1bc1cdf5e2f3f0a790
Signed-off-by: Kevin Sandi <ksandi@contractor.linuxfoundation.org>
.jjb-test/lf-go-jobs/go-jobs.yaml [new file with mode: 0644]
docs/jjb/lf-go-jobs.rst [new file with mode: 0644]
jjb/lf-go-jobs.yaml [new file with mode: 0644]
releasenotes/notes/add-go-verify-job-142a976b1467b748.yaml [new file with mode: 0644]
shell/go-test.sh [new file with mode: 0644]

diff --git a/.jjb-test/lf-go-jobs/go-jobs.yaml b/.jjb-test/lf-go-jobs/go-jobs.yaml
new file mode 100644 (file)
index 0000000..7fb59d8
--- /dev/null
@@ -0,0 +1,27 @@
+---
+- project:
+    name: "gerrit-go-jobs"
+    jobs:
+      - "gerrit-go-verify"
+
+    project: go/project
+    project-name: gerrit-go-project
+    go-root: go
+    branch: master
+
+- project:
+    name: "github-go-jobs"
+    jobs:
+      - "github-go-verify"
+
+    project: go/project
+    project-name: github-go-project
+    go-root: go
+    branch: master
+
+- project:
+    name: go-jobs-view
+    views:
+      - project-view
+
+    project-name: go-project
diff --git a/docs/jjb/lf-go-jobs.rst b/docs/jjb/lf-go-jobs.rst
new file mode 100644 (file)
index 0000000..020b600
--- /dev/null
@@ -0,0 +1,60 @@
+#######
+Go Jobs
+#######
+
+Macros
+======
+
+lf-go-test
+----------
+
+Calls go-test.sh script against a Go project.
+
+:Required Parameters:
+
+    :go-root: Path to the Go project root directory.
+
+lf-go-common
+------------
+
+Common Jenkins configuration for Go jobs.
+
+Job Templates
+=============
+
+Go Verify
+---------
+
+Job which runs go test ./... to verify a Go project.
+'go test ./...' runs unit tests on current folder and all subfolders.
+
+:Template Names:
+
+    - {project-name}-go-verify-{stream}"
+    - gerrit-go-verify
+    - github-go-verify
+
+:Comment Trigger: recheck|reverify
+
+:Required parameters:
+
+    :build-node: The node to run build on.
+    :jenkins-ssh-credential: Credential to use for SSH. (Generally configured in defaults.yaml)
+
+:Optional parameters:
+
+    :branch: Git branch to fetch for the build. (default: master)
+    :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
+    :build-timeout: Timeout in minutes before aborting build. (default: 60)
+    :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
+    :stream: Keyword that represents a release code-name.
+        Often the same as the branch. (default: master)
+    :submodule-recursive: Whether to checkout submodules recursively.
+        (default: true)
+    :submodule-timeout: Timeout (in minutes) for checkout operation.
+        (default: 10)
+    :submodule-disable: Disable submodule checkout operation.
+        (default: false)
+    :gerrit_verify_triggers: Override Gerrit Triggers.
+    :gerrit_trigger_file_paths: Override file paths to filter which file
+        modifications will trigger a build.
diff --git a/jjb/lf-go-jobs.yaml b/jjb/lf-go-jobs.yaml
new file mode 100644 (file)
index 0000000..312b6ea
--- /dev/null
@@ -0,0 +1,155 @@
+##########
+# Macros #
+##########
+
+- builder:
+    name: lf-go-test
+    builders:
+      - inject:
+          properties-content: "GO_ROOT={go-root}"
+      - shell: !include-raw-escape: ../shell/go-test.sh
+
+####################
+# COMMON FUNCTIONS #
+####################
+
+- lf_go_common: &lf_go_common
+    name: lf-go-common
+
+    project-type: freestyle
+    node: "{build-node}"
+
+    ######################
+    # Default parameters #
+    ######################
+
+    branch: master
+    build-days-to-keep: 7
+    build-timeout: 60
+    disable-job: false
+    git-url: "$GIT_URL/$PROJECT"
+    github-url: "https://github.com"
+    stream: master
+    submodule-recursive: true
+    submodule-timeout: 10
+    submodule-disable: false
+
+    #####################
+    # Job Configuration #
+    #####################
+
+    disabled: "{disable-job}"
+
+    properties:
+      - lf-infra-properties:
+          build-days-to-keep: "{build-days-to-keep}"
+
+    parameters:
+      - lf-infra-parameters:
+          project: "{project}"
+          branch: "{branch}"
+          stream: "{stream}"
+
+    wrappers:
+      - lf-infra-wrappers:
+          build-timeout: "{build-timeout}"
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
+
+    publishers:
+      - lf-infra-publish
+
+#############
+# Go Verify #
+#############
+
+- lf_go_verify: &lf_go_verify
+    name: lf-go-verify
+
+    concurrent: true
+
+    gerrit_verify_triggers:
+      - patchset-created-event:
+          exclude-drafts: true
+          exclude-trivial-rebase: false
+          exclude-no-code-change: false
+      - draft-published-event
+      - comment-added-contains-event:
+          comment-contains-value: '^Patch Set\s+\d+:\s+(recheck|reverify)\s*$'
+
+    gerrit_trigger_file_paths:
+      - compare-type: REG_EXP
+        pattern: ".*"
+
+    # github_included_regions MUST match gerrit_trigger_file_paths
+    github_included_regions:
+      - ".*"
+
+    builders:
+      - lf-go-test:
+          go-root: "{go-root}"
+
+- job-template:
+    name: "{project-name}-go-verify-{stream}"
+    id: gerrit-go-verify
+    <<: *lf_go_common
+    # yamllint disable-line rule:key-duplicates
+    <<: *lf_go_verify
+
+    scm:
+      - lf-infra-gerrit-scm:
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
+          git-url: "{git-url}"
+          refspec: "$GERRIT_REFSPEC"
+          branch: "$GERRIT_BRANCH"
+          submodule-disable: "{submodule-disable}"
+          submodule-recursive: "{submodule-recursive}"
+          submodule-timeout: "{submodule-timeout}"
+          choosing-strategy: gerrit
+
+    triggers:
+      - gerrit:
+          server-name: "{gerrit-server-name}"
+          trigger-on: "{obj:gerrit_verify_triggers}"
+          projects:
+            - project-compare-type: ANT
+              project-pattern: "{project}"
+              branches:
+                - branch-compare-type: ANT
+                  branch-pattern: "**/{branch}"
+              file-paths: "{obj:gerrit_trigger_file_paths}"
+
+- job-template:
+    name: "{project-name}-go-verify-{stream}"
+    id: github-go-verify
+    <<: *lf_go_common
+    # yamllint disable-line rule:key-duplicates
+    <<: *lf_go_verify
+
+    properties:
+      - github:
+          url: "{github-url}/{github-org}/{project}"
+
+    scm:
+      - lf-infra-github-scm:
+          url: "{git-clone-url}{github-org}/{project}"
+          refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
+          branch: "$sha1"
+          submodule-recursive: "{submodule-recursive}"
+          submodule-timeout: "{submodule-timeout}"
+          submodule-disable: "{submodule-disable}"
+          choosing-strategy: default
+          jenkins-ssh-credential: "{jenkins-ssh-credential}"
+
+    triggers:
+      - github-pull-request:
+          trigger-phrase: "^(recheck|reverify)$"
+          only-trigger-phrase: true
+          status-context: "Go Verify"
+          permit-all: true
+          github-hooks: true
+          org-list:
+            - "{github-org}"
+          white-list: "{obj:github_pr_allowlist}"
+          admin-list: "{obj:github_pr_admin_list}"
+          white-list-target-branches:
+            - "{branch}"
diff --git a/releasenotes/notes/add-go-verify-job-142a976b1467b748.yaml b/releasenotes/notes/add-go-verify-job-142a976b1467b748.yaml
new file mode 100644 (file)
index 0000000..8bee6b4
--- /dev/null
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    Add gerrit-go-verify job that will support running unit test for Go
+    projects. It will run the command 'go test ./...' inside the indicated
+    GO_ROOT path.
diff --git a/shell/go-test.sh b/shell/go-test.sh
new file mode 100644 (file)
index 0000000..e9acc1f
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2021 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+set -eux
+
+# This script triggers unit tests for a Golang project under $GO_ROOT path
+echo "--> go-test.sh"
+go version
+
+cd "$GO_ROOT"
+
+go mod tidy
+go test ./...
+
+echo "--> go-test.sh ends"