Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Mage as build tool #111

Merged
merged 8 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- run: |
git clone --depth 1 --branch v1.13.0 https://github.com/magefile/mage
cd mage
go run bootstrap.go

- run: go version
- run: go env
- run: docker version
- run: |
go version
go env
mage -version
docker version

# First build to check for compile errors
- run: build/build.sh
- run: mage build
# Then lint, taking `.golangci.yml` into account
- uses: golangci/golangci-lint-action@v3
# Finally test all modules
# This starts and stops Docker containers for services like PostgreSQL, Redis etc.
# Takes up to 10m on GitHub Actions
# TODO: Change workflow so that when only one module is changed, only that module's tests are run
- run: build/test.sh
- run: mage test all

# Combining of coverage reports not required with the action, which detects all reports in subdirectories and uploads all of them
#- run: build/combine-coverage.sh
Expand Down
15 changes: 0 additions & 15 deletions build/combine-coverage.sh

This file was deleted.

97 changes: 0 additions & 97 deletions build/test.sh

This file was deleted.

21 changes: 0 additions & 21 deletions build/tidy.ps1

This file was deleted.

14 changes: 14 additions & 0 deletions magefiles/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/philippgille/magefiles

go 1.18

require (
github.com/bitfield/script v0.20.2
github.com/magefile/mage v1.13.0
)

require (
bitbucket.org/creachadair/shell v0.0.7 // indirect
github.com/itchyny/gojq v0.12.7 // indirect
github.com/itchyny/timefmt-go v0.1.3 // indirect
)
22 changes: 22 additions & 0 deletions magefiles/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
bitbucket.org/creachadair/shell v0.0.7 h1:Z96pB6DkSb7F3Y3BBnJeOZH2gazyMTWlvecSD4vDqfk=
bitbucket.org/creachadair/shell v0.0.7/go.mod h1:oqtXSSvSYr4624lnnabXHaBsYW6RD80caLi2b3hJk0U=
github.com/bitfield/script v0.20.2 h1:4DexsRtBILVMEn3EZwHbtJdDqdk43sXI8gM3F04JXgs=
github.com/bitfield/script v0.20.2/go.mod h1:l3AZPVAtKQrL03bwh7nlNTUtgrgSWurpJSbtqspYrOA=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/itchyny/gojq v0.12.7 h1:hYPTpeWfrJ1OT+2j6cvBScbhl0TkdwGM4bc66onUSOQ=
github.com/itchyny/gojq v0.12.7/go.mod h1:ZdvNHVlzPgUf8pgjnuDTmGfHA/21KoutQUJ3An/xNuw=
github.com/itchyny/timefmt-go v0.1.3 h1:7M3LGVDsqcd0VZH2U+x393obrzZisp7C0uEe921iRkU=
github.com/itchyny/timefmt-go v0.1.3/go.mod h1:0osSSCQSASBJMsIZnhAaF1C2fCBTJZXrnj37mG8/c+A=
github.com/magefile/mage v1.13.0 h1:XtLJl8bcCM7EFoO8FyH8XK3t7G5hQAeK+i4tq+veT9M=
github.com/magefile/mage v1.13.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
85 changes: 85 additions & 0 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//go:build mage

package main

import (
"errors"
"runtime"

"github.com/bitfield/script"
"github.com/magefile/mage/sh"
)

// Update updates the dependencies of all modules.
// It only updates direct dependencies within the same major version, like `go get` with `@latest` does.
// It doesn't update transitive dependencies, like `go get -u` does.
// It also runs `go mod tidy` for all modules after updating.
func Update() error {
switch runtime.GOOS {
case "windows":
return sh.Run("./build/update-deps.ps1")
case "darwin":
fallthrough
case "linux":
return sh.Run("./build/update-deps.sh")
}
return errors.New("your OS is not supported")
}

// Build builds all modules.
func Build() error {
switch runtime.GOOS {
case "windows":
return sh.Run("./build/build.ps1")
case "darwin":
fallthrough
case "linux":
return sh.Run("./build/build.sh")
}
return errors.New("your OS is not supported")
}

// Test tests the given module. Pass "all" to test all modules.
func Test(module string) error {
if module == "all" {
// Helper packages and examples currently don't have tests, so currently for *all* tests we can just iterate all `gokv.Store` implementations
// TODO: Add tests for helper and example packages, then change this behavior.
impls, err := script.File("./build/implementations").Slice()
if err != nil {
return err
}
for _, impl := range impls {
err = testImpl(impl)
if err != nil {
return err
}
}
return nil
}

switch module {
case "encoding", "sql", "test", "util":
return errors.New("module " + module + " doesn't have any tests")
case "examples":
return errors.New("examples don't have any tests")
}

i, err := script.File("./build/implementations").Match(module).CountLines()
if err != nil {
return err
}
if i == 0 {
return errors.New("module from parameter not found")
}

return testImpl(module)
}

// Clean cleans the build/test output, like coverage.txt files
func Clean() error {
p := script.FindFiles(".").
Match("coverage.txt").
ExecForEach("rm ./{{.}}") // On Windows `rm` works as it's an alias for Remove-Item
p.Wait()
return p.Error()
}
Loading