Skip to content

Commit

Permalink
tests: cleanup github workflows (#14745)
Browse files Browse the repository at this point in the history
* tests: pull repo into current directory; change inputs for unit tests from scenario based to run-checks inputs based; change run-checks to go tests ./...

* tests: remove necessary things

* tests: remove unnecessary force depth in checkout

* tests: remove a directory level for actions

* tests: corrected uploading coverage results to occur only if coverage is generated

* tests: more meaningful names and moved skip cover condition to outside unit-tests.yaml

* run-checks: removed go test list for test discovery
  • Loading branch information
maykathm authored Nov 29, 2024
1 parent bf97e74 commit 69641bd
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ runs:
run: |
sudo apt update
sudo apt build-dep -y "${{ inputs.snapd-src-dir }}"
rm -rf ./debian-deps
19 changes: 11 additions & 8 deletions .github/workflows/spread-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ jobs:
if [ -f "$FAILED_TESTS_FILE" ]; then
echo "Failed tests file found"
FAILED_TESTS="$(cat $FAILED_TESTS_FILE)"
if [ -n "$FAILED_TESTS" ]; then
echo "Failed tests to run: $FAILED_TESTS"
echo "FAILED_TESTS=$FAILED_TESTS" >> $GITHUB_ENV
fi
echo "Failed tests to run: $FAILED_TESTS"
echo "FAILED_TESTS=$FAILED_TESTS" >> $GITHUB_ENV
fi
- name: Setup run tests variable
Expand Down Expand Up @@ -228,7 +226,12 @@ jobs:
# propagated; and we use a subshell as this option could trigger
# undesired changes elsewhere
echo "Running command: $SPREAD $RUN_TESTS"
(set -o pipefail; $SPREAD -no-debug-output -logs spread-logs $RUN_TESTS | PYTHONDONTWRITEBYTECODE=1 ./tests/lib/external/snapd-testing-tools/utils/log-filter $FILTER_PARAMS | tee spread.log)
(
set -o pipefail
$SPREAD -no-debug-output -logs spread-logs $RUN_TESTS | \
./tests/lib/external/snapd-testing-tools/utils/log-filter $FILTER_PARAMS | \
tee spread.log
)
- name: Upload spread logs
if: always()
Expand All @@ -252,7 +255,7 @@ jobs:
if [ -e spread.log ]; then
echo "Running spread log analyzer"
ACTIONS_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}"
PYTHONDONTWRITEBYTECODE=1 ./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --output spread-results.json --cut 1 >/dev/null
./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --output spread-results.json --cut 1 >/dev/null
while IFS= read -r line; do
if [ ! -z "$line" ]; then
echo "Adding failed test line to filtered log"
Expand All @@ -268,15 +271,15 @@ jobs:
run: |
if [ -f spread.log ]; then
echo "Running spread log parser"
PYTHONDONTWRITEBYTECODE=1 ./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --output spread-results.json
./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --output spread-results.json
# Add openstack backend definition to spread.yaml
if [ "${{ inputs.backend }}" = openstack ]; then
./tests/lib/spread/add-backend tests/lib/spread/backend.openstack.yaml spread.yaml
fi
echo "Running spread log analyzer"
PYTHONDONTWRITEBYTECODE=1 ./tests/lib/external/snapd-testing-tools/utils/log-analyzer list-reexecute-tasks "$RUN_TESTS" spread-results.json > "$FAILED_TESTS_FILE"
./tests/lib/external/snapd-testing-tools/utils/log-analyzer list-reexecute-tasks "$RUN_TESTS" spread-results.json > "$FAILED_TESTS_FILE"
echo "List of failed tests saved"
cat "$FAILED_TESTS_FILE"
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/static-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
static-checks:
runs-on: ${{ inputs.runs-on }}
env:
GOPATH: ${{ github.workspace }}
# Set PATH to ignore the load of magic binaries from /usr/local/bin And
# to use the go snap automatically. Note that we install go from the
# snap in a step below. Without this we get the GitHub-controlled latest
Expand All @@ -30,21 +29,17 @@ jobs:
with:
# needed for git commit history
fetch-depth: 0
# NOTE: checkout the code in a fixed location, even for forks, as this
# is relevant for go's import system.
path: ./src/github.com/snapcore/snapd

