Skip to content

Commit 2564ffc

Browse files
author
Sandeep
committed
use go.mod as single source of truth for Go version in CI, Dockerfiles, and Makefile
1 parent 2f67941 commit 2564ffc

4 files changed

Lines changed: 30 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Set up Go
1919
uses: actions/setup-go@v6
2020
with:
21-
go-version: '1.25'
21+
go-version-file: 'go.mod'
2222
cache: false # golangci-lint-action handles its own caching
2323

2424
- name: Run golangci-lint
@@ -45,7 +45,7 @@ jobs:
4545
- name: Set up Go
4646
uses: actions/setup-go@v6
4747
with:
48-
go-version: '1.25'
48+
go-version-file: 'go.mod'
4949
cache: true
5050

5151
- name: Run go vet
@@ -62,7 +62,7 @@ jobs:
6262
- name: Set up Go
6363
uses: actions/setup-go@v6
6464
with:
65-
go-version: '1.25'
65+
go-version-file: 'go.mod'
6666
cache: true
6767

6868
- name: Install staticcheck
@@ -71,11 +71,25 @@ jobs:
7171
- name: Run staticcheck
7272
run: staticcheck ./...
7373

74+
resolve-go-version:
75+
name: Resolve Go version
76+
runs-on: ubuntu-latest
77+
outputs:
78+
go-version: ${{ steps.go-version.outputs.version }}
79+
steps:
80+
- name: Checkout code
81+
uses: actions/checkout@v5
82+
83+
- name: Extract Go version from go.mod
84+
id: go-version
85+
run: echo "version=$(grep '^go ' go.mod | awk '{print $2}')" >> "$GITHUB_OUTPUT"
86+
7487
build:
7588
name: Build (Alpine)
89+
needs: resolve-go-version
7690
runs-on: ubuntu-latest
7791
container:
78-
image: golang:1.25-alpine
92+
image: golang:${{ needs.resolve-go-version.outputs.go-version }}-alpine
7993

8094
steps:
8195
- name: Install build dependencies
@@ -101,7 +115,7 @@ jobs:
101115
- name: Set up Go
102116
uses: actions/setup-go@v6
103117
with:
104-
go-version: '1.25'
118+
go-version-file: 'go.mod'
105119
cache: true
106120

107121
- name: Install Java (for JVM tests)

Dockerfile.base.alpine

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# syntax=docker/dockerfile:1.6
22

3-
FROM golang:1.25.8-alpine AS builder
3+
ARG GO_VERSION
4+
FROM golang:${GO_VERSION}-alpine AS builder
45

56
RUN apk add --no-cache \
67
clang \

Dockerfile.linux

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM golang:1.25.8-alpine AS builder
1+
ARG GO_VERSION
2+
FROM golang:${GO_VERSION}-alpine AS builder
23
WORKDIR /app
34
RUN apk add --no-cache \
45
clang \
@@ -15,8 +16,8 @@ FROM scratch AS final
1516
COPY --from=builder /app/cmd/yc/yc /yc
1617
ENTRYPOINT ["/yc"]
1718

18-
### command to build yc file
19+
### command to build yc file (GO_VERSION is read from go.mod)
1920
## If ARM64
20-
# docker buildx build -f Dockerfile.linux --target final -o type=local,dest=./bin/linux/arm64 .
21+
# docker buildx build -f Dockerfile.linux --build-arg GO_VERSION=$(grep '^go ' go.mod | awk '{print $2}') --target final -o type=local,dest=./bin/linux/arm64 .
2122
## If x86_64
22-
# docker buildx build -f Dockerfile.linux --target final -o type=local,dest=./bin/linux/amd64 .
23+
# docker buildx build -f Dockerfile.linux --build-arg GO_VERSION=$(grep '^go ' go.mod | awk '{print $2}') --target final -o type=local,dest=./bin/linux/amd64 .

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CWD := $(shell pwd)
2+
GO_VERSION := $(shell grep '^go ' go.mod | awk '{print $$2}')
23

34
IMAGE_NAME := yc-360-script-base:alpine
45
CONTAINER_NAME := yc-360-script-base-alpine
@@ -9,7 +10,7 @@ _:
910
echo "default"
1011

1112
alpine:
12-
docker build -f Dockerfile.base.alpine -t $(IMAGE_NAME) .
13+
docker build --build-arg GO_VERSION=$(GO_VERSION) -f Dockerfile.base.alpine -t $(IMAGE_NAME) .
1314

1415
base: alpine
1516
docker rm -f $(CONTAINER_NAME) || true
@@ -35,6 +36,7 @@ build-all:
3536

3637
# linux/amd64
3738
docker buildx build \
39+
--build-arg GO_VERSION=$(GO_VERSION) \
3840
--platform linux/amd64 \
3941
-f Dockerfile.base.alpine \
4042
--target export \
@@ -43,6 +45,7 @@ build-all:
4345

4446
# linux/arm64
4547
docker buildx build \
48+
--build-arg GO_VERSION=$(GO_VERSION) \
4649
--platform linux/arm64 \
4750
-f Dockerfile.base.alpine \
4851
--target export \

0 commit comments

Comments
 (0)