Added coverage, codeclimate, test publishing and improvements #156
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
pull_request: | |
paths: | |
- '.github/workflows/test.yml' | |
- 'cmd/**' | |
- 'test/**' | |
- 'go.mod' | |
- 'go.sum' | |
- 'makefile' | |
- '!**/*.md' | |
push: | |
branches: [ main ] | |
workflow_call: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
jobs: | |
lint: | |
permissions: | |
contents: read # for actions/checkout to fetch code | |
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests | |
name: Lint | |
timeout-minutes: 10 | |
strategy: | |
matrix: | |
platform: [ubuntu-latest] | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- name: Harden the runner (Audit all outbound calls) | |
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 | |
with: | |
egress-policy: audit | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- uses: golangci/golangci-lint-action@2226d7cb06a077cd73e56eedd38eecad18e5d837 # v6.5.0 | |
with: | |
# must be specified without patch version | |
version: latest | |
format: | |
name: Format | |
strategy: | |
matrix: | |
platform: [ubuntu-latest] | |
go: [1.22.x] | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- name: Harden the runner (Audit all outbound calls) | |
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 | |
with: | |
egress-policy: audit | |
- name: Check out repository code | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Install go 1.22 | |
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 | |
with: | |
go-version: ${{ matrix.go }} | |
- name: Check formatting | |
run: | | |
make format-check | |
test: | |
strategy: | |
matrix: | |
platform: [ubuntu-latest, windows-latest] | |
include: | |
- platform: ubuntu-latest | |
target: linux | |
- platform: windows-latest | |
target: windows | |
name: 'Test (${{ matrix.target }})' | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- name: Harden the runner (Audit all outbound calls) | |
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 | |
with: | |
egress-policy: audit | |
- name: Install linux deps | |
if: ${{ startsWith(matrix.platform, 'ubuntu') }} | |
run: | | |
sudo apt-get update | |
sudo apt-get install \ | |
ninja-build | |
- name: Install windows deps | |
if: ${{ startsWith(matrix.platform, 'windows') }} | |
run: choco install -y ninja | |
- name: Check out repository code | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Install Go | |
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 | |
with: | |
go-version-file: go.mod | |
check-latest: true | |
cache-dependency-path: | | |
**/go.mod | |
**/go.sum | |
- name: Install go-junit-report | |
run: go install github.com/jstemmer/go-junit-report/v2@latest | |
- name: Unit testing | |
run: | | |
mkdir -p build | |
go test -v ./... > build/vidx2pidxtests-${{ matrix.target }}-amd64.txt | |
- name: Generate JUnit test report | |
if: always() | |
run: | | |
go-junit-report -set-exit-code -in build/vidx2pidxtests-${{ matrix.target }}-amd64.txt -iocopy -out build/vidx2pidx-testreport-${{ matrix.target }}-amd64.xml | |
- name: Archive unit test results | |
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 | |
with: | |
name: test-results-${{ matrix.target }} | |
path: ./build/vidx2pidx-testreport-*.xml | |
if-no-files-found: error | |
publish-test-results: | |
if: ${{ github.workflow != 'Release' }} | |
name: "Publish Tests Results" | |
needs: [ test ] | |
runs-on: ubuntu-latest | |
permissions: | |
checks: write | |
pull-requests: write | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 | |
with: | |
egress-policy: audit | |
- name: Download Artifacts | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | |
with: | |
path: artifacts | |
- name: publish test results | |
uses: EnricoMi/publish-unit-test-result-action@170bf24d20d201b842d7a52403b73ed297e6645b # v2.18.0 | |
with: | |
files: "artifacts/**/vidx2pidx-testreport-*.xml" | |
report_individual_runs: true | |
coverage: | |
if: ${{ github.workflow != 'Release' && github.repository == 'Open-CMSIS-Pack/vidx2pidx' }} | |
needs: [ test ] | |
name: 'Coverage check' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 | |
with: | |
egress-policy: audit | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install \ | |
ninja-build | |
- name: Check out repository code | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Install Go | |
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 | |
with: | |
go-version-file: go.mod | |
check-latest: true | |
cache-dependency-path: | | |
**/go.mod | |
**/go.sum | |
- name: Check coverage | |
run: | | |
make coverage-check | |
- name: Publish coverage report to Code Climate | |
uses: paambaati/codeclimate-action@f429536ee076d758a24705203199548125a28ca7 # v9.0.0 | |
env: | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
with: | |
debug: true | |
coverageLocations: ./build/cover.out:gocov | |
prefix: github.com/open-cmsis-pack/vidx2pidx |