Skip to content

Commit

Permalink
Fix publish target (#45)
Browse files Browse the repository at this point in the history
* Fix publish target

I have converted the repository from make to mage, and from azure devops
pipelines to github actions. I figured as long as I was here fixing our
broken build, lets just finish moving over to where we want to be.

The problem with the publish target was a few things. One there was a
bug in the magefiles generatePackageFeed function, where it wasn't
checking the error when calling porter to generate the atom.xml file for
the feed. Porter wasn't installed, and it was quietly failing.

We are now using a fixed version of the magefiles repo, and installing
porter into bin before attempting to publish.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>

* Bump magefiles to v0.2.3

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>

* Use target.Dir instead of target.Path

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
  • Loading branch information
carolynvs committed May 24, 2022
1 parent 6dd7cd7 commit e9aeee3
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 129 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: build
on: [workflow_dispatch, push, pull_request]

env:
# Make mage super verbose ALL THE TIME
MAGEFILE_VERBOSE: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
check-latest: true
- name: Configure Agent
run: go run mage.go ConfigureAgent
- name: Build
run: mage Build
- name: Test
run: mage Test
- name: Cross Compile
run: mage XBuildAll
- name: Publish
if: ${{ github.event_name == 'push' }}
run: mage Publish
env:
GITHUB_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/azure
.DS_Store
/build/git_askpass.sh
tests/integration/testdata/.cnab
22 changes: 16 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ project.
---

* [Initial setup](#initial-setup)
* [Makefile explained](#makefile-explained)
* [Magefile explained](#magefile-explained)

---

Expand All @@ -22,13 +22,23 @@ You need to have [porter installed](https://porter.sh/install) first. Then run
`make build install`. This will build and install the plugin into your porter
home directory.

## Makefile explained
## Magefile explained

Here are the most common Makefile tasks:
We use [mage](https://magefile.org) instead of make. If you don't have mage installed already,
you can install it with `go run mage.go EnsureMage`.

* `build` builds the plugin.
* `install` installs the plugin into **~/.porter/plugins**.
* `test-unit` runs the unit tests.
[mage]: https://magefile.org

Mage targets are not case-sensitive, but in our docs we use camel case to make
it easier to read. You can run either `mage Build` or `mage build` for
example.

Run `mage` without any arguments to see a list of the available targets.
Below are some commonly used targets:

* `Build` builds the plugin.
* `Install` installs the plugin into **~/.porter/plugins**.
* `TestUnit` runs the unit tests.

## Debugging

Expand Down
72 changes: 0 additions & 72 deletions Makefile

This file was deleted.

44 changes: 0 additions & 44 deletions build/azure-pipelines.yml

This file was deleted.

5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ replace (

// Fixes https://github.com/spf13/viper/issues/761
github.com/spf13/viper => github.com/getporter/viper v1.7.1-porter.2.0.20210514172839-3ea827168363

)

require (
get.porter.sh/magefiles v0.2.2
get.porter.sh/magefiles v0.2.3
get.porter.sh/porter v1.0.0-alpha.19.0.20220519145811-23393bfc2dec
github.com/Azure/azure-pipeline-go v0.2.2
github.com/Azure/azure-sdk-for-go v44.2.0+incompatible
Expand All @@ -24,10 +23,12 @@ require (
github.com/Azure/go-autorest/autorest/azure/auth v0.5.0
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.0 // indirect
github.com/carolynvs/magex v0.8.0
github.com/cnabio/cnab-go v0.23.2
github.com/hashicorp/go-hclog v0.14.1
github.com/hashicorp/go-plugin v1.4.0
github.com/hashicorp/yamux v0.0.0-20190923154419-df201c70410d // indirect
github.com/magefile/mage v1.11.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ contrib.go.opencensus.io/integrations/ocsql v0.1.4/go.mod h1:8DsSdjz3F+APR+0z0Wk
contrib.go.opencensus.io/resource v0.1.1/go.mod h1:F361eGI91LCmW1I/Saf+rX0+OFcigGlFvXwEGEnkRLA=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
get.porter.sh/magefiles v0.1.3/go.mod h1:Whw/DSX8dcgn7dUPb6csbY6PtuTy1wujwFR2G6ONf20=
get.porter.sh/magefiles v0.2.2 h1:9TwJVvIlo+NE1RHNA5FdCciDb0wV4yyp6T3aR7Jtpy8=
get.porter.sh/magefiles v0.2.2/go.mod h1:lwDECEEivbBHACLImnDEhwlr8g3E4xZR1W0DO8FOGa8=
get.porter.sh/magefiles v0.2.3 h1:f6hNUsqIGaNhwMt8a4rhHOjvoSuf4ZBs4ZdV1/OxUIU=
get.porter.sh/magefiles v0.2.3/go.mod h1:lwDECEEivbBHACLImnDEhwlr8g3E4xZR1W0DO8FOGa8=
get.porter.sh/porter v1.0.0-alpha.19.0.20220519145811-23393bfc2dec h1:ynOL2I+EOYfELxTDyBROqjzp1A4g/LOiN8DCvae/x9o=
get.porter.sh/porter v1.0.0-alpha.19.0.20220519145811-23393bfc2dec/go.mod h1:ntxLM2g3/W1PwSispSkV+JzepLxt6xFd4XNbcez0EB4=
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
Expand Down
109 changes: 106 additions & 3 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,47 @@ package main
import (
"fmt"
"os"
"path/filepath"

// mage:import
"get.porter.sh/magefiles/ci"
"get.porter.sh/magefiles/porter"
"get.porter.sh/magefiles/releases"
"get.porter.sh/magefiles/tools"
"github.com/carolynvs/magex/mgx"
"github.com/carolynvs/magex/shx"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/target"
)

const (
// Name of the plugin
pluginName = "azure"

// go package to build when building the plugin
pluginPkg = "get.porter.sh/plugin/" + pluginName

// directory where the compiled binaries for the plugin are generated
binDir = "bin/plugins/" + pluginName
)

var (
// Build a command that stops the build on if the command fails
must = shx.CommandBuilder{StopOnError: true}

// List of directories that should trigger a build when changed
srcDirs = []string{"cmd/", "pkg/", "go.mod", "magefile.go"}
)

// Publish the cross-compiled binaries.
// Publish uploads the cross-compiled binaries for the plugin
func Publish() {
mg.SerialDeps(porter.UseBinForPorterHome, porter.EnsurePorter)

releases.PreparePluginForPublish(pluginName)
releases.PublishPlugin(pluginName)
releases.PublishPluginFeed(pluginName)
}

// Test out publish locally, with your github forks
// TestPublish tries out publish locally, with your github forks
// Assumes that you forked and kept the repository name unchanged.
func TestPublish(username string) {
pluginRepo := fmt.Sprintf("github.com/%s/%s-plugins", username, pluginName)
Expand All @@ -35,3 +58,83 @@ func TestPublish(username string) {

Publish()
}

// Install the azure plugin to PORTER_HOME
func Install() {
pluginDir := filepath.Join(porter.GetPorterHome(), "plugins", pluginName)
mgx.Must(os.MkdirAll(pluginDir, 0700))

// Copy the plugin into PORTER_HOME
mgx.Must(shx.Copy(filepath.Join(binDir, pluginName), pluginDir))
}

// ConfigureAgent sets up the CI server before running the build
func ConfigureAgent() error {
return ci.ConfigureAgent()
}

// EnsureMage installs mage
func EnsureMage() error {
return tools.EnsureMage()
}

func Fmt() {
must.RunV("go", "fmt", "./...")
}

func Vet() {
must.RunV("go", "vet", "./...")
}

// Test runs all tests
func Test() {
// Do not run TestIntegration until its safe to run in CI
mg.SerialDeps(TestUnit)
}

// TestUnit runs the unit tests
func TestUnit() {
v := ""
if mg.Verbose() {
v = "-v"
}

must.Command("go", "test", v, "./...").CollapseArgs().RunV()
}

// TestIntegration runs integration tests, requires AZURE_* environment variables set
// This is not yet run in CI so make sure to run locally
func TestIntegration() {
must.RunV("bash", "./tests/integration/script.sh")
}

func Build() {
rebuild, err := target.Dir(filepath.Join(binDir, pluginName), srcDirs...)
if err != nil {
mgx.Must(fmt.Errorf("error inspecting source dirs %s: %w", srcDirs, err))
}
if rebuild {
mgx.Must(releases.BuildClient(pluginPkg, pluginName, binDir))
} else {
fmt.Println("target is up-to-date")
}
}

// XBuildAll cross-compiles the plugin
func XBuildAll() {
rebuild, err := target.Dir(filepath.Join(binDir, "dev/azure-linux-amd64"), srcDirs...)
if err != nil {
mgx.Must(fmt.Errorf("error inspecting source dirs %s: %w", srcDirs, err))
}
if rebuild {
releases.XBuildAll(pluginPkg, pluginName, binDir)
} else {
fmt.Println("target is up-to-date")
}

releases.PreparePluginForPublish(pluginName)
}

func Clean() error {
return os.RemoveAll("bin")
}

0 comments on commit e9aeee3

Please sign in to comment.