Skip to content

elisasre/mageutil

Folders and files

NameName
Last commit message
Last commit date
Dec 3, 2024
Nov 15, 2023
Nov 14, 2024
Nov 9, 2023
Nov 14, 2024
Jan 11, 2025
Nov 14, 2024
Mar 10, 2025
Nov 14, 2024
Nov 14, 2024
Nov 14, 2024
Nov 14, 2024
Nov 16, 2023
Nov 14, 2024
Dec 2, 2024
Nov 14, 2024
Oct 30, 2024
Sep 28, 2023
Oct 5, 2023
Apr 4, 2024
Sep 28, 2023
Mar 21, 2025
Mar 21, 2025
Nov 14, 2024

Repository files navigation

mageutil

Go Reference build

Mageutil provides ready made targets and helper functions for Magefile. For usage please refer to documentation provided by Magefile. For autocompletions see completions.

Example

Example magefile:

//go:build mage

package main

import (
	"os"

	"github.com/magefile/mage/mg"

	//mage:import
	_ "github.com/elisasre/mageutil/git/target"
	//mage:import
	_ "github.com/elisasre/mageutil/golangcilint/target"
	//mage:import
	_ "github.com/elisasre/mageutil/golicenses/target"
	//mage:import
	docker "github.com/elisasre/mageutil/docker/target"
	//mage:import
	golang "github.com/elisasre/mageutil/golang/target"
)

// Configure imported targets
func init() {
	os.Setenv(mg.VerboseEnv, "1")
	os.Setenv("CGO_ENABLED", "0")

	golang.BuildTarget = "./cmd/myapp"
	golang.RunArgs = []string{"--loglevel", "0", "--development", "true"}
	docker.ImageName = "docker.io/myorg/myapp"
	docker.ProjectUrl = "https://github.com/myorg/myapp"
}

Output with example magefile:

$ mage

Targets:
  docker:build          builds docker image
  docker:push           pushes all tags for image
  git:clean             removes all untracked files from workspace
  go:build              build binary and calculate sha sum for it
  go:coverProfile       convert binary coverage into text format
  go:crossBuild         build binary for build matrix
  go:integrationTest    run integration tests
  go:licenses           reports licenses used by dependencies
  go:lint               runs golangci-lint for all go files.
  go:run                build binary and execute it
  go:test               run unit and integration tests
  go:tidy               run go mod tidy
  go:tidyAndVerify      verify that go.mod matches imports
  go:unitTest           run all unit tests
  go:viewCoverage       open test coverage in browser

Integration tests

Running mage go:integrationTest has couple expectations from test code:

  1. Test files must be placed under ./integrationtests
  2. Test must produce coverage files in binary format
  3. Coverage files must be placed under ./target/tests/cover/int/

To comply with these rules library like this could be used.