Skip to content

Commit 6824843

Browse files
authored
CI: update Go SDK versions and use Go 1.24 for tests of Go coverage support (pantsbuild#22810)
Update the Go SDK versions available in CI to v1.25.3 and v1.24.9 from v1.19.x. Since Pants does not support the Go "coverage redesign" which became the only coverage implementation in Go 1.25, the coverage tests in `src/python/pants/backend/go/util_rules/coverage_test.py` are now conditioned on Go 1.24 being available on the system. (Those tests are skipped otherwise.) There are some other test fixes as well due to the upgrade from Go 1.19 to Go 1.25.
1 parent 238a20a commit 6824843

File tree

8 files changed

+262
-38
lines changed

8 files changed

+262
-38
lines changed

.github/workflows/public_repos.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,11 @@ jobs:
10731073
- name: Install Go
10741074
uses: actions/setup-go@v5
10751075
with:
1076-
go-version: 1.19.5
1076+
go-version: 1.25.3
1077+
- name: Install Go
1078+
uses: actions/setup-go@v5
1079+
with:
1080+
go-version: 1.24.9
10771081
- name: Pants on
10781082
run: |2
10791083

.github/workflows/release.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ jobs:
165165
- name: Install Go
166166
uses: actions/setup-go@v5
167167
with:
168-
go-version: 1.19.5
168+
go-version: 1.25.3
169+
- name: Install Go
170+
uses: actions/setup-go@v5
171+
with:
172+
go-version: 1.24.9
169173
- env:
170174
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY || '--DISABLED--' }}
171175
PANTS_PROCESS_EXECUTION_LOCAL_PARALLELISM: '1'
@@ -290,7 +294,11 @@ jobs:
290294
- name: Install Go
291295
uses: actions/setup-go@v5
292296
with:
293-
go-version: 1.19.5
297+
go-version: 1.25.3
298+
- name: Install Go
299+
uses: actions/setup-go@v5
300+
with:
301+
go-version: 1.24.9
294302
- env:
295303
ARCHFLAGS: -arch x86_64
296304
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY || '--DISABLED--' }}
@@ -410,7 +418,11 @@ jobs:
410418
- name: Install Go
411419
uses: actions/setup-go@v5
412420
with:
413-
go-version: 1.19.5
421+
go-version: 1.25.3
422+
- name: Install Go
423+
uses: actions/setup-go@v5
424+
with:
425+
go-version: 1.24.9
414426
- env:
415427
ARCHFLAGS: -arch arm64
416428
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY || '--DISABLED--' }}

