--- /dev/null
+#######
+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.
--- /dev/null
+##########
+# 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}"
--- /dev/null
+#!/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"