mageutil

package module
v1.5.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

README

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.

Documentation

Overview

package mageutil provides util functions for Magefile. For usage please refer to documentation provided by Magefile. For autocompletions see completions.

Index

Constants

View Source
const (
	OCILabelTitle       = docker.OCILabelTitle
	OCILabelURL         = docker.OCILabelURL
	OCILabelVersion     = docker.OCILabelVersion
	OCILabelDescription = docker.OCILabelDescription
	OCILabelCreated     = docker.OCILabelCreated
	OCILabelSource      = docker.OCILabelSource
	OCILabelLicenses    = docker.OCILabelLicenses
	OCILabelAuthors     = docker.OCILabelAuthors
	OCILabelVendor      = docker.OCILabelVendor
	OCILabelRevision    = docker.OCILabelRevision
)
View Source
const (
	DefaultPlatform   = docker.DefaultPlatform
	DefaultDockerfile = docker.DefaultDockerfile
	DefaultBuildCtx   = docker.DefaultBuildCtx
	DefaultExtraCtx   = docker.DefaultExtraCtx
)
View Source
const (
	CmdDir     = "./cmd/"
	TargetDir  = "./target/"
	ReportsDir = TargetDir + "reports/"
)
View Source
const (
	UnitCoverProfile        = ReportsDir + "unit-test-coverage.out"
	IntegrationCoverProfile = ReportsDir + "integration-test-coverage.out"
	MergedCoverProfile      = ReportsDir + "merged-test-coverage.out"
)
View Source
const (
	UNKNOWN = "Unknown"
)

Variables

This section is empty.

Functions

func AwsVault deprecated added in v1.3.0

func AwsVault(ctx context.Context, args ...string) error

Deprecated: use sub package.

func AwsVaultCredentials deprecated added in v1.3.0

func AwsVaultCredentials(ctx context.Context, awsProfile string) (aws.Credentials, error)

Deprecated: use sub package.

func AwsVaultEnv deprecated added in v1.3.0

func AwsVaultEnv(ctx context.Context, awsProfile string) (map[string]string, error)

Deprecated: use sub package.

func AwsVaultExec deprecated added in v1.3.0

func AwsVaultExec(ctx context.Context, awsProfile string, args ...string) error

Deprecated: use sub package.

func AwsWithEnvCredentials deprecated added in v1.3.0

func AwsWithEnvCredentials(ctx context.Context, awsProfile string, fn func() error) error

Deprecated: use sub package.

func BinDir deprecated

func BinDir() (string, error)

Deprecated: use sub package.

func Build deprecated

func Build(ctx context.Context, name string) error

Deprecated: use sub package.

func BuildAll deprecated

func BuildAll(ctx context.Context) error

Deprecated: use sub package.

func BuildFor deprecated

func BuildFor(ctx context.Context, goos, goarch, name string) error

Deprecated: use sub package.

func BuildForArmMac deprecated

func BuildForArmMac(ctx context.Context, name string)

Deprecated: use sub package.

func BuildForLinux deprecated

func BuildForLinux(ctx context.Context, name string)

Deprecated: use sub package.

func BuildForMac deprecated

func BuildForMac(ctx context.Context, name string)

Deprecated: use sub package.

func BuildForWindows deprecated

func BuildForWindows(ctx context.Context, name string)

Deprecated: use sub package.

func BuildWithSHA deprecated

func BuildWithSHA(ctx context.Context, goos, goarch, name string)

Deprecated: use sub package.

func CGO

func CGO(enabled bool)

CGO can be used to enable of disable CGO. By default this package will disable CGO.

func Clean deprecated

func Clean(ctx context.Context) error

Deprecated: use sub package.

func CoverInfo deprecated

func CoverInfo(ctx context.Context, profile string) error

Deprecated: use sub package.

func DefaultLabels deprecated

func DefaultLabels(imageName, url, desc string) map[string]string

Deprecated: use sub package.

func Docker deprecated

func Docker(ctx context.Context, args ...string) error

Deprecated: use sub package.

func DockerBuild deprecated

func DockerBuild(ctx context.Context, platform, dockerfile, buildCtx string, tags []string, extraCtx, labels map[string]string) error

Deprecated: use sub package.

func DockerBuildDefault deprecated

func DockerBuildDefault(ctx context.Context, imageName, url string) error

Deprecated: use sub package.

func DockerPushAllTags deprecated

func DockerPushAllTags(ctx context.Context, imageName string) error

Deprecated: use sub package.

func DockerTags deprecated

func DockerTags(imageName string, tags ...string) []string

Deprecated: use sub package.

func Ensure deprecated added in v1.1.0

func Ensure(ctx context.Context) error

Deprecated: use sub package.

func EnsureInSync deprecated added in v1.1.0

func EnsureInSync(ctx context.Context) error

Deprecated: use sub package.

