Open-CMSIS-Pack/cpackget

View on GitHub
.github/workflows/test.yml

Summary

Maintainability
Test Coverage
name: Test

on:
  workflow_dispatch:
  push: 
    branches: [main]
  pull_request:
    paths:
      - .github/workflows/test.yml
      - cmd/**/*.go
      - testdata/**/*
      - makefile
      - .golangci.yml
      - go.mod
      - go.sum
  workflow_call:
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  lint:
    name: Lint
    timeout-minutes: 10
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
          check-latest: true

      - uses: golangci/golangci-lint-action@v6
        with:
          version: latest

  format:
    name: Format
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4

      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
          check-latest: true

      - name: Check formatting
        run: |
          make format-check

  vulnerability-check:
    name: "Vulnerability check"
    runs-on: ubuntu-latest
    steps:
      - name: Scan for Vulnerabilities
        uses: golang/govulncheck-action@v1
        with:
          go-version-file: go.mod
          check-latest: true
          go-package: ./...

  # Make sure local_repository.pidx is linted against PackIndex.xsd
  xmllint:
    name: Xmllint
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4

      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
          check-latest: true

      - name: Install xmllint
        run: sudo apt-get update && sudo apt-get install libxml2-utils

      - name: Check if local_repository.pidx is valid
        run: |
          make test-xmllint-localrepository

  test-amd64:
    strategy:
      matrix:
        # Tests on Mac are currently broken
        goos: [windows, linux, darwin]
        include:
          - goos: windows
            runs-on: windows-latest
          - goos: linux
            runs-on: ubuntu-latest
          - goos: darwin
            runs-on: macos-latest

    name: "${{ matrix.goos }} | amd64"
    runs-on: ${{ matrix.runs-on }}
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4

      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
          check-latest: true

      - name: Install go-junit-report
        run: go install github.com/jstemmer/go-junit-report/v2@latest

      - name: Run unit tests
        run: |
          mkdir -p build
          make test > build/cpackgettests-${{ matrix.goos }}-amd64.txt

      - name: Generate JUnit test report
        if: always()
        run: |
          go-junit-report -set-exit-code -in build/cpackgettests-${{ matrix.goos }}-amd64.txt -iocopy -out build/cpackget-testreport-${{ matrix.goos }}-amd64.xml
 
      - name: Publish coverage report to Code Climate
        if: ${{ startsWith(matrix.runs-on, 'ubuntu') && (github.workflow != 'Release') }}
        uses: paambaati/codeclimate-action@v9.0.0
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
        with:
          debug: true
          coverageLocations: ./cover.out:gocov
          prefix: github.com/open-cmsis-pack/cpackget

      - name: Archive unit test results
        uses: actions/upload-artifact@v4
        with:
          name: test-results-${{ matrix.goos }}-amd64
          path: ./build/cpackget-testreport-${{ matrix.goos }}-amd64.xml
          if-no-files-found: error

  test-linux-arm64:
    name: "linux | arm64"
    runs-on: ubuntu-latest
    steps:
      - name: Unit testing
        uses: uraimo/run-on-arch-action@v2
        with:
          arch: aarch64
          distro: ubuntu_latest
          env: |
            GIT_DISCOVERY_ACROSS_FILESYSTEM: 1
          install: |
            apt-get update -qq -y
            apt-get install -qq -y software-properties-common git make
            add-apt-repository -y ppa:longsleep/golang-backports
            apt-get update -qq -y
            apt-get install -qq -y golang-1.22
          setup: |
            mkdir -p "${PWD}/artifacts"
          dockerRunArgs: |
            --volume "${PWD}/artifacts:/artifacts"
          run: |
            export PATH=$PATH:/usr/lib/go-1.22/bin
            git clone --depth 1 ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
            cd cpackget
            git fetch --depth 1 origin ${GITHUB_REF}
            git checkout FETCH_HEAD
            mkdir -p build
            make test > build/cpackgettests-linux-arm64.txt
            cp build/cpackgettests-linux-arm64.txt "/artifacts/cpackgettests-linux-arm64.txt"

      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.22'
          check-latest: true

      - name: Install go-junit-report
        run: go install github.com/jstemmer/go-junit-report/v2@latest

      - name: Generate JUnit test report
        run: |
          go-junit-report -set-exit-code -in ${PWD}/artifacts/cpackgettests-linux-arm64.txt -iocopy -out ./cpackget-testreport-linux-arm64.xml
  
      - name: Archive unit test results
        uses: actions/upload-artifact@v4
        with:
          name: test-results-linux-arm64
          path: ./cpackget-testreport-linux-arm64.xml
          if-no-files-found: error