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

Add ldflags support #1

Merged
merged 1 commit into from Jul 13, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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