Skip to content

Commit

Permalink
tests: update actions versions to avoid warnings in prs github summary (
Browse files Browse the repository at this point in the history
canonical#14402)

* Update actions versions to avoid warnings in prs github summary

For each pr we have too many warnings, mostrly caused because we are not
using the latest actions.

* Fix issue related to coverage files not being uploded

Those logs fail to be uploaded when they are saved in a hidden directory
(bug in the action)

* update the directory used to save coverage files

* Update variables in run-checks

* Addimg more logs to see how coverage is executed

* saving coverage to ${{ github.workspace }}/coverage/coverage.cov

* skip race scenario from sending coverage

* Showing coverage params used

* Fix if condition to upload unit test coverage

* fix check for stable

* add race scenario to test coverage

* change the name of the coverage file uploaded

* update also normal scenario

* fix normal scenario

* skip test coverage for race scenario

This is causing multible race coditions.

* fix how code coverage is merged in "Download the coverage files"

* use codecov v4
  • Loading branch information
sergiocazzolato authored Sep 21, 2024
1 parent 848d437 commit dc801d0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 38 deletions.
63 changes: 34 additions & 29 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- test
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
fi
- name: Uploading snapd snap artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: snap-files-${{ matrix.toolchain }}-${{ matrix.version }}
path: "*.snap"
Expand All @@ -86,7 +86,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# needed for git commit history
fetch-depth: 0
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
sudo tar cvf cached-apt.tar /var/cache/apt
- name: upload Debian dependencies
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: debian-dependencies
path: ./cached-apt.tar
Expand Down Expand Up @@ -143,7 +143,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# needed for git commit history
fetch-depth: 0
Expand All @@ -158,7 +158,7 @@ jobs:
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
- name: Download Debian dependencies
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: debian-dependencies
path: ./debian-deps/
Expand Down Expand Up @@ -216,7 +216,7 @@ jobs:
- name: Cache prebuilt indent
id: cache-indent-bin
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: indent-bin
key: ${{ runner.os }}-indent-2.2.13
Expand Down Expand Up @@ -259,7 +259,7 @@ jobs:
steps:

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# needed for git commit history
fetch-depth: 0
Expand Down Expand Up @@ -296,7 +296,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# needed for git commit history
fetch-depth: 0
Expand All @@ -311,7 +311,7 @@ jobs:
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
- name: Download Debian dependencies
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: debian-dependencies
path: ./debian-deps/
Expand Down Expand Up @@ -352,6 +352,8 @@ jobs:
- name: Reset code coverage data
run: |
rm -rf ${{ github.workspace }}/.coverage/
COVERAGE_OUT="${{ github.workspace }}/coverage/coverage-${{ matrix.unit-scenario}}.cov"
echo "COVERAGE_OUT=$COVERAGE_OUT" >> $GITHUB_ENV
- name: Test Go
if: ${{ matrix.unit-scenario == 'normal' }}
Expand All @@ -361,11 +363,11 @@ jobs:
- name: Upload the coverage results
if: ${{ matrix.gochannel != 'latest/stable' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: coverage-files
path: "${{ github.workspace }}/src/github.com/snapcore/snapd/.coverage/coverage*.cov"
name: "coverage-files-${{ matrix.unit-scenario }}"
path: "${{ github.workspace }}/coverage/coverage*.cov"

# TODO run unit tests of C code
unit-tests-special:
Expand Down Expand Up @@ -395,7 +397,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# needed for git commit history
fetch-depth: 0
Expand All @@ -410,7 +412,7 @@ jobs:
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
- name: Download Debian dependencies
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: debian-dependencies
path: ./debian-deps/
Expand Down Expand Up @@ -451,6 +453,8 @@ jobs:
- name: Reset code coverage data
run: |
rm -rf ${{ github.workspace }}/.coverage/
COVERAGE_OUT="${{ github.workspace }}/coverage/coverage-${{ matrix.unit-scenario}}.cov"
echo "COVERAGE_OUT=$COVERAGE_OUT" >> $GITHUB_ENV
- name: Test Go (SNAPD_DEBUG=1)
if: ${{ matrix.unit-scenario == 'snapd_debug' }}
Expand Down Expand Up @@ -488,12 +492,12 @@ jobs:
SKIP_DIRTY_CHECK=1 GO_TEST_RACE=1 SKIP_COVERAGE=1 ./run-checks --unit
- name: Upload the coverage results
if: ${{ matrix.gochannel != 'latest/stable' }}
uses: actions/upload-artifact@v3
if: ${{ matrix.gochannel != 'latest/stable' && matrix.unit-scenario != 'race' }}
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: coverage-files
path: "${{ github.workspace }}/src/github.com/snapcore/snapd/.coverage/coverage*.cov"
name: "coverage-files-${{ matrix.unit-scenario }}"
path: "${{ github.workspace }}/coverage/coverage*.cov"


unit-tests-cross-distro:
Expand Down Expand Up @@ -572,13 +576,14 @@ jobs:
GOROOT: ""
steps:
- name: Download the coverage files
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: coverage-files
pattern: coverage-files-*
path: .coverage/
merge-multiple: true

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
# uploading to codecov occasionally fails, so continue running the test
# workflow regardless of the upload
continue-on-error: true
Expand Down Expand Up @@ -745,7 +750,7 @@ jobs:
mkdir "${{ github.workspace }}"
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# spread uses tags as delta reference
fetch-depth: 0
Expand All @@ -757,7 +762,7 @@ jobs:
shell: bash

- name: Get previous cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: "${{ github.workspace }}/.test-results"
key: "${{ github.job }}-results-${{ github.run_id }}-${{ matrix.group }}-${{ steps.get-previous-attempt.outputs.previous_attempt }}"
Expand Down Expand Up @@ -842,7 +847,7 @@ jobs:
echo "GRAFANA START: pr ${CHANGE_ID} attempt ${{ github.run_attempt }} run ${{ github.run_id }} group ${{ matrix.group }}" > "$FILTERED_LOG_FILE"
- name: Download built snap
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
if: "!endsWith(matrix.group, '-fips')"
with:
name: snap-files-default-test
Expand All @@ -851,7 +856,7 @@ jobs:
path: "${{ github.workspace }}/built-snap"

- name: Download built FIPS snap
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
# eg. ubuntu-fips
if: "endsWith(matrix.group, '-fips')"
with:
Expand Down Expand Up @@ -918,13 +923,13 @@ jobs:
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)
- name: Uploading spread logs
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: spread-logs-${{ matrix.systems }}
path: "spread-logs/*.log"
if-no-files-found: ignore

- name: Discard spread workers
if: always()
Expand Down Expand Up @@ -975,7 +980,7 @@ jobs:
- name: Save spread test results to cache
if: always()
uses: actions/cache/save@v3
uses: actions/cache/save@v4
with:
path: "${{ github.workspace }}/.test-results"
key: "${{ github.job }}-results-${{ github.run_id }}-${{ matrix.group }}-${{ github.run_attempt }}"
19 changes: 10 additions & 9 deletions run-checks
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ if [ "$STATIC" = 1 ]; then
./tests/lib/external/snapd-testing-tools/utils/spread-shellcheck $FILTERED_FILES --exclude "$exclude_tools_path" --exclude "tests/nested/manual/core20-preseed"
fi

if [ -z "${SKIP_MISSPELL-}" ]; then
if [ -z "${SKIP_MISSPELL:-}" ]; then
echo "Checking spelling errors"
if ! command -v misspell >/dev/null; then
goinstall github.com/client9/misspell/cmd/misspell
Expand All @@ -309,7 +309,7 @@ if [ "$STATIC" = 1 ]; then
xargs -0 misspell -error -i "$MISSPELL_IGNORE"
fi

if [ -z "${SKIP_INEFFASSIGN-}" ]; then
if [ -z "${SKIP_INEFFASSIGN:-}" ]; then
if dpkg --compare-versions "$(go version | awk '$3 ~ /^go[0-9]/ {print substr($3, 3)}')" ge 1.12; then
echo "Checking for ineffective assignments"
if ! command -v ineffassign >/dev/null; then
Expand Down Expand Up @@ -357,7 +357,7 @@ if [ "$STATIC" = 1 ]; then

# FIXME: re-add staticcheck with a matching version for the used go-version

if [ -z "${SKIP_TESTS_FORMAT_CHECK-}" ] || [ "$SKIP_TESTS_FORMAT_CHECK" = 0 ]; then
if [ -z "${SKIP_TESTS_FORMAT_CHECK:-}" ] || [ "$SKIP_TESTS_FORMAT_CHECK" = 0 ]; then
CHANGED_TESTS=""
FILTERED_TESTS=""
EXCLUDE_PATH=tests/lib/external/snapd-testing-tools
Expand Down Expand Up @@ -394,7 +394,7 @@ if [ "$STATIC" = 1 ]; then
exit 1
fi

if [ -z "${SKIP_GOLANGCI_LINT-}" ]; then
if [ -z "${SKIP_GOLANGCI_LINT:-}" ]; then

echo "Checking installation of golangci-lint"
gcil="$(command -v golangci-lint || true)"
Expand Down Expand Up @@ -439,11 +439,11 @@ if [ "$UNIT" = 1 ]; then

tags=
race=
if [ -n "${GO_BUILD_TAGS-}" ]; then
if [ -n "${GO_BUILD_TAGS:-}" ]; then
echo "Using build tags: $GO_BUILD_TAGS"
tags="-tags $GO_BUILD_TAGS"
fi
if [ -n "${GO_TEST_RACE-}" ]; then
if [ -n "${GO_TEST_RACE:-}" ]; then
echo "Using go test -race"
race="-race"
fi
Expand All @@ -455,15 +455,16 @@ if [ "$UNIT" = 1 ]; then
# tests
echo Running tests from "$PWD"
if [ "$short" = 1 ]; then
echo "Running without test coverage"
# shellcheck disable=SC2046,SC2086
GOTRACEBACK=1 $goctest $tags $race -short -timeout 5m $(go list ./... | grep -v '/vendor/' )
else
coverage=""
if [ -z "${SKIP_COVERAGE-}" ]; then
if [ -z "${SKIP_COVERAGE:-}" ]; then
coverage="-coverprofile=$COVERAGE_OUT -covermode=$COVERMODE"
# Prepare the coverage output profile.
mkdir -p "$(dirname "$COVERAGE_OUT")"
echo "mode: $COVERMODE" > "$COVERAGE_OUT"
echo "Using coverage params: $coverage"
else
echo "Skipping test coverage"
fi
Expand Down Expand Up @@ -492,7 +493,7 @@ EOF
exit 1
fi

if [ -n "${SKIP_DIRTY_CHECK-}" ]; then
if [ -n "${SKIP_DIRTY_CHECK:-}" ]; then
exit 0
fi

Expand Down

0 comments on commit dc801d0

Please sign in to comment.