Skip to content

Commit 22e0d85

Browse files
ci: add devcontainer version drift detection
- Add Docker ecosystem to dependabot to track base image updates - Add CI workflow that fails PRs when go.mod and Dockerfile Go versions diverge
1 parent 2185ec3 commit 22e0d85

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,16 @@ updates:
4242
github-actions:
4343
patterns:
4444
- "*"
45+
46+
# Enable version updates for Dockerfile base images
47+
- package-ecosystem: "docker"
48+
directory: "/.devcontainer"
49+
schedule:
50+
interval: "weekly"
51+
day: "monday"
52+
labels:
53+
- "dependencies"
54+
- "devcontainer"
55+
commit-message:
56+
prefix: "deps"
57+
include: "scope"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: devcontainer-version-check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- 'go.mod'
9+
- '.devcontainer/Dockerfile'
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
check-go-version-alignment:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
19+
20+
- name: Verify Dockerfile Go version satisfies go.mod
21+
run: |
22+
# Extract the major.minor Go version required by go.mod
23+
GOMOD_VERSION=$(grep '^go ' go.mod | awk '{print $2}')
24+
GOMOD_MAJOR_MINOR=$(echo "$GOMOD_VERSION" | grep -oE '^[0-9]+\.[0-9]+')
25+
26+
# Extract the Go version from the Dockerfile base image tag
27+
DOCKERFILE_TAG=$(grep -oP 'devcontainers/go:\K[0-9]+\.[0-9]+' .devcontainer/Dockerfile)
28+
29+
echo "go.mod requires: go ${GOMOD_VERSION} (major.minor: ${GOMOD_MAJOR_MINOR})"
30+
echo "Dockerfile base image: go:${DOCKERFILE_TAG}"
31+
32+
if [[ -z "$GOMOD_MAJOR_MINOR" || -z "$DOCKERFILE_TAG" ]]; then
33+
echo "ERROR: Could not parse versions"
34+
exit 1
35+
fi
36+
37+
if [[ "$GOMOD_MAJOR_MINOR" != "$DOCKERFILE_TAG" ]]; then
38+
echo ""
39+
echo "ERROR: Version mismatch!"
40+
echo "The devcontainer base image (go:${DOCKERFILE_TAG}) does not match"
41+
echo "the Go version required by go.mod (${GOMOD_MAJOR_MINOR})."
42+
echo ""
43+
echo "Update .devcontainer/Dockerfile:"
44+
echo " FROM mcr.microsoft.com/devcontainers/go:${GOMOD_MAJOR_MINOR}-bookworm"
45+
echo ""
46+
echo "You may also need to update the pinned Go tool versions in the Dockerfile"
47+
echo "(gopls, delve, staticcheck, gotext) to versions compatible with Go ${GOMOD_MAJOR_MINOR}."
48+
exit 1
49+
fi
50+
51+
echo "OK: Versions are aligned."

0 commit comments

Comments
 (0)