Skip to content

Commit

Permalink
azure pipelines (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Feb 24, 2019
1 parent f04769f commit e24f5fc
Show file tree
Hide file tree
Showing 14 changed files with 409 additions and 55 deletions.
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

59 changes: 59 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
variables:
GOBIN: "$(GOPATH)/bin" # Go binaries path
GOPATH: "$(system.defaultWorkingDirectory)/gopath" # Go workspace path
modulePath: "$(GOPATH)/src/github.com/$(build.repository.name)" # Path to the module"s code

jobs:
- job: Windows
pool:
vmImage: "vs2017-win2016"
strategy:
matrix:
go 1.9:
go_version: "1.9"
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11"
GO111MODULE: "off"
steps:
- template: azure-tests.yml

- job: macOS
pool:
vmImage: "macOS-10.13"
strategy:
matrix:
go 1.9:
go_version: "1.9"
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11"
GO111MODULE: "off"
steps:
- template: azure-tests.yml

- job: Linux
pool:
vmImage: "ubuntu-16.04"
strategy:
matrix:
go 1.9:
go_version: "1.9"
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11"
GO111MODULE: "off"
steps:
- template: azure-tests.yml
19 changes: 19 additions & 0 deletions azure-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
steps:
- task: GoTool@0
inputs:
version: $(go_version)
- task: Bash@3
inputs:
targetType: inline
script: |
mkdir -p "$(GOBIN)"
mkdir -p "$(GOPATH)/pkg"
mkdir -p "$(modulePath)"
shopt -s extglob
mv !(gopath) "$(modulePath)"
displayName: "Setup Go Workspace"
- script: |
go get -t -v ./...
go test -race ./...
workingDirectory: "$(modulePath)"
displayName: "Tests"
41 changes: 41 additions & 0 deletions cmd/azure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cmd

import (
"context"

"github.com/gobuffalo/genny"
"github.com/gobuffalo/release/genny/azure"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var azureOptions = struct {
*azure.Options
dryRun bool
}{
Options: &azure.Options{},
}

var azureCmd = &cobra.Command{
Use: "azure",
Short: "generates azure pipelines files for Azure DevOps pipelines",
RunE: func(cmd *cobra.Command, args []string) error {
var run *genny.Runner = genny.WetRunner(context.Background())
if azureOptions.dryRun {
run = genny.DryRunner(context.Background())
}

opts := azureOptions.Options
if err := run.WithNew(azure.New(opts)); err != nil {
return errors.WithStack(err)
}

return run.Run()
},
}

func init() {
rootCmd.AddCommand(azureCmd)
azureCmd.Flags().BoolVarP(&azureOptions.dryRun, "dry-run", "d", false, "runs the generator dry")
azureCmd.Flags().BoolVarP(&azureOptions.Force, "force", "f", false, "force files to overwrite existing ones")
}
8 changes: 8 additions & 0 deletions genny/azure/azure-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions genny/azure/azure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package azure

import (
"github.com/gobuffalo/genny"
"github.com/gobuffalo/packr/v2"
"github.com/gobuffalo/plush"
"github.com/gobuffalo/plushgen"
"github.com/pkg/errors"
)

func New(opts *Options) (*genny.Generator, error) {
g := genny.New()

if err := opts.Validate(); err != nil {
return g, errors.WithStack(err)
}
box := packr.New("github.com/gobuffalo/release/genny/azure/templates", "../azure/templates")
if err := genny.ForceBox(g, box, opts.Force); err != nil {
return g, errors.WithStack(err)
}
ctx := plush.NewContext()
ctx.Set("opts", opts)
g.Transformer(plushgen.Transformer(ctx))
return g, nil
}
28 changes: 28 additions & 0 deletions genny/azure/azure_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package azure

import (
"testing"

"github.com/gobuffalo/genny/gentest"
"github.com/stretchr/testify/require"
)

func Test_New(t *testing.T) {
r := require.New(t)

g, err := New(&Options{})
r.NoError(err)

run := gentest.NewRunner()
run.With(g)

r.NoError(run.Run())

res := run.Results()

r.Len(res.Commands, 0)
r.Len(res.Files, 2)

err = gentest.CompareFiles([]string{"azure-pipelines.yml", "azure-tests.yml"}, res.Files)
r.NoError(err)
}
10 changes: 10 additions & 0 deletions genny/azure/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package azure

type Options struct {
Force bool
}

// Validate that options are usuable
func (opts *Options) Validate() error {
return nil
}
1 change: 1 addition & 0 deletions genny/azure/options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package azure
59 changes: 59 additions & 0 deletions genny/azure/templates/azure-pipelines.yml.plush
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
variables:
GOBIN: "$(GOPATH)/bin" # Go binaries path
GOPATH: "$(system.defaultWorkingDirectory)/gopath" # Go workspace path
modulePath: "$(GOPATH)/src/github.com/$(build.repository.name)" # Path to the module"s code

jobs:
- job: Windows
pool:
vmImage: "vs2017-win2016"
strategy:
matrix:
go 1.9:
go_version: "1.9"
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11"
GO111MODULE: "off"
steps:
- template: azure-tests.yml

- job: macOS
pool:
vmImage: "macOS-10.13"
strategy:
matrix:
go 1.9:
go_version: "1.9"
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11"
GO111MODULE: "off"
steps:
- template: azure-tests.yml

- job: Linux
pool:
vmImage: "ubuntu-16.04"
strategy:
matrix:
go 1.9:
go_version: "1.9"
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11"
GO111MODULE: "off"
steps:
- template: azure-tests.yml
19 changes: 19 additions & 0 deletions genny/azure/templates/azure-tests.yml.plush
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
steps:
- task: GoTool@0
inputs:
version: $(go_version)
- task: Bash@3
inputs:
targetType: inline
script: |
mkdir -p "$(GOBIN)"
mkdir -p "$(GOPATH)/pkg"
mkdir -p "$(modulePath)"
shopt -s extglob
mv !(gopath) "$(modulePath)"
displayName: "Setup Go Workspace"
- script: |
go get -t -v ./...
go test -race ./...
workingDirectory: "$(modulePath)"
displayName: "Tests"
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/Masterminds/semver v1.4.2
github.com/fatih/structs v1.1.0 // indirect
github.com/gobuffalo/envy v1.6.15
github.com/gobuffalo/genny v0.0.0-20190131190646-008a76242145
github.com/gobuffalo/genny v0.0.0-20190219203444-c95082806342
github.com/gobuffalo/github_flavored_markdown v1.0.7 // indirect
github.com/gobuffalo/licenser v0.0.0-20181211173111-f8a311c51159
github.com/gobuffalo/logger v0.0.0-20181127160119-5b956e21995c
Expand All @@ -19,5 +19,4 @@ require (
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v0.0.3
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc // indirect
)
Loading

0 comments on commit e24f5fc

Please sign in to comment.