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-08-24 15:08:24 +02:00
|
|
|
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v3
|
2022-08-23 22:02:13 +02:00
|
|
|
|
|
|
|
# see https://michaelheap.com/ensure-github-actions-pinned-sha/
|
|
|
|
- name: Ensure SHA pinned actions
|
|
|
|
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@6ca5574367befbc9efdb2fa25978084159c5902d # pin@v1.3.0
|
2022-02-18 01:47:35 +00:00
|
|
|
|
2022-08-24 15:08:24 +02:00
|
|
|
- name: Setup go
|
|
|
|
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # pin@v3
|
2022-02-18 01:47:35 +00:00
|
|
|
with:
|
|
|
|
go-version: 1.17
|
|
|
|
|
2022-08-24 15:08:24 +02:00
|
|
|
- name: golangci-lint
|
|
|
|
uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc # 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-08-24 15:38:49 +02:00
|
|
|
go install golang.org/x/tools/cmd/goimports@latest
|
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-03-07 10:43:36 +01:00
|
|
|
- name: Verify generated code is up to date
|
|
|
|
run: make verify-codegen
|
|
|
|
|
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-08-23 22:02:13 +02:00
|
|
|
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # pin@v2.4.0
|
2022-02-18 01:47:35 +00:00
|
|
|
|
|
|
|
- name: Unshallow
|
|
|
|
run: git fetch --prune --unshallow
|
|
|
|
|
|
|
|
- name: Set up Go
|
2022-08-23 22:02:13 +02:00
|
|
|
uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 # pin@v2.1.5
|
2022-02-18 01:47:35 +00:00
|
|
|
with:
|
|
|
|
go-version: 1.17
|
|
|
|
|
|
|
|
- name: Cache Go modules
|
2022-08-23 22:02:13 +02:00
|
|
|
uses: actions/cache@d9747005de0f7240e5d35a68dca96b3f41b8b340 # pin@v1.2.0
|
2022-02-18 01:47:35 +00:00
|
|
|
with:
|
|
|
|
path: ~/go/pkg/mod
|
|
|
|
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
|