-
Notifications
You must be signed in to change notification settings - Fork 3
42 lines (37 loc) · 1.2 KB
/
check-go-version.yml
File metadata and controls
42 lines (37 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
name: Check Go Version Match
on:
push:
paths:
- Dockerfile
- go.mod
pull_request:
paths:
- Dockerfile
- go.mod
jobs:
check-go-version:
runs-on: ubuntu-latest
name: Go Version Consistency
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Extract Go version from go.mod
id: go_mod
run: |
GO_MOD_VERSION=$(grep '^go ' go.mod | awk '{print $2}' | cut -d. -f1,2)
echo "version=$GO_MOD_VERSION" >> "$GITHUB_OUTPUT"
- name: Extract Go version from Dockerfile
id: dockerfile
run: |
DOCKER_VERSION=$(grep -Eo 'golang:[0-9]+\.[0-9]+' Dockerfile | head -1 | sed 's/golang://')
echo "version=$DOCKER_VERSION" >> "$GITHUB_OUTPUT"
- name: Compare versions
env:
GO_MOD_VERSION: ${{ steps.go_mod.outputs.version }}
DOCKERFILE_VERSION: ${{ steps.dockerfile.outputs.version }}
run: |
if [ "$GO_MOD_VERSION" != "$DOCKERFILE_VERSION" ]; then
echo "::error::Go version mismatch: go.mod=$GO_MOD_VERSION, Dockerfile=$DOCKERFILE_VERSION"
exit 1
fi
echo "Go versions match: $GO_MOD_VERSION"