build: moved magefiles directory to project root

Moved the magefiles directory back to the project's root directory and
created a separate go.mod file to keep the dependencies separated.

The idea was suggested here:
https://github.com/magefile/mage/issues/502
This commit is contained in:
Dan Anglin 2024-05-23 11:09:34 +01:00
parent 421c21bf52
commit 3d17c30d0f
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
7 changed files with 5 additions and 38 deletions

View file

@ -47,7 +47,6 @@ You can install Enbas with Mage using the following commands:
[source,console]
----
git clone https://github.com/dananglin/enbas.git
cd enbas/internal/build/
mage install
----

View file

@ -1,5 +0,0 @@
module enbas-build
go 1.22.0
require github.com/magefile/mage v1.15.0

8
mage
View file

@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
cd ./internal/build
mage $@

5
magefiles/go.mod Normal file
View file

@ -0,0 +1,5 @@
module codeflow.dananglin.me.uk/apollo/enbas/magefiles
go 1.22.3
require github.com/magefile/mage v1.15.0

View file

@ -29,10 +29,6 @@ var Default = Build
// To enable verbose mode set ENBAS_TEST_VERBOSE=1.
// To enable coverage mode set ENBAS_TEST_COVER=1.
func Test() error {
if err := changeToProjectRoot(); err != nil {
return fmt.Errorf("unable to change to the project's root directory; %w", err)
}
goTest := sh.RunCmd("go", "test")
args := []string{"./..."}
@ -50,10 +46,6 @@ func Test() error {
// Lint runs golangci-lint against the code.
func Lint() error {
if err := changeToProjectRoot(); err != nil {
return fmt.Errorf("unable to change to the project's root directory; %w", err)
}
return sh.RunV("golangci-lint", "run", "--color", "always")
}
@ -61,10 +53,6 @@ func Lint() error {
// To rebuild packages that are already up-to-date set ENBAS_BUILD_REBUILD_ALL=1
// To enable verbose mode set ENBAS_BUILD_VERBOSE=1
func Build() error {
if err := changeToProjectRoot(); err != nil {
return fmt.Errorf("unable to change to the project's root directory; %w", err)
}
main := "./cmd/" + app
binary := "./__build/" + app
flags := ldflags()
@ -107,10 +95,6 @@ func Install() error {
// Clean clean the workspace.
func Clean() error {
if err := changeToProjectRoot(); err != nil {
return fmt.Errorf("unable to change to the project's root directory; %w", err)
}
if err := sh.Rm(app); err != nil {
return err
}
@ -122,14 +106,6 @@ func Clean() error {
return nil
}
func changeToProjectRoot() error {
if err := os.Chdir("../.."); err != nil {
return fmt.Errorf("unable to change directory; %w", err)
}
return nil
}
// ldflags returns the build flags.
func ldflags() string {
ldflagsfmt := "-s -w -X main.binaryVersion=%s -X main.gitCommit=%s -X main.goVersion=%s -X main.buildTime=%s"