Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github: unit-tests: split unit tests to code specific workflows #15065

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/download-install-debian-deps/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ runs:
run: |
sudo apt update
sudo apt build-dep -y "${{ inputs.snapd-src-dir }}"
sudo apt install -y clang
rm -rf ./debian-deps
35 changes: 27 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,41 @@ jobs:
needs:
- go-channels
- static-checks
name: "unit-tests default ${{ matrix.gochannel }}"
name: "unit-tests (Go default ${{ matrix.gochannel }})"
with:
runs-on: ubuntu-latest
gochannel: ${{ matrix.gochannel }}
skip-coverage: ${{ matrix.gochannel == 'latest/stable' }}
code: 'go'
strategy:
# we cache successful runs so it's fine to keep going
fail-fast: false
matrix:
gochannel: ${{ fromJson(needs.go-channels.outputs.go-channels) }}

# TODO run unit tests of C code
unit-tests-c:
uses: ./.github/workflows/unit-tests.yaml
needs:
- cache-build-deps
name: "unit-tests (C ${{ matrix.test-case.c-compiler }})"
with:
runs-on: ubuntu-latest
code: 'c'
c-compiler: ${{ matrix.test-case.c-compiler }}
strategy:
# we cache successful runs so it's fine to keep going
fail-fast: false
matrix:
test-case:
- { c-compiler: gcc }
- { c-compiler: clang }

unit-tests-special:
uses: ./.github/workflows/unit-tests.yaml
needs:
- go-channels
- static-checks
name: "unit-tests (${{ matrix.gochannel }} ${{ matrix.test-case.go-build-tags }}
name: "unit-tests (Go ${{ matrix.gochannel }} ${{ matrix.test-case.go-build-tags }}
${{ matrix.test-case.go-test-race && ' test-race' || ''}}
${{ matrix.test-case.snapd-debug && ' snapd-debug' || ''}})"
with:
Expand All @@ -194,6 +211,7 @@ jobs:
go-build-tags: ${{ matrix.test-case.go-build-tags }}
go-test-race: ${{ matrix.test-case.go-test-race }}
snapd-debug: ${{ matrix.test-case.snapd-debug }}
code: 'go'
strategy:
# we cache successful runs so it's fine to keep going
fail-fast: false
Expand Down Expand Up @@ -232,6 +250,7 @@ jobs:
needs:
- unit-tests
- unit-tests-special
- unit-tests-c
- unit-tests-cross-distro
if: always()
steps:
Expand All @@ -244,7 +263,7 @@ jobs:
needs-json: ${{ toJSON(needs) }}

code-coverage:
needs: [unit-tests, unit-tests-special]
needs: [unit-tests, unit-tests-special, unit-tests-c]
runs-on: ubuntu-20.04
env:
GOPATH: ${{ github.workspace }}
Expand Down Expand Up @@ -292,7 +311,7 @@ jobs:

spread-fundamental:
uses: ./.github/workflows/spread-tests.yaml
needs: [unit-tests, snap-builds, read-systems]
needs: [unit-tests, unit-tests-c, snap-builds, read-systems]
name: "spread ${{ matrix.group }}"
with:
# Github doesn't support passing sequences as parameters.
Expand Down Expand Up @@ -320,7 +339,7 @@ jobs:
if: github.event_name == 'pull_request'
# For workflow runs that are PRs, run this non-fundamental systems job
# only after the fundamental systems job succeeds.
needs: [unit-tests, snap-builds, read-systems, spread-fundamental]
needs: [unit-tests, unit-tests-c, snap-builds, read-systems, spread-fundamental]
name: "spread ${{ matrix.group }}"
with:
# Github doesn't support passing sequences as parameters.
Expand All @@ -347,7 +366,7 @@ jobs:
if: github.event_name != 'pull_request'
# For workflow runs that are not for PRs, no need to impose a dependency
# on the fundamental systems job's success before running this job.
needs: [unit-tests, snap-builds, read-systems]
needs: [unit-tests, unit-tests-c, snap-builds, read-systems]
name: "spread ${{ matrix.group }}"
with:
# Github doesn't support passing sequences as parameters.
Expand All @@ -371,7 +390,7 @@ jobs:

spread-nested:
uses: ./.github/workflows/spread-tests.yaml
needs: [unit-tests, snap-builds]
needs: [unit-tests, unit-tests-c, snap-builds]
name: "spread ${{ matrix.group }}"
with:
# Github doesn't support passing sequences as parameters.
Expand Down
33 changes: 27 additions & 6 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ on:
description: 'A tag to indicate which runner to use'
required: true
type: string
code:
description: 'Code to test (c, go)'
required: true
type: string
c-compiler:
description: 'Compiler for C code'
type: string
default: ''
required: false
gochannel:
description: 'The snap store channel to use to install the go snap'
required: true
required: false
type: string
skip-coverage:
description: 'If true, will not generate test coverage files'
Expand All @@ -31,9 +40,6 @@ on:

jobs:
unit-tests:
name: "unit-tests (${{ inputs.gochannel }} ${{ inputs.go-build-tags }}
${{ inputs.go-test-race && ' test-race' || ''}}
${{ inputs.snapd-debug && ' snapd-debug' || ''}})"
runs-on: ${{ inputs.runs-on }}
env:
# Set PATH to ignore the load of magic binaries from /usr/local/bin And
Expand All @@ -43,6 +49,7 @@ jobs:
PATH: /snap/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${{ github.workspace }}/bin
GOROOT: ""
GO_BUILD_TAGS: ${{ inputs.go-build-tags }}
CC: ${{ inputs.c-compiler }}

steps:
- name: Checkout code
Expand All @@ -56,24 +63,37 @@ jobs:

# golang latest ensures things work on the edge
- name: Install the go snap
if: ${{ inputs.code == 'go' }}
run: |
if [ -z "${{ inputs.gochannel }}" ]; then
echo "gochannel is unset"
exit 1
fi
sudo snap install --classic --channel=${{ inputs.gochannel }} go

- name: Get deps
if: ${{ inputs.code == 'go' }}
run: |
./get-deps.sh

- name: Build C
if: ${{ inputs.code == 'c' }}
run: |
if [ -z "${{ inputs.c-compiler }}" ]; then
echo "c-compiler is unset"
exit 1
fi
cd cmd/
./autogen.sh
make -j$(nproc)

- name: Build Go
if: ${{ inputs.code == 'go' }}
run: |
go build ./...

- name: Test C
if: ${{ inputs.code == 'c' }}
run: |
cd cmd/ && make distcheck

Expand All @@ -90,14 +110,15 @@ jobs:
run: echo "SKIP_COVERAGE=1" >> $GITHUB_ENV

- name: Test Go
if: ${{ inputs.code == 'go' }}
run: |
./run-checks --unit

- name: Create coverage results name
if: ${{ ! inputs.skip-coverage }}
run: |
converted=$(tr '/' '-' <<<${{ inputs.gochannel }})
name="coverage-files-${converted}-${{ inputs.go-build-tags || 'notags' }}${{ inputs.go-test-race && '-race' || ''}}${{ inputs.snapd-debug && '-snapddebug' || ''}}"
converted=$(tr '/' '-' <<<'${{ inputs.gochannel }}')
name="coverage-files-${{ inputs.code }}-${converted}-${{ inputs.go-build-tags || 'notags' }}${{ inputs.go-test-race && '-race' || ''}}${{ inputs.snapd-debug && '-snapddebug' || ''}}${{ inputs.c-compiler }}"
echo "COVERAGE_NAME=$name" >> $GITHUB_ENV

- name: Upload the coverage results
Expand Down
Loading