# Fetch base ref, needed for golangci-lint
- name: Fetching base ref ${{ github.base_ref }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
- name: Download and install Debian dependencies
# Github does not allow variables in "uses"; this has to be a hard-coded path
uses: ./src/github.com/snapcore/snapd/.github/workflows/actions/download-install-debian-deps
uses: ./.github/actions/download-install-debian-deps
with:
snapd-src-dir: "${{ github.workspace }}/src/github.com/snapcore/snapd"
snapd-src-dir: "${{ github.workspace }}"

# golang latest ensures things work on the edge
- name: Install the go snap
Expand All @@ -58,7 +53,7 @@ jobs:
- name: Get C vendoring
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/c-vendor && ./vendor.sh
cd c-vendor && ./vendor.sh
- name: Install golangci-lint snap
run: |
Expand All @@ -68,7 +63,7 @@ jobs:
id: changed-files
uses: tj-actions/[email protected]
with:
path: ./src/github.com/snapcore/snapd
path: ./

- name: Save changes files
run: |
Expand All @@ -78,7 +73,6 @@ jobs:
- name: Run static checks
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
# run gofmt checks only with the latest stable Go
if [ "${{ matrix.gochannel }}" != "latest/stable" ]; then
export SKIP_GOFMT=1
Expand Down Expand Up @@ -113,7 +107,7 @@ jobs:
- name: Check C source code formatting
run: |
set -x
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/
cd cmd/
./autogen.sh
# apply formatting
PATH=${{ github.workspace }}/indent-bin/opt/indent/bin:$PATH make fmt
Expand Down
42 changes: 17 additions & 25 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,12 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# needed for git commit history
fetch-depth: 0
# NOTE: checkout the code in a fixed location, even for forks, as this
# is relevant for go's import system.
path: ./src/github.com/snapcore/snapd

# Fetch base ref, needed for golangci-lint
- name: Fetching base ref ${{ github.base_ref }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
# golang latest ensures things work on the edge

- name: Download Debian dependencies
run: |
sudo apt clean
sudo apt update
sudo apt build-dep -d -y ${{ github.workspace }}/src/github.com/snapcore/snapd
sudo apt build-dep -d -y ${{ github.workspace }}
# for indent
sudo apt install texinfo autopoint
Expand Down Expand Up @@ -118,42 +105,47 @@ jobs:
unit-tests:
uses: ./.github/workflows/unit-tests.yaml
needs: [static-checks]
name: "unit-tests default ${{ matrix.gochannel }}"
with:
runs-on: ubuntu-22.04
gochannel: ${{ matrix.gochannel }}
unit-scenario: ${{ matrix.unit-scenario }}
skip-coverage: ${{ matrix.gochannel == 'latest/stable' }}
strategy:
# we cache successful runs so it's fine to keep going
fail-fast: false
matrix:
gochannel:
- 1.18
- latest/stable
unit-scenario:
- normal

# TODO run unit tests of C code
unit-tests-special:
uses: ./.github/workflows/unit-tests.yaml
needs: [static-checks]
name: "unit-tests (${{ matrix.gochannel }} ${{ matrix.test-case.go-build-tags }}
${{ matrix.test-case.go-test-race && ' test-race' || ''}}
${{ matrix.test-case.snapd-debug && ' snapd-debug' || ''}})"
with:
runs-on: ubuntu-22.04
gochannel: ${{ matrix.gochannel }}
unit-scenario: ${{ matrix.unit-scenario }}
skip-coverage: ${{ matrix.gochannel == 'latest/stable' || matrix.test-case.skip-coverage }}
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 }}
strategy:
# we cache successful runs so it's fine to keep going
fail-fast: false
matrix:
gochannel:
- 1.18
- latest/stable
unit-scenario:
- snapd_debug
- withbootassetstesting
- nosecboot
- faultinject
- race
- snapdusergo
test-case:
- { go-build-tags: snapd_debug, skip-coverage: false, snapd-debug: true, go-test-race: false}
- { go-build-tags: withbootassetstesting, skip-coverage: false, snapd-debug: false, go-test-race: false}
- { go-build-tags: nosecboot, skip-coverage: false, snapd-debug: false, go-test-race: false}
- { go-build-tags: faultinject, skip-coverage: false, snapd-debug: false, go-test-race: false}
- { go-build-tags: snapdusergo, skip-coverage: false, snapd-debug: false, go-test-race: false}
- { go-build-tags: "", skip-coverage: true, snapd-debug: false, go-test-race: true }

unit-tests-cross-distro:
uses: ./.github/workflows/unit-tests-cross-distro.yaml
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/unit-tests-cross-distro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# needed for git commit history
fetch-depth: 0

