Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mage command layout and CI adjustments #118

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,29 @@ 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
with:
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:
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,29 @@ 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
with:
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]
Expand Down
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
run:
timeout: 5m

output:
format: github-actions
40 changes: 21 additions & 19 deletions magefiles/mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

"github.com/elisasre/mageutil"
"github.com/magefile/mage/mg"
)

const (
Expand All @@ -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)
}