|
| 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