| Eric Ball | 8f40444 | 2026-01-05 21:31:56 -0800 | [diff] [blame] | 1 | --- |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # SPDX-FileCopyrightText: 2026 The Linux Foundation |
| 4 | name: Gerrit Verify - Unit Tests |
| Eric Ball | 22e7717 | 2026-05-29 17:39:59 -0700 | [diff] [blame^] | 5 | # Requires a go.mod file to be present in the repo |
| Eric Ball | 8f40444 | 2026-01-05 21:31:56 -0800 | [diff] [blame] | 6 | |
| 7 | # yamllint disable-line rule:truthy |
| 8 | on: |
| Eric Ball | a4700f0 | 2026-04-20 17:34:07 -0700 | [diff] [blame] | 9 | workflow_call: |
| Eric Ball | 8f40444 | 2026-01-05 21:31:56 -0800 | [diff] [blame] | 10 | 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 Ball | 1aa07c0 | 2026-04-20 18:16:08 -0700 | [diff] [blame] | 64 | secrets: |
| 65 | GERRIT_SSH_PRIVKEY: |
| 66 | description: "SSH Key for the authorized user account" |
| 67 | required: true |
| Eric Ball | 8f40444 | 2026-01-05 21:31:56 -0800 | [diff] [blame] | 68 | |
| 69 | concurrency: |
| 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 | |
| 74 | jobs: |
| Eric Ball | f7debd2 | 2026-04-16 10:28:25 -0700 | [diff] [blame] | 75 | prepare: |
| 76 | runs-on: ubuntu-latest |
| 77 | steps: |
| 78 | - name: Clear votes |
| 79 | # yamllint disable-line rule:line-length |
| Eric Ball | 1aa07c0 | 2026-04-20 18:16:08 -0700 | [diff] [blame] | 80 | uses: lfreleng-actions/gerrit-review-action@c4157b2200e1c2464a52f741c01ff85909c62811 |
| Eric Ball | f7debd2 | 2026-04-16 10:28:25 -0700 | [diff] [blame] | 81 | 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 Ball | 01fcab4 | 2026-04-17 15:23:22 -0700 | [diff] [blame] | 89 | comment-only: false |
| Eric Ball | f7debd2 | 2026-04-16 10:28:25 -0700 | [diff] [blame] | 90 | - name: Allow replication |
| 91 | run: sleep 10s |
| 92 | |
| Eric Ball | 8f40444 | 2026-01-05 21:31:56 -0800 | [diff] [blame] | 93 | unit-tests: |
| Eric Ball | f7debd2 | 2026-04-16 10:28:25 -0700 | [diff] [blame] | 94 | needs: prepare |
| Eric Ball | 8f40444 | 2026-01-05 21:31:56 -0800 | [diff] [blame] | 95 | 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 Ball | 1aa07c0 | 2026-04-20 18:16:08 -0700 | [diff] [blame] | 102 | uses: lfit/checkout-gerrit-change-action@fc57a3dd3318f31bd34d435d134e30443593eb80 # v1.0.1 |
| Eric Ball | 8f40444 | 2026-01-05 21:31:56 -0800 | [diff] [blame] | 103 | 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 Ball | f7debd2 | 2026-04-16 10:28:25 -0700 | [diff] [blame] | 121 | - name: Check License Headers |
| Eric Ball | b64854e | 2026-04-21 16:43:33 -0700 | [diff] [blame] | 122 | uses: opencord/shared-workflows/.github/actions/license-check-action@main |
| Eric Ball | 8f40444 | 2026-01-05 21:31:56 -0800 | [diff] [blame] | 123 | - 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 Ball | f7debd2 | 2026-04-16 10:28:25 -0700 | [diff] [blame] | 132 | |
| Eric Ball | 01fcab4 | 2026-04-17 15:23:22 -0700 | [diff] [blame] | 133 | 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 Ball | 1aa07c0 | 2026-04-20 18:16:08 -0700 | [diff] [blame] | 144 | uses: lfreleng-actions/gerrit-review-action@c4157b2200e1c2464a52f741c01ff85909c62811 |
| Eric Ball | 01fcab4 | 2026-04-17 15:23:22 -0700 | [diff] [blame] | 145 | 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 |