From 1f6e51b2f7a0e267cded96104497ce0a17260ad3 Mon Sep 17 00:00:00 2001 From: Toby Date: Sun, 12 Jul 2020 14:08:33 -0700 Subject: [PATCH] Add ldflags support --- action.yml | 4 ++++ entrypoint.go | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 4423943..f501d02 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,10 @@ inputs: description: 'Destination directory inside workspace to output build-artifacts.' default: 'build' required: false + ldflags: + description: 'Flags to pass to the Go linker.' + default: '' + required: false # action runner (golang:latest image) runs: diff --git a/entrypoint.go b/entrypoint.go index 1d878ba..b7c921c 100644 --- a/entrypoint.go +++ b/entrypoint.go @@ -39,7 +39,7 @@ func copyFile(src, dest string) { /*************************************/ // build the package for a platform -func build(packageName, destDir string, platform map[string]string, compress bool) { +func build(packageName, destDir string, platform map[string]string, ldflags string, compress bool) { // platform config platformKernel := platform["kernel"] @@ -79,7 +79,7 @@ func build(packageName, destDir string, platform map[string]string, compress boo /*------------*/ // command-line options for the `go build` command - buildOptions := []string{"build", "-buildmode", "exe", "-o", buildFilePath, packagePath} + buildOptions := []string{"build", "-buildmode", "exe", "-ldflags", ldflags, "-o", buildFilePath, packagePath} // generate `go build` command buildCmd := exec.Command("go", buildOptions...) @@ -169,6 +169,7 @@ func main() { inputPackage := os.Getenv("INPUT_PACKAGE") inputCompress := os.Getenv("INPUT_COMPRESS") inputDest := os.Getenv("INPUT_DEST") + inputLdflags := os.Getenv("INPUT_LDFLAGS") // package name to build packageName := strings.ReplaceAll(inputPackage, " ", "") @@ -198,7 +199,7 @@ func main() { } // execute `build` function - build(packageName, destDir, platformMap, compress) + build(packageName, destDir, platformMap, inputLdflags, compress) } /*------------*/