From b483eab827a7d38dbd018289e93bc56b4d48b654 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Sat, 6 Jun 2026 07:34:31 +0100 Subject: [PATCH] fix(ci): add go mod download + use make cross in release workflow to fix missing go.sum errors during cross-platform builds --- .gitea/workflows/release.yml | 26 +++++++++++++++----------- Makefile | 7 +++++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 06049dd..e4cf97e 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -23,22 +23,26 @@ jobs: with: go-version: '1.24' + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download Go modules + run: go mod download + - name: Build for multiple platforms run: | VERSION=${GITHUB_REF#refs/tags/} COMMIT=$(git rev-parse --short HEAD) DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) - mkdir -p build - for plat in 'linux/amd64' 'linux/arm64' 'darwin/amd64' 'darwin/arm64' 'windows/amd64'; do - IFS='/' read -r OS ARCH <<< "$plat" - BIN="gostations-${OS}-${ARCH}" - if [ "$OS" = "windows" ]; then BIN="${BIN}.exe"; fi - GOOS="$OS" GOARCH="$ARCH" go build -trimpath -ldflags "-s -w \ - -X 'github.com/gmgauthier/gostations/internal/version.Version=${VERSION}' \ - -X 'github.com/gmgauthier/gostations/internal/version.Commit=${COMMIT}' \ - -X 'github.com/gmgauthier/gostations/internal/version.BuildDate=${DATE}' \ - -X 'main.version=${VERSION}'" -o "build/${BIN}" . - done + make cross VERSION="$VERSION" COMMIT="$COMMIT" DATE="$DATE" + # make cross (with deps) handles the loop + ldflags + + - name: Prepare assets run: | diff --git a/Makefile b/Makefile index ae30582..b497f94 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,10 @@ lint: @which golangci-lint > /dev/null || (echo "❌ golangci-lint not found. Install with:" && echo " go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest" && exit 1) golangci-lint run -build: +deps: + go mod download + +build: deps @mkdir -p build go build -trimpath -ldflags "$(LDFLAGS)" -o build/gostations . @echo "✅ Dev build: VERSION=$(VERSION) COMMIT=$(COMMIT) DATE=$(DATE)" @@ -44,7 +47,7 @@ clean: rm -rf build/ # Cross compile (used by release workflow) -cross: +cross: deps @mkdir -p build @for plat in 'linux/amd64' 'linux/arm64' 'darwin/amd64' 'darwin/arm64' 'windows/amd64'; do \ IFS='/' read -r OS ARCH <<< "$$plat"; \