2022-02-18 01:47:35 +00:00
|
|
|
name: tests
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- 'main'
|
|
|
|
- 'release*'
|
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- 'main'
|
|
|
|
- 'release*'
|
|
|
|
|
2022-08-23 22:02:13 +02:00
|
|
|
permissions:
|
2022-02-18 01:47:35 +00:00
|
|
|
contents: read
|
|
|
|
packages: write
|
2022-08-23 22:02:13 +02:00
|
|
|
id-token: write
|
2022-02-18 01:47:35 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
pre-checks:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2022-12-05 09:43:16 +01:00
|
|
|
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # pin@v3
|
2022-08-23 22:02:13 +02:00
|
|
|
|
2022-09-02 10:55:41 +02:00
|
|
|
- name: Unshallow
|
|
|
|
run: git fetch --prune --unshallow
|
|
|
|
|
2022-08-23 22:02:13 +02:00
|
|
|
# see https://michaelheap.com/ensure-github-actions-pinned-sha/
|
|
|
|
- name: Ensure SHA pinned actions
|
2022-12-02 13:23:12 +01:00
|
|
|
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@af2eb3226618e2494e3d9084f515ad6dcf16e229 # pin@v2.0.1
|
2022-11-15 15:08:09 +09:00
|
|
|
with:
|
|
|
|
# slsa-github-generator requires using a semver tag for reusable workflows.
|
|
|
|
# See: https://github.com/slsa-framework/slsa-github-generator#referencing-slsa-builders-and-generators
|
|
|
|
allowlist: |
|
|
|
|
slsa-framework/slsa-github-generator
|
2022-02-18 01:47:35 +00:00
|
|
|
|
2022-08-24 15:08:24 +02:00
|
|
|
- name: Setup go
|
2022-12-06 07:49:45 +01:00
|
|
|
uses: actions/setup-go@d0a58c1c4d2b25278816e339b944508c875f3613 # pin@v3
|
2022-02-18 01:47:35 +00:00
|
|
|
with:
|
2022-09-25 12:11:28 +02:00
|
|
|
go-version: ~1.18.6
|
2022-02-18 01:47:35 +00:00
|
|
|
|
2022-08-24 15:08:24 +02:00
|
|
|
- name: golangci-lint
|
2022-12-05 10:20:42 +00:00
|
|
|
uses: golangci/golangci-lint-action@0ad9a0988b3973e851ab0a07adf248ec2e100376 # pin@v3
|
2022-02-18 01:47:35 +00:00
|
|
|
with:
|
2022-08-24 15:08:24 +02:00
|
|
|
version: v1.48
|
2022-02-18 01:47:35 +00:00
|
|
|
|
|
|
|
- name: gofmt check
|
|
|
|
run: |
|
|
|
|
if [ "$(gofmt -s -l . | wc -l)" -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "The following files were found to be not go formatted:"
|
|
|
|
gofmt -s -l .
|
|
|
|
echo "Please run 'make fmt' to go format the above files."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
- name: goimports
|
|
|
|
run: |
|
2022-11-07 14:29:26 +05:30
|
|
|
go install golang.org/x/tools/cmd/goimports@f112c43328372460f7ac5bc951711609e22b01cc # v0.2.0
|
2022-02-18 01:47:35 +00:00
|
|
|
if [ "$(goimports -l . | wc -l)" -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "The following files were found to have import formatting issues:"
|
|
|
|
goimports -l -l .
|
|
|
|
echo "Please run 'make fmt' to go format the above files."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Checking unused pkgs using go mod tidy
|
|
|
|
run: |
|
|
|
|
make unused-package-check
|
|
|
|
|
2022-04-05 17:52:13 +02:00
|
|
|
- name: Go vet
|
|
|
|
run: |
|
|
|
|
make vet
|
|
|
|
|
2022-02-18 01:47:35 +00:00
|
|
|
tests:
|
2022-03-28 16:01:27 +02:00
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
2022-08-23 22:02:13 +02:00
|
|
|
autogen-internals: [ true, false ]
|
2022-02-18 01:47:35 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: pre-checks
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2022-12-05 09:43:16 +01:00
|
|
|
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # pin@v3.1.0
|
2022-02-18 01:47:35 +00:00
|
|
|
|
|
|
|
- name: Unshallow
|
|
|
|
run: git fetch --prune --unshallow
|
|
|
|
|
|
|
|
- name: Set up Go
|
2022-12-06 07:49:45 +01:00
|
|
|
uses: actions/setup-go@d0a58c1c4d2b25278816e339b944508c875f3613 # pin@v3.4.0
|
2022-02-18 01:47:35 +00:00
|
|
|
with:
|
2022-09-25 12:11:28 +02:00
|
|
|
go-version: ~1.18.6
|
2022-02-18 01:47:35 +00:00
|
|
|
|
|
|
|
- name: Cache Go modules
|
2022-12-05 08:58:10 +01:00
|
|
|
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # pin@v3
|
2022-02-18 01:47:35 +00:00
|
|
|
with:
|
2022-09-01 19:41:48 +02:00
|
|
|
path: |
|
|
|
|
~/.cache/go-build
|
|
|
|
~/go/pkg/mod
|
2022-02-18 01:47:35 +00:00
|
|
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-go-
|
|
|
|
|
|
|
|
- name: Kyverno unit test
|
|
|
|
run: |
|
|
|
|
export PROJECT_PATH=$(pwd)
|
2022-03-28 16:01:27 +02:00
|
|
|
export FLAG_AUTOGEN_INTERNALS=${{ matrix.autogen-internals }}
|
2022-02-18 01:47:35 +00:00
|
|
|
make test-unit
|