func Git deprecated

func Git(ctx context.Context, args ...string) error

Deprecated: use sub package.

func Go deprecated

func Go(ctx context.Context, args ...string) error

Deprecated: use sub package.

func GoList deprecated

func GoList(ctx context.Context, target string) ([]string, error)

Deprecated: use sub package.

func GoWith deprecated

func GoWith(ctx context.Context, env map[string]string, args ...string) error

Deprecated: use sub package.

func GolangCILint deprecated

func GolangCILint(ctx context.Context, args ...string) error

Deprecated: use sub package.

func IntegrationTest deprecated

func IntegrationTest(ctx context.Context, pkg string) error

Deprecated: use sub package.

func LicenseCheck deprecated

func LicenseCheck(ctx context.Context, w io.Writer, targets ...string) error

Deprecated: use sub package. LicenseCheck runs github.com/google/go-licenses/licenses for given targets and writes toe output into w.

func LintAll deprecated

func LintAll(ctx context.Context) error

Deprecated: use sub package.

func MergeCover deprecated

func MergeCover(ctx context.Context, coverFiles []string, w io.Writer) error

Deprecated: use sub package.

func MergeCoverProfiles deprecated

func MergeCoverProfiles(ctx context.Context) error

Deprecated: use sub package.

func MustSetEnv

func MustSetEnv(k, v string)

func Npm deprecated added in v1.2.0

func Npm(ctx context.Context, args ...string) error

Deprecated: use sub package.

func NpmCleanInstall deprecated added in v1.2.0

func NpmCleanInstall(ctx context.Context) error

Deprecated: use sub package.

func NpmInstall deprecated added in v1.2.0

func NpmInstall(ctx context.Context) error

Deprecated: use sub package.

func NpmRun deprecated added in v1.2.0

func NpmRun(ctx context.Context, args ...string) error

Deprecated: use sub package.

func NpmUpdate deprecated added in v1.2.0

func NpmUpdate(ctx context.Context) error

Deprecated: use sub package.

func NpmWith deprecated added in v1.2.0

func NpmWith(_ context.Context, env map[string]string, args ...string) error

Deprecated: use sub package.

func Run deprecated

func Run(ctx context.Context, name string, args ...string) error

Deprecated: use sub package.

func SHA256Sum

func SHA256Sum(ctx context.Context, name string) error

SHA256Sum calculates sum for single file and stores it in file. Output should be compatible with sha256sum program.

func SopsDecryptFile deprecated added in v1.3.0

func SopsDecryptFile(ctx context.Context, file string) ([]byte, error)

Deprecated: use sub package.

func SopsDecryptWithAwsEnv deprecated added in v1.3.0

func SopsDecryptWithAwsEnv(ctx context.Context, file, profile string) ([]byte, error)

Deprecated: use sub packages.

func SwaggerDocs deprecated

func SwaggerDocs(ctx context.Context, searchDir, apiFile, outputDir string) error

Deprecated: use sub package.

func SwaggerDocsWithConf deprecated

func SwaggerDocsWithConf(ctx context.Context, conf gen.Config) error

Deprecated: use sub package.

func Targets deprecated

func Targets(ctx context.Context) ([]string, error)

Deprecated: use sub package.

func Tidy deprecated added in v1.2.0

func Tidy(ctx context.Context) error

Deprecated: use sub package.

func TidyAndVerifyNoChanges deprecated added in v1.2.0

func TidyAndVerifyNoChanges(ctx context.Context) error

Deprecated: use sub package.

func UnitTest deprecated

func UnitTest(ctx context.Context) error

Deprecated: use sub package.

func Verbose

func Verbose(enabled bool)

Verbose can be used to control mage's verbose state. By default this package will set mage in verbose state.

func VulnCheck deprecated

func VulnCheck(ctx context.Context, args ...string) error

Deprecated: use sub package.

func VulnCheckAll deprecated

func VulnCheckAll(ctx context.Context) error

Deprecated: use sub package.

func YamlFmt deprecated added in v1.2.0

func YamlFmt(ctx context.Context, paths ...string) error

Deprecated: use sub package.

func YamlLint deprecated added in v1.2.0

func YamlLint(ctx context.Context, paths ...string) error

Deprecated: use sub package.

func YamlOperationWithDefaultConfig deprecated added in v1.2.0

func YamlOperationWithDefaultConfig(ctx context.Context, op command.Operation, paths ...string) error

Deprecated: use sub package.

Types

type BuildInfo added in v1.2.0

type BuildInfo struct {
	BinPath string
	GOOS    string
	GOARCH  string
}

BuildInfo contains relevant information about produced binary.

func BuildForArmMacWithInfo deprecated added in v1.2.0

func BuildForArmMacWithInfo(ctx context.Context, name string) (BuildInfo, error)

Deprecated: use sub package.