- name: Install dependencies
run: |
Expand All @@ -51,6 +48,7 @@ jobs:
exit 1
;;
esac
- name: Set up test user
run: |
useradd -U -m test-user
Expand Down
117 changes: 43 additions & 74 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,50 @@ on:
description: 'The snap store channel to use to install the go snap'
required: true
type: string
unit-scenario:
description: 'The name of the scenario being tested: {normal, snapd-debug, withbootassetstesting, nosecboot, faultinject, race, snapdusergo}'
required: true
skip-coverage:
description: 'If true, will not generate test coverage files'
type: boolean
default: false
required: false
go-build-tags:
description: 'Tag to add to go test'
type: string
required: false
go-test-race:
description: 'If true, will add race tag to go test'
type: boolean
default: false
required: false
snapd-debug:
description: 'If true, will set SNAPD_DEBUG=1'
type: boolean
default: false
required: false

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:
GOPATH: ${{ github.workspace }}
# Set PATH to ignore the load of magic binaries from /usr/local/bin And
# to use the go snap automatically. Note that we install go from the
# snap in a step below. Without this we get the GitHub-controlled latest
# version of go.
PATH: /snap/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${{ github.workspace }}/bin
GOROOT: ""
GO_BUILD_TAGS: ${{ inputs.go-build-tags }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# needed for git commit history
fetch-depth: 0
# NOTE: checkout the code in a fixed location, even for forks, as this
# is relevant for go's import system.
path: ./src/github.com/snapcore/snapd

# Fetch base ref, needed for golangci-lint
- name: Fetching base ref ${{ github.base_ref }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}

- name: Download and install Debian dependencies
# Github does not allow variables in "uses"; this has to be a hard-coded path
uses: ./src/github.com/snapcore/snapd/.github/workflows/actions/download-install-debian-deps
uses: ./.github/actions/download-install-debian-deps
with:
snapd-src-dir: "${{ github.workspace }}/src/github.com/snapcore/snapd"
snapd-src-dir: "${{ github.workspace }}"

# golang latest ensures things work on the edge
- name: Install the go snap
Expand All @@ -55,79 +61,42 @@ jobs:
- name: Get deps
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/ && ./get-deps.sh
./get-deps.sh
- name: Build C
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/
cd cmd/
./autogen.sh
make -j$(nproc)
- name: Build Go
run: |
go build github.com/snapcore/snapd/...
go build ./...
- name: Test C
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/ && make distcheck
- name: Reset code coverage data
run: |
rm -rf ${{ github.workspace }}/.coverage/
COVERAGE_OUT="${{ github.workspace }}/coverage/coverage-${{ inputs.unit-scenario}}.cov"
echo "COVERAGE_OUT=$COVERAGE_OUT" >> $GITHUB_ENV
- name: Test Go
if: ${{ inputs.unit-scenario == 'normal' }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
./run-checks --unit
cd cmd/ && make distcheck
- name: Set SNAPD_DEBUG=1
if: ${{ inputs.snapd-debug }}
run: echo "SNAPD_DEBUG=1" >> $GITHUB_ENV

- name: Test Go (SNAPD_DEBUG=1)
if: ${{ inputs.unit-scenario == 'snapd_debug' }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
SKIP_DIRTY_CHECK=1 SNAPD_DEBUG=1 ./run-checks --unit
- name: Set GO_TEST_RACE=1
if: ${{ inputs.go-test-race }}
run: echo "GO_TEST_RACE=1" >> $GITHUB_ENV

- name: Test Go (withbootassetstesting)
if: ${{ inputs.unit-scenario == 'withbootassetstesting' }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
SKIP_DIRTY_CHECK=1 GO_BUILD_TAGS=withbootassetstesting ./run-checks --unit
- name: Set SKIP_COVERAGE=1
if: ${{ inputs.skip-coverage }}
run: echo "SKIP_COVERAGE=1" >> $GITHUB_ENV

- name: Test Go (nosecboot)
if: ${{ inputs.unit-scenario == 'nosecboot' }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
echo "Dropping github.com/snapcore/secboot"
# use govendor remove so that a subsequent govendor sync does not
# install secboot again
# ${{ github.workspace }}/bin/govendor remove github.com/snapcore/secboot
# ${{ github.workspace }}/bin/govendor remove +unused
SKIP_DIRTY_CHECK=1 GO_BUILD_TAGS=nosecboot ./run-checks --unit
- name: Test Go (faultinject)
if: ${{ inputs.unit-scenario == 'faultinject' }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
SKIP_DIRTY_CHECK=1 GO_BUILD_TAGS=faultinject ./run-checks --unit
- name: Test Go (-race)
if: ${{ inputs.unit-scenario == 'race' }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
SKIP_DIRTY_CHECK=1 GO_TEST_RACE=1 SKIP_COVERAGE=1 ./run-checks --unit
- name: Test Go (snapdusergo)
if: ${{ inputs.unit-scenario == 'snapdusergo' }}
- name: Test Go
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
SKIP_DIRTY_CHECK=1 GO_BUILD_TAGS=snapdusergo ./run-checks --unit
./run-checks --unit
- name: Upload the coverage results
if: ${{ inputs.gochannel != 'latest/stable' && inputs.unit-scenario != 'race' }}
if: ${{ ! inputs.skip-coverage }}
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: "coverage-files-${{ inputs.unit-scenario }}"
path: "${{ github.workspace }}/coverage/coverage*.cov"
name: "coverage-files-${{ inputs.go-build-tags || 'notags' }}${{ inputs.go-test-race && '-race' || ''}}${{ inputs.snapd-debug && '-snapddebug' || ''}}"
path: "${{ github.workspace }}/.coverage/coverage*.cov"
Loading

0 comments on commit 69641bd

Please sign in to comment.