mage

package module
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 0 Imported by: 0

README

github.com/coopnorge/mage

Mage CI targets

Usage

See Inventory or docs.

Development workflow

Validation
$ go tool mage validate
List other targets
$ go tool mage -l
Go module documentation preview
$ go install golang.org/x/pkgsite/cmd/pkgsite@latest
$ pkgsite

Documentation

Overview

Package mage implements Goop Norge SA's opinionated CI. Mage is used to implement the targets.

Go and Docker are the minimum requirements to run the targets provided by this Go module. The targets are designed to be imported in local magefiles in repositories. Unless specifically noted targets should work both macOS, Linux and GitHub Actions, on Windows your mileage may wary.

Provided target packages

Setup

In the root of the repository initialize a new Go modules and import this module and mage as as tool.

go mod init
go get github.com/coopnorge/mage@latest
go get -tool github.com/magefile/mage

Configure mage in magefiles/magefile.go (golib is used for the example).

import (
	//mage:import
	_ "github.com/coopnorge/mage/targets/golib"
)

In the repository add a GitHub Actions Workflow

on:
  pull_request: {}
  push:
    branches:
      - main
jobs:
  cicd:
    uses: coopnorge/mage/.github/workflows/mage.yaml@v0 # Use the latest available version
    permissions:
      contents: read
      id-token: write
      packages: read
    secrets: inherit

Run the CI targets locally

List the available targets

go tool mage -l

Run targets with

go tool mage <target>

Extend the pre-defined target packages

Exported packages with targets can be used to compose targets for repositories that contain applications written in multiple technologies.

Example

Simple use-cases import a targets packages a directly exposes it to the user using the //mage:import statement

package main

import (

	//mage:import
	_ "github.com/coopnorge/mage/targets/goapp"
)

func main() {
	// Do not declare the main function in magefiles
}
Example (Advanced)

When declaring advanced use cases Build is the only required target.

package main

import (
	"context"

	//mage:import
	"github.com/coopnorge/mage/targets/goapp"
	"github.com/magefile/mage/mg"
)

// When declaring advanced use cases Build is the only required target.
func main() {
	// Do not declare the main function in magefiles
}

// Generate files
func Generate(ctx context.Context) error {
	mg.CtxDeps(ctx, goapp.Generate)
	return nil
}

// Build creates deployable artifacts from the Go source code in the
// repository.
func Build(ctx context.Context) error {
	mg.SerialCtxDeps(ctx, goapp.Build)
	return nil
}

// Validate all code
func Validate(ctx context.Context) error {
	mg.CtxDeps(ctx, goapp.Validate)
	return nil
}

// Fix files
func Fix(ctx context.Context) error {
	mg.CtxDeps(ctx, goapp.Fix)
	return nil
}

// Clean validate and build output
func Clean(ctx context.Context) error {
	mg.CtxDeps(ctx, goapp.Clean)
	return nil
}

Directories

Path Synopsis
internal
git
pallets
Package pallets has the concern of validating pallets
Package pallets has the concern of validating pallets
targets/golang
Package golang contains targets related to golang
Package golang contains targets related to golang
goapp
Package goapp implements the [mage targets] for working with Go applications.
Package goapp implements the [mage targets] for working with Go applications.
golib
Package golib implements the [mage targets] for working with Go libraries.
Package golib implements the [mage targets] for working with Go libraries.
terraformmodule
Package goapp implements the [mage targets] for working with Go applications.
Package goapp implements the [mage targets] for working with Go applications.

Jump to

Keyboard shortcuts

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