func BuildForLinuxWithInfo deprecated added in v1.2.0

func BuildForLinuxWithInfo(ctx context.Context, name string) (BuildInfo, error)

Deprecated: use sub package.

func BuildForMacWithInfo deprecated added in v1.2.0

func BuildForMacWithInfo(ctx context.Context, name string) (BuildInfo, error)

Deprecated: use sub package.

func BuildForWindowsWithInfo deprecated added in v1.2.0

func BuildForWindowsWithInfo(ctx context.Context, name string) (BuildInfo, error)

Deprecated: use sub package.

func BuildForWithInfo deprecated added in v1.2.0

func BuildForWithInfo(ctx context.Context, goos, goarch, name string) (BuildInfo, error)

Deprecated: use sub package.

func BuildWithInfo deprecated added in v1.2.0

func BuildWithInfo(ctx context.Context, name string) (BuildInfo, error)

Deprecated: use sub package.

func BuildWithSHAWithInfo deprecated added in v1.2.0

func BuildWithSHAWithInfo(ctx context.Context, goos, goarch, name string) (BuildInfo, error)

Deprecated: use sub package.

type NpmCmd added in v1.2.0

type NpmCmd func(ctx context.Context, args ...string) error

func NewNpmCmd deprecated added in v1.2.0

func NewNpmCmd(args ...string) NpmCmd

Deprecated: use sub package.

func (NpmCmd) Audit deprecated added in v1.2.0

func (npm NpmCmd) Audit(ctx context.Context) error

Deprecated: use sub package.

func (NpmCmd) CleanInstall deprecated added in v1.2.0

func (npm NpmCmd) CleanInstall(ctx context.Context) error

Deprecated: use sub package.

func (NpmCmd) Install deprecated added in v1.2.0

func (npm NpmCmd) Install(ctx context.Context) error

Deprecated: use sub package.

func (NpmCmd) Npm deprecated added in v1.2.0

func (npm NpmCmd) Npm(ctx context.Context, args ...string) error

Deprecated: use sub package.

func (NpmCmd) Run deprecated added in v1.2.0

func (npm NpmCmd) Run(ctx context.Context, args ...string) error

Deprecated: use sub package.

func (NpmCmd) Update deprecated added in v1.2.0

func (npm NpmCmd) Update(ctx context.Context) error

Deprecated: use sub package.

Directories

Path Synopsis
Package awsvault exposes github.com/99designs/aws-vault as library.
Package awsvault exposes github.com/99designs/aws-vault as library.
cdk
target
Package target exposes cdk targets that can be imported in magefile using [import syntax].
Package target exposes cdk targets that can be imported in magefile using [import syntax].
target
Package target exposes docker targets that can be imported in magefile using [import syntax].
Package target exposes docker targets that can be imported in magefile using [import syntax].
git
Package git exposes git command.
Package git exposes git command.
package golang provides util functions for managing Go project with Go.
package golang provides util functions for managing Go project with Go.
target
Package target exposes Go targets that can be imported in magefile using [import syntax].
Package target exposes Go targets that can be imported in magefile using [import syntax].
target
Package target exposes golanci-lint targets that can be imported in magefile using [import syntax].
Package target exposes golanci-lint targets that can be imported in magefile using [import syntax].
Package golicenses exposes github.com/google/go-licenses/licenses as library.
Package golicenses exposes github.com/google/go-licenses/licenses as library.
target
Package target exposes golicenses targets that can be imported in magefile using [import syntax].
Package target exposes golicenses targets that can be imported in magefile using [import syntax].
Package govulncheck exposes golang.org/x/vuln/scan as library.
Package govulncheck exposes golang.org/x/vuln/scan as library.
target
Package target exposes govulncheck targets that can be imported in magefile using [import syntax].
Package target exposes govulncheck targets that can be imported in magefile using [import syntax].
target
Package target exposes Lambda targets that can be imported in magefile using [import syntax].
Package target exposes Lambda targets that can be imported in magefile using [import syntax].
npm
Package npm exposes npm functionality as library.
Package npm exposes npm functionality as library.
target
Package target exposes npm targets that can be imported in magefile using [import syntax].
Package target exposes npm targets that can be imported in magefile using [import syntax].
Package sops provides sops decrypting functionality.
Package sops provides sops decrypting functionality.
Package swaggo exposes openapi tools as library with sane defaults.
Package swaggo exposes openapi tools as library with sane defaults.
target
Package target exposes swaggo targets that can be imported in magefile using [import syntax].
Package target exposes swaggo targets that can be imported in magefile using [import syntax].
Package yamlfmt exposes yaml formatting functionality as library with sane defaults.
Package yamlfmt exposes yaml formatting functionality as library with sane defaults.
target
Package target exposes yaml targets that can be imported in magefile using [import syntax].
Package target exposes yaml targets that can be imported in magefile using [import syntax].

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL