-
Notifications
You must be signed in to change notification settings - Fork 350
89 lines (79 loc) · 3.32 KB
/
Copy pathvalidate-go-version.yml
File metadata and controls
89 lines (79 loc) · 3.32 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: validate-go-version
on:
pull_request:
paths:
- "**/go.mod"
- "**/Dockerfile"
- ".devcontainer/devcontainer.json"
- "eng/pipelines/templates/steps/setup-go.yml"
- ".github/workflows/validate-go-version.yml"
branches: [main]
permissions:
contents: read
jobs:
check-go-version-consistency:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Validate Go version consistency
run: |
# Source of truth: cli/azd/go.mod
EXPECTED=$(grep -m1 '^go ' cli/azd/go.mod | awk '{print $2}')
echo "Expected Go version (from cli/azd/go.mod): $EXPECTED"
ERRORS=0
# Check all go.mod files
echo ""
echo "Checking go.mod files..."
while IFS= read -r f; do
VERSION=$(grep -m1 '^go ' "$f" | awk '{print $2}')
if [ "$VERSION" != "$EXPECTED" ]; then
echo "::error file=$f::Go version mismatch: found '$VERSION', expected '$EXPECTED'"
ERRORS=$((ERRORS + 1))
else
echo " OK: $f ($VERSION)"
fi
done < <(find cli/azd -name 'go.mod')
# Check ADO pipeline template
echo ""
echo "Checking ADO pipeline template..."
ADO_FILE="eng/pipelines/templates/steps/setup-go.yml"
if [ -f "$ADO_FILE" ]; then
ADO_VERSION=$(grep -m1 'GoVersion:' "$ADO_FILE" | awk '{print $2}')
if [ "$ADO_VERSION" != "$EXPECTED" ]; then
echo "::error file=$ADO_FILE::GoVersion mismatch: found '$ADO_VERSION', expected '$EXPECTED'"
ERRORS=$((ERRORS + 1))
else
echo " OK: $ADO_FILE ($ADO_VERSION)"
fi
fi
# Check Dockerfiles referencing golang:<version> base images
echo ""
echo "Checking Dockerfiles..."
while IFS= read -r f; do
DOCKER_VERSION=$(grep -oP 'golang:\K[\d.]+' "$f" | head -1)
if [ -n "$DOCKER_VERSION" ] && [ "$DOCKER_VERSION" != "$EXPECTED" ]; then
echo "::error file=$f::Dockerfile golang version mismatch: found '$DOCKER_VERSION', expected '$EXPECTED'"
ERRORS=$((ERRORS + 1))
elif [ -n "$DOCKER_VERSION" ]; then
echo " OK: $f (golang:$DOCKER_VERSION)"
fi
done < <(find cli/azd -name 'Dockerfile')
# Check devcontainer.json Go feature version
echo ""
echo "Checking devcontainer.json..."
DEVCONTAINER=".devcontainer/devcontainer.json"
if [ -f "$DEVCONTAINER" ]; then
DC_VERSION=$(grep -A1 'devcontainers/features/go' "$DEVCONTAINER" | grep -oP '"version":\s*"\K[\d.]+')
if [ -n "$DC_VERSION" ] && [ "$DC_VERSION" != "$EXPECTED" ]; then
echo "::error file=$DEVCONTAINER::devcontainer Go version mismatch: found '$DC_VERSION', expected '$EXPECTED'"
ERRORS=$((ERRORS + 1))
elif [ -n "$DC_VERSION" ]; then
echo " OK: $DEVCONTAINER ($DC_VERSION)"
fi
fi
echo ""
if [ "$ERRORS" -gt 0 ]; then
echo "::error::$ERRORS Go version mismatch(es) found. Run 'cd cli/azd && mage updateGoVersion $EXPECTED' to fix."
exit 1
fi
echo "All Go versions are consistent ($EXPECTED)."