Add ldflags support

This commit is contained in:
Toby 2020-07-12 14:08:33 -07:00
parent 3d5409b1f3
commit 1f6e51b2f7
2 changed files with 8 additions and 3 deletions

View File

@ -29,6 +29,10 @@ inputs:
description: 'Destination directory inside workspace to output build-artifacts.' description: 'Destination directory inside workspace to output build-artifacts.'
default: 'build' default: 'build'
required: false required: false
ldflags:
description: 'Flags to pass to the Go linker.'
default: ''
required: false
# action runner (golang:latest image) # action runner (golang:latest image)
runs: runs:

View File

@ -39,7 +39,7 @@ func copyFile(src, dest string) {
/*************************************/ /*************************************/
// build the package for a platform // 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 // platform config
platformKernel := platform["kernel"] 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 // 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 // generate `go build` command
buildCmd := exec.Command("go", buildOptions...) buildCmd := exec.Command("go", buildOptions...)
@ -169,6 +169,7 @@ func main() {
inputPackage := os.Getenv("INPUT_PACKAGE") inputPackage := os.Getenv("INPUT_PACKAGE")
inputCompress := os.Getenv("INPUT_COMPRESS") inputCompress := os.Getenv("INPUT_COMPRESS")
inputDest := os.Getenv("INPUT_DEST") inputDest := os.Getenv("INPUT_DEST")
inputLdflags := os.Getenv("INPUT_LDFLAGS")
// package name to build // package name to build
packageName := strings.ReplaceAll(inputPackage, " ", "") packageName := strings.ReplaceAll(inputPackage, " ", "")
@ -198,7 +199,7 @@ func main() {
} }
// execute `build` function // execute `build` function
build(packageName, destDir, platformMap, compress) build(packageName, destDir, platformMap, inputLdflags, compress)
} }
/*------------*/ /*------------*/