From 39abd8782669baa68509d7fcbae88329cb0fec92 Mon Sep 17 00:00:00 2001 From: Marcus Vorwaller Date: Thu, 14 May 2026 03:30:17 -0700 Subject: [PATCH] ci: optimize build configuration for faster CI and release builds Align CI Go toolchain with go.mod, make module/build caching explicit, pin golangci-lint, add a Go build cache to the release workflow, and add reproducible build flags to the Makefile. - ci.yml: use go-version-file: go.mod in test and lint jobs so the toolchain matches the module's go 1.24.0 requirement (the previous hardcoded 1.23 forced toolchain re-downloads and cache misses) - ci.yml: enable explicit setup-go caching keyed on go.sum - ci.yml: pin golangci-lint to v1.64.8 instead of latest for reproducible, cache-friendly lint runs - release.yml: add actions/cache for ~/.cache/go-build and ~/go/pkg/mod before GoReleaser, which otherwise recompiles all 4 platform targets from scratch - Makefile: add -trimpath and -s -w ldflags to build/install targets via GO_BUILD_FLAGS/LDFLAGS variables, matching .goreleaser.yml Nightshift-Task: build-optimize Nightshift-Ref: https://github.com/marcus/nightshift Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/ci.yml | 10 +++++++--- .github/workflows/release.yml | 10 ++++++++++ Makefile | 8 ++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fc5686..91eacd8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,9 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version-file: go.mod + cache: true + cache-dependency-path: go.sum - name: Download dependencies run: go mod download @@ -44,9 +46,11 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version-file: go.mod + cache: true + cache-dependency-path: go.sum - name: Run golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: latest + version: v1.64.8 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index df9e27f..143f7f6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,16 @@ jobs: with: go-version-file: go.mod + - name: Cache Go build and module cache + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-release-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-release- + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v6 with: diff --git a/Makefile b/Makefile index 088be01..a1a105e 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,17 @@ BINARY=nightshift PKG=./cmd/nightshift +# Build flags (match .goreleaser.yml for reproducible, cache-friendly artifacts) +GO_BUILD_FLAGS=-trimpath +LDFLAGS=-s -w + # Build the binary build: - go build -o $(BINARY) $(PKG) + go build $(GO_BUILD_FLAGS) -ldflags="$(LDFLAGS)" -o $(BINARY) $(PKG) # Install the binary to your Go bin directory install: - go install $(PKG) + go install $(GO_BUILD_FLAGS) -ldflags="$(LDFLAGS)" $(PKG) @echo "Installed $(BINARY) to $$(if [ -n "$$(go env GOBIN)" ]; then go env GOBIN; else echo "$$(go env GOPATH)/bin"; fi)" # Run provider calibration comparison tool