Add shared workflow for unit tests plus tag check
This is slightly rearranged from the base unit test WF, to make the
license and tag checks run only once, rather than for each UT target.
Signed-off-by: Eric Ball <eball@linuxfoundation.org>
Change-Id: I093004c7fd76658e0a040e88631ffddc62a6c9b9
diff --git a/.github/workflows/verify-unit-tests-tag.yaml b/.github/workflows/verify-unit-tests-tag.yaml
new file mode 100644
index 0000000..50454fb
--- /dev/null
+++ b/.github/workflows/verify-unit-tests-tag.yaml
@@ -0,0 +1,169 @@
+---
+# SPDX-License-Identifier: Apache-2.0
+# SPDX-FileCopyrightText: 2026 The Linux Foundation
+name: Gerrit Verify - Unit Tests
+
+# yamllint disable-line rule:truthy
+on:
+ workflow_call:
+ inputs:
+ # Gerrit-to-Github defaults
+ GERRIT_BRANCH:
+ description: "Branch that change is against"
+ required: true
+ type: string
+ GERRIT_CHANGE_ID:
+ description: "The ID for the change"
+ required: true
+ type: string
+ GERRIT_CHANGE_NUMBER:
+ description: "The Gerrit number"
+ required: true
+ type: string
+ GERRIT_CHANGE_URL:
+ description: "URL to the change"
+ required: true
+ type: string
+ GERRIT_EVENT_TYPE:
+ description: "Type of Gerrit event"
+ required: true
+ type: string
+ GERRIT_PATCHSET_NUMBER:
+ description: "The patch number for the change"
+ required: true
+ type: string
+ GERRIT_PATCHSET_REVISION:
+ description: "The revision sha"
+ required: true
+ type: string
+ GERRIT_PROJECT:
+ description: "Project in Gerrit"
+ required: true
+ type: string
+ GERRIT_REFSPEC:
+ description: "Gerrit refspec of change"
+ required: true
+ type: string
+ # Workflow-specific inputs
+ UNIT_TEST_TARGETS:
+ description: "List of targets in json-formatted string"
+ required: false
+ type: string
+ default: '["lint", "sca", "test"]'
+ DEST_GOPATH:
+ description: "Specifies part of the GOPATH. Usually set to Github org."
+ required: false
+ type: string
+ default: "github.com/opencord"
+ GOPROXY:
+ description: "Url for Go proxy"
+ required: false
+ type: string
+ default: "https://proxy.golang.org"
+ secrets:
+ GERRIT_SSH_PRIVKEY:
+ description: "SSH Key for the authorized user account"
+ required: true
+
+concurrency:
+ # yamllint disable-line rule:line-length
+ group: verify-unit-tests-${{ github.workflow }}-${{ github.event.inputs.GERRIT_CHANGE_ID || github.run_id }}
+ cancel-in-progress: true
+
+jobs:
+ prepare:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Clear votes
+ # yamllint disable-line rule:line-length
+ uses: lfreleng-actions/gerrit-review-action@c4157b2200e1c2464a52f741c01ff85909c62811
+ with:
+ host: ${{ vars.GERRIT_SERVER }}
+ username: ${{ vars.GERRIT_SSH_USER }}
+ key: ${{ secrets.GERRIT_SSH_PRIVKEY }}
+ known_hosts: ${{ vars.GERRIT_KNOWN_HOSTS }}
+ gerrit-change-number: ${{ inputs.GERRIT_CHANGE_NUMBER }}
+ gerrit-patchset-number: ${{ inputs.GERRIT_PATCHSET_NUMBER }}
+ vote-type: clear
+ comment-only: false
+ - name: Allow replication
+ run: sleep 10s
+
+ unit-tests:
+ needs: prepare
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ target: ${{ fromJSON(inputs.UNIT_TEST_TARGETS) }}
+ steps:
+ - name: Gerrit Checkout
+ # yamllint disable-line rule:line-length
+ uses: lfit/checkout-gerrit-change-action@fc57a3dd3318f31bd34d435d134e30443593eb80 # v1.0.1
+ with:
+ gerrit-refspec: ${{ inputs.GERRIT_REFSPEC }}
+ gerrit-project: ${{ inputs.GERRIT_PROJECT }}
+ gerrit-url: ${{ vars.GERRIT_URL }}
+ delay: "0s"
+ submodules: "true"
+ fetch-depth: 0
+ # yamllint disable-line rule:line-length
+ - name: Install python
+ uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
+ with:
+ python-version: "3.10"
+ - name: Install virtualenv
+ run: pip install virtualenv
+ - name: Install Go
+ uses: actions/setup-go@v5
+ with:
+ go-version-file: go.mod
+ - name: Run unit tests
+ env:
+ DEST_GOPATH: ${{ inputs.DEST_GOPATH }}
+ UNIT_TEST_TARGETS: ${{ matrix.target }}
+ GOPROXY: ${{ inputs.GOPROXY }}
+ TEST_PROJECT: ${{ github.repository }}
+ WORKSPACE: ${{ github.workspace }}
+ run: |
+ make SHELL="/bin/bash" ${{ matrix.target }}
+
+ license-and-tag-check:
+ needs: prepare
+ runs-on: ubuntu-latest
+ steps:
+ - name: Gerrit Checkout
+ # yamllint disable-line rule:line-length
+ uses: lfit/checkout-gerrit-change-action@fc57a3dd3318f31bd34d435d134e30443593eb80 # v1.0.1
+ with:
+ gerrit-refspec: ${{ inputs.GERRIT_REFSPEC }}
+ gerrit-project: ${{ inputs.GERRIT_PROJECT }}
+ gerrit-url: ${{ vars.GERRIT_URL }}
+ delay: "0s"
+ submodules: "true"
+ fetch-depth: 0
+ - name: Check Tags
+ uses: opencord/shared-workflows/.github/actions/tag-check-action@main
+ - name: Check License Headers
+ uses: opencord/shared-workflows/.github/actions/license-check-action@main
+
+ vote:
+ if: ${{ always() }}
+ # yamllint enable rule:line-length
+ needs: [prepare, unit-tests]
+ runs-on: ubuntu-latest
+ steps:
+ - name: Get conclusion
+ # yamllint disable-line rule:line-length
+ uses: im-open/workflow-conclusion@e4f7c4980600fbe0818173e30931d3550801b992 # v2.2.3
+ - name: Set vote
+ # yamllint disable-line rule:line-length
+ uses: lfreleng-actions/gerrit-review-action@c4157b2200e1c2464a52f741c01ff85909c62811
+ with:
+ host: ${{ vars.GERRIT_SERVER }}
+ username: ${{ vars.GERRIT_SSH_USER }}
+ key: ${{ secrets.GERRIT_SSH_PRIVKEY }}
+ known_hosts: ${{ vars.GERRIT_KNOWN_HOSTS }}
+ gerrit-change-number: ${{ inputs.GERRIT_CHANGE_NUMBER }}
+ gerrit-patchset-number: ${{ inputs.GERRIT_PATCHSET_NUMBER }}
+ vote-type: ${{ env.WORKFLOW_CONCLUSION }}
+ comment-only: false