|
1 | 1 | name: Test |
2 | 2 |
|
3 | | -on: [push, pull_request, workflow_call] |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - '.github/workflows/test.yml' |
| 7 | + - 'cmd/**' |
| 8 | + - 'test/**' |
| 9 | + - 'go.mod' |
| 10 | + - 'go.sum' |
| 11 | + - 'makefile' |
| 12 | + - '!**/*.md' |
| 13 | + push: |
| 14 | + branches: [ main ] |
| 15 | + workflow_call: |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 19 | + cancel-in-progress: true |
4 | 20 |
|
5 | 21 | permissions: |
6 | 22 | contents: read |
@@ -86,21 +102,125 @@ jobs: |
86 | 102 | strategy: |
87 | 103 | matrix: |
88 | 104 | platform: [ubuntu-latest, windows-latest] |
89 | | - go: [1.22.x] |
90 | | - name: '${{ matrix.platform }} | ${{ matrix.go }}' |
| 105 | + include: |
| 106 | + - platform: ubuntu-latest |
| 107 | + target: linux |
| 108 | + - platform: windows-latest |
| 109 | + target: windows |
| 110 | + name: 'Test (${{ matrix.target }})' |
91 | 111 | runs-on: ${{ matrix.platform }} |
92 | 112 | steps: |
93 | 113 | - name: Harden the runner (Audit all outbound calls) |
94 | 114 | uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 |
95 | 115 | with: |
96 | 116 | egress-policy: audit |
97 | 117 |
|
| 118 | + - name: Install linux deps |
| 119 | + if: ${{ startsWith(matrix.platform, 'ubuntu') }} |
| 120 | + run: | |
| 121 | + sudo apt-get update |
| 122 | + sudo apt-get install \ |
| 123 | + ninja-build |
| 124 | + |
| 125 | + - name: Install windows deps |
| 126 | + if: ${{ startsWith(matrix.platform, 'windows') }} |
| 127 | + run: choco install -y ninja |
| 128 | + |
98 | 129 | - name: Check out repository code |
99 | 130 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
100 | | - - name: Install go 1.22 |
| 131 | + |
| 132 | + - name: Install Go |
101 | 133 | uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 |
102 | 134 | with: |
103 | | - go-version: ${{ matrix.go }} |
| 135 | + go-version-file: go.mod |
| 136 | + check-latest: true |
| 137 | + cache-dependency-path: | |
| 138 | + **/go.mod |
| 139 | + **/go.sum |
| 140 | +
|
| 141 | + - name: Install go-junit-report |
| 142 | + run: go install github.com/jstemmer/go-junit-report/v2@latest |
| 143 | + |
104 | 144 | - name: Unit testing |
| 145 | + run: | |
| 146 | + mkdir -p build |
| 147 | + go test -v ./... > build/vidx2pidxtests-${{ matrix.target }}-amd64.txt |
| 148 | +
|
| 149 | + - name: Generate JUnit test report |
| 150 | + if: always() |
| 151 | + run: | |
| 152 | + go-junit-report -set-exit-code -in build/vidx2pidxtests-${{ matrix.target }}-amd64.txt -iocopy -out build/vidx2pidx-testreport-${{ matrix.target }}-amd64.xml |
| 153 | +
|
| 154 | + - name: Archive unit test results |
| 155 | + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 |
| 156 | + with: |
| 157 | + name: test-results-${{ matrix.target }} |
| 158 | + path: ./build/vidx2pidx-testreport-*.xml |
| 159 | + if-no-files-found: error |
| 160 | + |
| 161 | + publish-test-results: |
| 162 | + if: ${{ github.workflow != 'Release' }} |
| 163 | + name: "Publish Tests Results" |
| 164 | + needs: [ test ] |
| 165 | + runs-on: ubuntu-latest |
| 166 | + permissions: |
| 167 | + checks: write |
| 168 | + pull-requests: write |
| 169 | + steps: |
| 170 | + - name: Harden Runner |
| 171 | + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 |
| 172 | + with: |
| 173 | + egress-policy: audit |
| 174 | + |
| 175 | + - name: Download Artifacts |
| 176 | + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 |
| 177 | + with: |
| 178 | + path: artifacts |
| 179 | + |
| 180 | + - name: publish test results |
| 181 | + uses: EnricoMi/publish-unit-test-result-action@170bf24d20d201b842d7a52403b73ed297e6645b # v2.18.0 |
| 182 | + with: |
| 183 | + files: "artifacts/**/vidx2pidx-testreport-*.xml" |
| 184 | + report_individual_runs: true |
| 185 | + |
| 186 | + coverage: |
| 187 | + if: ${{ github.workflow != 'Release' && github.repository == 'Open-CMSIS-Pack/vidx2pidx' }} |
| 188 | + needs: [ test ] |
| 189 | + name: 'Coverage check' |
| 190 | + runs-on: ubuntu-latest |
| 191 | + steps: |
| 192 | + - name: Harden Runner |
| 193 | + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 |
| 194 | + with: |
| 195 | + egress-policy: audit |
| 196 | + |
| 197 | + - name: Install dependencies |
| 198 | + run: | |
| 199 | + sudo apt-get update |
| 200 | + sudo apt-get install \ |
| 201 | + ninja-build |
| 202 | +
|
| 203 | + - name: Check out repository code |
| 204 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 205 | + |
| 206 | + - name: Install Go |
| 207 | + uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 |
| 208 | + with: |
| 209 | + go-version-file: go.mod |
| 210 | + check-latest: true |
| 211 | + cache-dependency-path: | |
| 212 | + **/go.mod |
| 213 | + **/go.sum |
| 214 | +
|
| 215 | + - name: Check coverage |
105 | 216 | run: | |
106 | 217 | make coverage-check |
| 218 | +
|
| 219 | + - name: Publish coverage report to Code Climate |
| 220 | + uses: paambaati/codeclimate-action@f429536ee076d758a24705203199548125a28ca7 # v9.0.0 |
| 221 | + env: |
| 222 | + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} |
| 223 | + with: |
| 224 | + debug: true |
| 225 | + coverageLocations: ./build/cover.out:gocov |
| 226 | + prefix: github.com/open-cmsis-pack/vidx2pidx |
0 commit comments