Skip to content

Commit

Permalink
Merge pull request #1 from tobyxdd/ldflags
Browse files Browse the repository at this point in the history
Add ldflags support
  • Loading branch information
thatisuday committed Jul 13, 2020
2 parents 3d5409b + 1f6e51b commit 542468f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions entrypoint.go
Expand Up @@ -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"]
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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, " ", "")
Expand Down Expand Up @@ -198,7 +199,7 @@ func main() {
}

// execute `build` function
build(packageName, destDir, platformMap, compress)
build(packageName, destDir, platformMap, inputLdflags, compress)
}

/*------------*/
Expand Down

0 comments on commit 542468f

Please sign in to comment.