mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
d6c0ea01e3
Signed-off-by: ShutingZhao <shuting@nirmata.com> Signed-off-by: ShutingZhao <shuting@nirmata.com>
108 lines
3.1 KiB
YAML
108 lines
3.1 KiB
YAML
name: tests
|
|
on:
|
|
push:
|
|
branches:
|
|
- 'main'
|
|
- 'release*'
|
|
pull_request:
|
|
branches:
|
|
- 'main'
|
|
- 'release*'
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
id-token: write
|
|
|
|
jobs:
|
|
pre-checks:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
|
|
|
|
- name: Unshallow
|
|
run: git fetch --prune --unshallow
|
|
|
|
# see https://michaelheap.com/ensure-github-actions-pinned-sha/
|
|
- name: Ensure SHA pinned actions
|
|
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@af2eb3226618e2494e3d9084f515ad6dcf16e229 # pin@v2.0.1
|
|
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
|
|
|
|
- name: Setup go
|
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
|
with:
|
|
go-version: ~1.19.4
|
|
|
|
- name: golangci-lint
|
|
uses: golangci/golangci-lint-action@0ad9a0988b3973e851ab0a07adf248ec2e100376 # pin@v3
|
|
with:
|
|
version: v1.48
|
|
|
|
- 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: |
|
|
go install golang.org/x/tools/cmd/goimports@f112c43328372460f7ac5bc951711609e22b01cc # v0.2.0
|
|
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
|
|
|
|
- name: Go vet
|
|
run: |
|
|
make vet
|
|
|
|
tests:
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
autogen-internals: [ true, false ]
|
|
runs-on: ubuntu-latest
|
|
needs: pre-checks
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
|
|
|
|
- name: Unshallow
|
|
run: git fetch --prune --unshallow
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
|
with:
|
|
go-version: ~1.19.4
|
|
|
|
- name: Cache Go modules
|
|
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # pin@v3
|
|
with:
|
|
path: |
|
|
~/.cache/go-build
|
|
~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-go-
|
|
|
|
- name: Kyverno unit test
|
|
run: |
|
|
export PROJECT_PATH=$(pwd)
|
|
export FLAG_AUTOGEN_INTERNALS=${{ matrix.autogen-internals }}
|
|
make test-unit
|