From 496d7334f59a501e95a0c16ac7f8bdbf1eafd406 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Fri, 24 Jun 2022 11:29:50 -0500 Subject: [PATCH] Add ConfigureAgent magefile target Make it easier for mixins to know what should be in their magefile by adding ConfigureAgent. Everything a mixin should be doing should have a corresponding target on the mixin.Magefile struct so it's easy to find. Signed-off-by: Carolyn Van Slyck --- mixins/magefile.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/mixins/magefile.go b/mixins/magefile.go index 239a2fe..6998734 100644 --- a/mixins/magefile.go +++ b/mixins/magefile.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" + "get.porter.sh/magefiles/ci" "get.porter.sh/magefiles/porter" "get.porter.sh/magefiles/releases" "github.com/carolynvs/magex/mgx" @@ -19,26 +20,31 @@ type Magefile struct { BinDir string } -// Create a magefile helper for a mixin +// NewMagefile creates a magefile helper for a mixin func NewMagefile(pkg, mixinName, binDir string) Magefile { return Magefile{Pkg: pkg, MixinName: mixinName, BinDir: binDir} } var must = shx.CommandBuilder{StopOnError: true} +// ConfigureAgent sets up a CI worker to use Go and mage. +func (m Magefile) ConfigureAgent() { + mgx.Must(ci.ConfigureAgent()) +} + // Build the mixin func (m Magefile) Build() { must.RunV("go", "mod", "tidy") releases.BuildAll(m.Pkg, m.MixinName, m.BinDir) } -// Cross-compile the mixin before a release +// XBuildAll cross-compiles the mixin before a release func (m Magefile) XBuildAll() { releases.XBuildAll(m.Pkg, m.MixinName, m.BinDir) releases.PrepareMixinForPublish(m.MixinName) } -// Run unit tests +// TestUnit runs unit tests func (m Magefile) TestUnit() { v := "" if mg.Verbose() { @@ -47,7 +53,7 @@ func (m Magefile) TestUnit() { must.Command("go", "test", v, "./pkg/...").CollapseArgs().RunV() } -// Run all tests +// Test runs a full suite of tests func (m Magefile) Test() { m.TestUnit() @@ -61,7 +67,7 @@ func (m Magefile) Publish() { mg.SerialDeps(m.PublishBinaries, m.PublishMixinFeed) } -// Publish binaries to a github release +// PublishBinaries uploads cross-compiled binaries to a GitHub release // Requires PORTER_RELEASE_REPOSITORY to be set to github.com/USERNAME/REPO func (m Magefile) PublishBinaries() { mg.SerialDeps(porter.UseBinForPorterHome, porter.EnsurePorter) @@ -76,8 +82,9 @@ func (m Magefile) PublishMixinFeed() { releases.PublishMixinFeed(m.MixinName) } -// Test out publish locally, with your github forks -// Assumes that you forked and kept the repository name unchanged. +// TestPublish uploads release artifacts to a fork of the mixin's repo. +// If your mixin is official hosted in a repository under your username, you will need to manually +// override PORTER_RELEASE_REPOSITORY and PORTER_PACKAGES_REMOTE to test out publishing safely. func (m Magefile) TestPublish(username string) { mixinRepo := fmt.Sprintf("github.com/%s/%s-mixin", username, m.MixinName) pkgRepo := fmt.Sprintf("https://github.com/%s/packages.git", username) @@ -99,7 +106,7 @@ func (m Magefile) Install() { mgx.Must(shx.Copy(filepath.Join(m.BinDir, "runtimes", m.MixinName+"-runtime"+xplat.FileExt()), filepath.Join(porterHome, "mixins", m.MixinName, "runtimes"))) } -// Remove generated build files +// Clean removes generated build files func (m Magefile) Clean() { os.RemoveAll("bin") }