From 1428c473efe0202022ce37dc7303284aafc829db Mon Sep 17 00:00:00 2001 From: Tomi Juntunen Date: Tue, 17 Oct 2023 09:49:09 +0300 Subject: [PATCH] mage command layout and CI adjustments --- .github/workflows/master.yml | 15 +++++++------- .github/workflows/pr.yml | 16 +++++++++------ .golangci.yml | 5 +++++ magefiles/mage.go | 40 +++++++++++++++++++----------------- 4 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index a7f8445..3c4d694 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -31,7 +31,7 @@ jobs: password: ${{ secrets.QUAY_TOKEN }} - name: Run unit tests - run: mage unittest + run: mage go:unittest - name: Upload test coverage to codecov uses: elisa-actions/codecov-action@v4-elisa @@ -39,20 +39,21 @@ jobs: url: https://codecov.csf.elisa.fi - name: Lint - env: - GOLANGCI_LINT_FLAGS: --out-format=github-actions - run: mage lint + run: mage go:lint + + - name: Vuln check + run: mage go:vulncheck - name: Build binary - run: mage build + run: mage go:build - name: Build image env: DOCKER_IMAGE_TAGS: sha-${{ github.sha }} - run: mage image + run: mage docker:image - name: Push image - run: mage pushImage + run: mage docker:pushImage - name: Update batch env: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c02bd18..767f811 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -21,7 +21,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Run unit tests - run: mage unittest + run: mage go:unittest - name: Upload test coverage to codecov uses: elisa-actions/codecov-action@v4-elisa @@ -29,17 +29,21 @@ jobs: url: https://codecov.csf.elisa.fi - name: Lint - env: - GOLANGCI_LINT_FLAGS: --out-format=github-actions - run: mage lint + run: mage go:lint + + - name: Vuln check + run: mage go:vulncheck + + - name: License check + run: mage go:licensecheck - name: Build binary - run: mage build + run: mage go:build - name: Build image env: DOCKER_IMAGE_TAGS: sha-${{ github.event.pull_request.head.sha }} - run: mage image + run: mage docker:image automerge: needs: [build] diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..af00016 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,5 @@ +run: + timeout: 5m + +output: + format: github-actions diff --git a/magefiles/mage.go b/magefiles/mage.go index 7221d0d..45663bc 100644 --- a/magefiles/mage.go +++ b/magefiles/mage.go @@ -7,6 +7,7 @@ import ( "os" "github.com/elisasre/mageutil" + "github.com/magefile/mage/mg" ) const ( @@ -15,47 +16,48 @@ const ( ImageName = "quay.io/elisaoyj/networkpolicy-controller" ) +type ( + Go mg.Namespace + Docker mg.Namespace + Workspace mg.Namespace +) + // Build binaries for executables under ./cmd -func Build(ctx context.Context) error { +func (Go) Build(ctx context.Context) error { return mageutil.BuildAll(ctx) } -// UnitTest whole repo -func UnitTest(ctx context.Context) error { +// UnitTest runs unit tests for whole repo +func (Go) UnitTest(ctx context.Context) error { return mageutil.UnitTest(ctx) } -// IntegrationTest whole repo -func IntegrationTest(ctx context.Context) error { - return mageutil.IntegrationTest(ctx, "./cmd/"+AppName) -} - -// Lint all go files. -func Lint(ctx context.Context) error { +// Lint runs lint for all go files +func (Go) Lint(ctx context.Context) error { return mageutil.LintAll(ctx) } -// VulnCheck all go files. -func VulnCheck(ctx context.Context) error { +// VulnCheck runs vuln check for all packages +func (Go) VulnCheck(ctx context.Context) error { return mageutil.VulnCheckAll(ctx) } -// LicenseCheck all files. -func LicenseCheck(ctx context.Context) error { +// LicenseCheck checks licences of all packages +func (Go) LicenseCheck(ctx context.Context) error { return mageutil.LicenseCheck(ctx, os.Stdout, mageutil.CmdDir+AppName) } // Clean removes all files ignored by git -func Clean(ctx context.Context) error { +func (Workspace) Clean(ctx context.Context) error { return mageutil.Clean(ctx) } -// Image creates docker image. -func Image(ctx context.Context) error { +// Image creates docker image +func (Docker) Image(ctx context.Context) error { return mageutil.DockerBuildDefault(ctx, ImageName, RepoURL) } -// PushImage creates docker image. -func PushImage(ctx context.Context) error { +// PushImage pushes docker image +func (Docker) PushImage(ctx context.Context) error { return mageutil.DockerPushAllTags(ctx, ImageName) }