.github/workflows/test.yaml

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,11 @@ jobs:
519519
- name: Install Go
520520
uses: actions/setup-go@v5
521521
with:
522-
go-version: 1.19.5
522+
go-version: 1.25.3
523+
- name: Install Go
524+
uses: actions/setup-go@v5
525+
with:
526+
go-version: 1.24.9
523527
- env:
524528
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY || '--DISABLED--' }}
525529
PANTS_PROCESS_EXECUTION_LOCAL_PARALLELISM: '1'
@@ -592,7 +596,11 @@ jobs:
592596
- name: Install Go
593597
uses: actions/setup-go@v5
594598
with:
595-
go-version: 1.19.5
599+
go-version: 1.25.3
600+
- name: Install Go
601+
uses: actions/setup-go@v5
602+
with:
603+
go-version: 1.24.9
596604
- env:
597605
ARCHFLAGS: -arch x86_64
598606
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY || '--DISABLED--' }}
@@ -675,7 +683,11 @@ jobs:
675683
- name: Install Go
676684
uses: actions/setup-go@v5
677685
with:
678-
go-version: 1.19.5
686+
go-version: 1.25.3
687+
- name: Install Go
688+
uses: actions/setup-go@v5
689+
with:
690+
go-version: 1.24.9
679691
- env:
680692
ARCHFLAGS: -arch arm64
681693
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY || '--DISABLED--' }}
@@ -977,7 +989,11 @@ jobs:
977989
- name: Install Go
978990
uses: actions/setup-go@v5
979991
with:
980-
go-version: 1.19.5
992+
go-version: 1.25.3
993+
- name: Install Go
994+
uses: actions/setup-go@v5
995+
with:
996+
go-version: 1.24.9
981997
- name: Download native binaries
982998
uses: actions/download-artifact@v4
983999
with:
@@ -1071,7 +1087,11 @@ jobs:
10711087
- name: Install Go
10721088
uses: actions/setup-go@v5
10731089
with:
1074-
go-version: 1.19.5
1090+
go-version: 1.25.3
1091+
- name: Install Go
1092+
uses: actions/setup-go@v5
1093+
with:
1094+
go-version: 1.24.9
10751095
- if: runner.os == 'Linux'
10761096
name: Download Apache `thrift` binary (Linux)
10771097
run: |
@@ -1183,7 +1203,11 @@ jobs:
11831203
- name: Install Go
11841204
uses: actions/setup-go@v5
11851205
with:
1186-
go-version: 1.19.5
1206+
go-version: 1.25.3
1207+
- name: Install Go
1208+
uses: actions/setup-go@v5
1209+
with:
1210+
go-version: 1.24.9
11871211
- if: runner.os == 'Linux'
11881212
name: Download Apache `thrift` binary (Linux)
11891213
run: |
@@ -1295,7 +1319,11 @@ jobs:
12951319
- name: Install Go
12961320
uses: actions/setup-go@v5
12971321
with:
1298-
go-version: 1.19.5
1322+
go-version: 1.25.3
1323+
- name: Install Go
1324+
uses: actions/setup-go@v5
1325+
with:
1326+
go-version: 1.24.9
12991327
- if: runner.os == 'Linux'
13001328
name: Download Apache `thrift` binary (Linux)
13011329
run: |
@@ -1407,7 +1435,11 @@ jobs:
14071435
- name: Install Go
14081436
uses: actions/setup-go@v5
14091437
with:
1410-
go-version: 1.19.5
1438+
go-version: 1.25.3
1439+
- name: Install Go
1440+
uses: actions/setup-go@v5
1441+
with:
1442+
go-version: 1.24.9
14111443
- if: runner.os == 'Linux'
14121444
name: Download Apache `thrift` binary (Linux)
14131445
run: |
@@ -1519,7 +1551,11 @@ jobs:
15191551
- name: Install Go
15201552
uses: actions/setup-go@v5
15211553
with:
1522-
go-version: 1.19.5
1554+
go-version: 1.25.3
1555+
- name: Install Go
1556+
uses: actions/setup-go@v5
1557+
with:
1558+
go-version: 1.24.9
15231559
- if: runner.os == 'Linux'
15241560
name: Download Apache `thrift` binary (Linux)
15251561
run: |
@@ -1631,7 +1667,11 @@ jobs:
16311667
- name: Install Go
16321668
uses: actions/setup-go@v5
16331669
with:
1634-
go-version: 1.19.5
1670+
go-version: 1.25.3
1671+
- name: Install Go
1672+
uses: actions/setup-go@v5
1673+
with:
1674+
go-version: 1.24.9
16351675
- if: runner.os == 'Linux'
16361676
name: Download Apache `thrift` binary (Linux)
16371677
run: |
@@ -1743,7 +1783,11 @@ jobs:
17431783
- name: Install Go
17441784
uses: actions/setup-go@v5
17451785
with:
1746-
go-version: 1.19.5
1786+
go-version: 1.25.3
1787+
- name: Install Go
1788+
uses: actions/setup-go@v5
1789+
with:
1790+
go-version: 1.24.9
17471791
- if: runner.os == 'Linux'
17481792
name: Download Apache `thrift` binary (Linux)
17491793
run: |
@@ -1855,7 +1899,11 @@ jobs:
18551899
- name: Install Go
18561900
uses: actions/setup-go@v5
18571901
with:
1858-
go-version: 1.19.5
1902+
go-version: 1.25.3
1903+
- name: Install Go
1904+
uses: actions/setup-go@v5
1905+
with:
1906+
go-version: 1.24.9
18591907
- if: runner.os == 'Linux'
18601908
name: Download Apache `thrift` binary (Linux)
18611909
run: |
@@ -1967,7 +2015,11 @@ jobs:
19672015
- name: Install Go
19682016
uses: actions/setup-go@v5
19692017
with:
1970-
go-version: 1.19.5
2018+
go-version: 1.25.3
2019+
- name: Install Go
2020+
uses: actions/setup-go@v5
2021+
with:
2022+
go-version: 1.24.9
19712023
- if: runner.os == 'Linux'
19722024
name: Download Apache `thrift` binary (Linux)
19732025
run: |
@@ -2079,7 +2131,11 @@ jobs:
20792131
- name: Install Go
20802132
uses: actions/setup-go@v5
20812133
with:
2082-
go-version: 1.19.5
2134+
go-version: 1.25.3
2135+
- name: Install Go
2136+
uses: actions/setup-go@v5
2137+
with:
2138+
go-version: 1.24.9
20832139
- if: runner.os == 'Linux'
20842140
name: Download Apache `thrift` binary (Linux)
20852141
run: |
@@ -2168,7 +2224,11 @@ jobs:
21682224
- name: Install Go
21692225
uses: actions/setup-go@v5
21702226
with:
2171-
go-version: 1.19.5
2227+
go-version: 1.25.3
2228+
- name: Install Go
2229+
uses: actions/setup-go@v5
2230+
with:
2231+
go-version: 1.24.9
21722232
- name: Download native binaries
21732233
uses: actions/download-artifact@v4
21742234
with:
@@ -2238,7 +2298,11 @@ jobs:
22382298
- name: Install Go
22392299
uses: actions/setup-go@v5
22402300
with:
2241-
go-version: 1.19.5
2301+
go-version: 1.25.3
2302+
- name: Install Go
2303+
uses: actions/setup-go@v5
2304+
with:
2305+
go-version: 1.24.9
22422306
- name: Set up Python 3.9, 3.10, 3.12, 3.13, 3.11
22432307
uses: actions/setup-python@v5
22442308
with:

src/python/pants/backend/go/conftest.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,122 @@ def _go_present() -> bool:
1919
return True
2020

2121

