blob: 1bab794b44336cf54754cf52fac53c939526d63b [file] [log] [blame]
Eric Ball8f404442026-01-05 21:31:56 -08001---
2# SPDX-License-Identifier: Apache-2.0
3# SPDX-FileCopyrightText: 2026 The Linux Foundation
4name: Gerrit Verify - Unit Tests
Eric Ball22e77172026-05-29 17:39:59 -07005# Requires a go.mod file to be present in the repo
Eric Ball8f404442026-01-05 21:31:56 -08006
7# yamllint disable-line rule:truthy
8on:
Eric Balla4700f02026-04-20 17:34:07 -07009 workflow_call:
Eric Ball8f404442026-01-05 21:31:56 -080010 inputs:
11 # Gerrit-to-Github defaults
12 GERRIT_BRANCH:
13 description: "Branch that change is against"
14 required: true
15 type: string
16 GERRIT_CHANGE_ID:
17 description: "The ID for the change"
18 required: true
19 type: string
20 GERRIT_CHANGE_NUMBER:
21 description: "The Gerrit number"
22 required: true
23 type: string
24 GERRIT_CHANGE_URL:
25 description: "URL to the change"
26 required: true
27 type: string
28 GERRIT_EVENT_TYPE:
29 description: "Type of Gerrit event"
30 required: true
31 type: string
32 GERRIT_PATCHSET_NUMBER:
33 description: "The patch number for the change"
34 required: true
35 type: string
36 GERRIT_PATCHSET_REVISION:
37 description: "The revision sha"
38 required: true
39 type: string
40 GERRIT_PROJECT:
41 description: "Project in Gerrit"
42 required: true
43 type: string
44 GERRIT_REFSPEC:
45 description: "Gerrit refspec of change"
46 required: true
47 type: string
48 # Workflow-specific inputs
49 UNIT_TEST_TARGETS:
50 description: "List of targets in json-formatted string"
51 required: false
52 type: string
53 default: '["lint", "sca", "test"]'
54 DEST_GOPATH:
55 description: "Specifies part of the GOPATH. Usually set to Github org."
56 required: false
57 type: string
58 default: "github.com/opencord"
59 GOPROXY:
60 description: "Url for Go proxy"
61 required: false
62 type: string
63 default: "https://proxy.golang.org"
Eric Ball1aa07c02026-04-20 18:16:08 -070064 secrets:
65 GERRIT_SSH_PRIVKEY:
66 description: "SSH Key for the authorized user account"
67 required: true
Eric Ball8f404442026-01-05 21:31:56 -080068
69concurrency:
70 # yamllint disable-line rule:line-length
71 group: verify-unit-tests-${{ github.workflow }}-${{ github.event.inputs.GERRIT_CHANGE_ID || github.run_id }}
72 cancel-in-progress: true
73
74jobs:
Eric Ballf7debd22026-04-16 10:28:25 -070075 prepare:
76 runs-on: ubuntu-latest
77 steps:
78 - name: Clear votes
79 # yamllint disable-line rule:line-length
Eric Ball1aa07c02026-04-20 18:16:08 -070080 uses: lfreleng-actions/gerrit-review-action@c4157b2200e1c2464a52f741c01ff85909c62811
Eric Ballf7debd22026-04-16 10:28:25 -070081 with:
82 host: ${{ vars.GERRIT_SERVER }}
83 username: ${{ vars.GERRIT_SSH_USER }}
84 key: ${{ secrets.GERRIT_SSH_PRIVKEY }}
85 known_hosts: ${{ vars.GERRIT_KNOWN_HOSTS }}
86 gerrit-change-number: ${{ inputs.GERRIT_CHANGE_NUMBER }}
87 gerrit-patchset-number: ${{ inputs.GERRIT_PATCHSET_NUMBER }}
88 vote-type: clear
Eric Ball01fcab42026-04-17 15:23:22 -070089 comment-only: false
Eric Ballf7debd22026-04-16 10:28:25 -070090 - name: Allow replication
91 run: sleep 10s
92
Eric Ball8f404442026-01-05 21:31:56 -080093 unit-tests:
Eric Ballf7debd22026-04-16 10:28:25 -070094 needs: prepare
Eric Ball8f404442026-01-05 21:31:56 -080095 runs-on: ubuntu-latest
96 strategy:
97 matrix:
98 target: ${{ fromJSON(inputs.UNIT_TEST_TARGETS) }}
99 steps:
100 - name: Gerrit Checkout
101 # yamllint disable-line rule:line-length
Eric Ball1aa07c02026-04-20 18:16:08 -0700102 uses: lfit/checkout-gerrit-change-action@fc57a3dd3318f31bd34d435d134e30443593eb80 # v1.0.1
Eric Ball8f404442026-01-05 21:31:56 -0800103 with:
104 gerrit-refspec: ${{ inputs.GERRIT_REFSPEC }}
105 gerrit-project: ${{ inputs.GERRIT_PROJECT }}
106 gerrit-url: ${{ vars.GERRIT_URL }}
107 delay: "0s"
108 submodules: "true"
109 fetch-depth: 0
110 # yamllint disable-line rule:line-length
111 - name: Install python
112 uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
113 with:
114 python-version: "3.10"
115 - name: Install virtualenv
116 run: pip install virtualenv
117 - name: Install Go
118 uses: actions/setup-go@v5
119 with:
120 go-version-file: go.mod
Eric Ballf7debd22026-04-16 10:28:25 -0700121 - name: Check License Headers
Eric Ballb64854e2026-04-21 16:43:33 -0700122 uses: opencord/shared-workflows/.github/actions/license-check-action@main
Eric Ball8f404442026-01-05 21:31:56 -0800123 - name: Run unit tests
124 env:
125 DEST_GOPATH: ${{ inputs.DEST_GOPATH }}
126 UNIT_TEST_TARGETS: ${{ matrix.target }}
127 GOPROXY: ${{ inputs.GOPROXY }}
128 TEST_PROJECT: ${{ github.repository }}
129 WORKSPACE: ${{ github.workspace }}
130 run: |
131 make SHELL="/bin/bash" ${{ matrix.target }}
Eric Ballf7debd22026-04-16 10:28:25 -0700132
Eric Ball01fcab42026-04-17 15:23:22 -0700133 vote:
134 if: ${{ always() }}
135 # yamllint enable rule:line-length
136 needs: [prepare, unit-tests]
137 runs-on: ubuntu-latest
138 steps:
139 - name: Get conclusion
140 # yamllint disable-line rule:line-length
141 uses: im-open/workflow-conclusion@e4f7c4980600fbe0818173e30931d3550801b992 # v2.2.3
142 - name: Set vote
143 # yamllint disable-line rule:line-length
Eric Ball1aa07c02026-04-20 18:16:08 -0700144 uses: lfreleng-actions/gerrit-review-action@c4157b2200e1c2464a52f741c01ff85909c62811
Eric Ball01fcab42026-04-17 15:23:22 -0700145 with:
146 host: ${{ vars.GERRIT_SERVER }}
147 username: ${{ vars.GERRIT_SSH_USER }}
148 key: ${{ secrets.GERRIT_SSH_PRIVKEY }}
149 known_hosts: ${{ vars.GERRIT_KNOWN_HOSTS }}
150 gerrit-change-number: ${{ inputs.GERRIT_CHANGE_NUMBER }}
151 gerrit-patchset-number: ${{ inputs.GERRIT_PATCHSET_NUMBER }}
152 vote-type: ${{ env.WORKFLOW_CONCLUSION }}
153 comment-only: false