Skip to content

Commit

Permalink
Add e2e test for using ldflags to set a build-time variable (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh authored Nov 2, 2021
1 parent 17edbb3 commit 9821190
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ jobs:
if [[ "$RUNNER_OS" == "Linux" ]]; then
docker run ${testimg} --wait=false -f HEAD
fi
# Check that using ldflags to set variables works.
cat > .ko.yaml << EOF
builds:
- id: test
main: ./test/
ldflags:
- "-X main.version=${{ github.sha }}"
EOF
docker run $(go run ./ publish ./test/ --platform=${GOOS}/${GOARCH}) --wait=false 2>&1 | grep "${{ github.sha }}"
1 change: 0 additions & 1 deletion .ko.yaml

This file was deleted.

5 changes: 5 additions & 0 deletions test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ var (
wait = flag.Bool("wait", true, "Whether to wait for SIGTERM")
)

// This is defined so we can test build-time variable setting using ldflags.
var version = "default"

func main() {
flag.Parse()

log.Println("version =", version)

dp := os.Getenv("KO_DATA_PATH")
file := filepath.Join(dp, *f)
bytes, err := ioutil.ReadFile(file)
Expand Down

0 comments on commit 9821190

Please sign in to comment.