22+
def _parse_go_version(version_string: str) -> tuple[int, int] | None:
23+
"""Parse 'go1.24.3' output to (1, 24)."""
24+
if not version_string.startswith("go"):
25+
return None
26+
27+
# Strip "go" prefix and split on "."
28+
version_parts = version_string[2:].split(".")
29+
30+
if len(version_parts) < 2:
31+
return None
32+
33+
try:
34+
major = int(version_parts[0])
35+
minor = int(version_parts[1])
36+
return (major, minor)
37+
except (ValueError, IndexError):
38+
return None
39+
40+
41+
@lru_cache(None)
42+
def _discover_go_binaries() -> list[tuple[str, tuple[int, int]]]:
43+
"""Discover all Go binaries in PATH and return sorted by version (newest first)."""
44+
path_env = os.getenv("PATH", "")
45+
if not path_env:
46+
return []
47+
48+
go_binaries = []
49+
seen_paths = set()
50+
51+
for path_dir in path_env.split(os.pathsep):
52+
if not path_dir or not os.path.isdir(path_dir):
53+
continue
54+
55+
go_binary = os.path.join(path_dir, "go")
56+
if os.path.isfile(go_binary) and os.access(go_binary, os.X_OK):
57+
# Resolve symlinks to avoid duplicates.
58+
real_path = os.path.realpath(go_binary)
59+
if real_path in seen_paths:
60+
continue
61+
seen_paths.add(real_path)
62+
63+
try:
64+
result = subprocess.run(
65+
[go_binary, "env", "GOVERSION"],
66+
capture_output=True,
67+
text=True,
68+
timeout=5,
69+
check=False,
70+
)
71+
if result.returncode == 0:
72+
version = _parse_go_version(result.stdout.strip())
73+
if version:
74+
go_binaries.append((go_binary, version))
75+
except (subprocess.TimeoutExpired, FileNotFoundError, PermissionError):
76+
continue
77+
78+
# Sort by version (newest first).
79+
go_binaries.sort(key=lambda x: x[1], reverse=True)
80+
return go_binaries
81+
82+
83+
def pytest_generate_tests(metafunc):
84+
"""Parametrize tests that require specific Go versions."""
85+
# Check if the test has the require_go_version_max marker.
86+
marker = metafunc.definition.get_closest_marker("require_go_version_max")
87+
if not marker:
88+
return
89+
90+
# Extract the maximum version from the marker.
91+
if len(marker.args) < 2:
92+
pytest.fail(
93+
f"require_go_version_max marker requires 2 args (major, minor), got {marker.args}"
94+
)
95+
return
96+
97+
max_major, max_minor = marker.args[0], marker.args[1]
98+
max_version = (max_major, max_minor)
99+
100+
# Discover available Go binaries
101+
available_go = _discover_go_binaries()
102+
103+
# Filter for compatible versions (<= max_version)
104+
compatible_go = [(path, version) for path, version in available_go if version <= max_version]
105+
106+
# Parametrize the test if it accepts a `go_binary_path` fixture.
107+
if "go_binary_path" in metafunc.fixturenames:
108+
if compatible_go:
109+
# Use the newest compatible version.
110+
best_go_path, best_version = compatible_go[0]
111+
metafunc.parametrize(
112+
"go_binary_path",
113+
[best_go_path],
114+
ids=[f"go{best_version[0]}.{best_version[1]}"],
115+
)
116+
else:
117+
# Parametrize with None and mark to skip, so the test shows as skipped rather than uncollected.
118+
available_versions = [f"{v[0]}.{v[1]}" for _, v in available_go]
119+
skip_msg = (
120+
f"Test requires Go <= {max_major}.{max_minor}, but only found: "
121+
f"{', '.join(available_versions) if available_versions else 'none'}"
122+
)
123+
metafunc.parametrize(
124+
"go_binary_path",
125+
[pytest.param(None, marks=pytest.mark.skip(reason=skip_msg))],
126+
ids=["no-compatible-go"],
127+
)
128+
129+
130+
def pytest_configure(config):
131+
"""Register custom markers."""
132+
config.addinivalue_line(
133+
"markers",
134+
"require_go_version_max(major, minor): mark test to require Go version <= specified",
135+
)
136+
137+
22138
def pytest_runtest_setup(item: pytest.Item) -> None:
23139
if not _go_present():
24140
pytest.skip(reason="`go` not present on PATH")

src/python/pants/backend/go/lint/vet/rules_integration_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def _check_err_msg(result_stderr: str) -> None:
133133
# Note: `go vet` sometimes emits "fmt.Printf" and sometimes just "Printf", depending on conditions
134134
# which are unclear so let the `fmt.` part be optional.
135135
assert re.search(
136-
r"./f.go:4:5: (fmt\.)?Printf format %s reads arg #1, but call has 0 args", result_stderr
137-
)
136+
r"./f.go.*Printf format %s reads arg #1, but call has 0 args", result_stderr
137+
), f"Expected vet to find an issue:\n\nstderr:\n{result_stderr}"
138138

139139

140140
def test_failing(rule_runner: RuleRunner) -> None:

0 commit comments

Comments
 (0)