Skip to content

Commit 11f139c

Browse files
Copilotpelikhan
andauthored
fix: normalize version strings in blocked versions check
Use case-insensitive normalization to ensure v1.0.0 and 1.0.0 are treated as the same version in blocked versions comparison. Update tests accordingly. Agent-Logs-Url: https://github.com/github/gh-aw/sessions/59710bfc-6f7b-4d62-ae00-03f2f989ad07 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent c6a9a2f commit 11f139c

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

actions/setup/js/check_version_updates.cjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ const https = require("https");
1818

1919
const CONFIG_URL = "https://raw.githubusercontent.com/github/gh-aw/main/config.json";
2020

21+
/**
22+
* Normalize a version string by stripping the leading "v" prefix if present.
23+
* This ensures "v1.0.0" and "1.0.0" are treated as equivalent.
24+
*
25+
* @param {string} version
26+
* @returns {string}
27+
*/
28+
function normalizeVersion(version) {
29+
return version.startsWith("v") ? version.slice(1) : version;
30+
}
31+
2132
/**
2233
* Parse a semver-like version string into an array of numeric parts.
2334
* Strips a leading "v" if present.
@@ -114,8 +125,9 @@ async function main() {
114125
const blockedVersions = Array.isArray(config.blockedVersions) ? config.blockedVersions : [];
115126
const minimumVersion = typeof config.minimumVersion === "string" ? config.minimumVersion : "";
116127

117-
// Check blocked versions
118-
if (blockedVersions.includes(compiledVersion)) {
128+
// Check blocked versions (normalize both sides to ignore leading "v" prefix)
129+
const normalizedCompiled = normalizeVersion(compiledVersion);
130+
if (blockedVersions.some(v => normalizeVersion(v) === normalizedCompiled)) {
119131
core.summary
120132
.addRaw("### ❌ Blocked compile-agentic version\n\n")
121133
.addRaw(`The compile-agentic version \`${compiledVersion}\` is **blocked** and cannot be used to run workflows.\n\n`)

actions/setup/js/check_version_updates.test.cjs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,20 @@ describe("check_version_updates", () => {
170170
expect(mockCore.setFailed).not.toHaveBeenCalled();
171171
});
172172

173-
it("should handle version strings without leading 'v'", async () => {
173+
it("should block version when config uses version without 'v' prefix", async () => {
174174
process.env.GH_AW_COMPILED_VERSION = "v1.0.0";
175175
mockHttpsSuccess(JSON.stringify({ blockedVersions: ["1.0.0"], minimumVersion: "" }));
176-
// "v1.0.0" is NOT in ["1.0.0"] because includes() uses exact string match
176+
// "v1.0.0" should be blocked by "1.0.0" after normalization
177177
await checkVersionUpdates.main();
178-
expect(mockCore.setFailed).not.toHaveBeenCalled();
178+
expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining("Blocked compile-agentic version"));
179+
});
180+
181+
it("should block version regardless of 'v' prefix in compiled version", async () => {
182+
process.env.GH_AW_COMPILED_VERSION = "1.0.0";
183+
mockHttpsSuccess(JSON.stringify({ blockedVersions: ["v1.0.0"], minimumVersion: "" }));
184+
// "1.0.0" should be blocked by "v1.0.0" after normalization
185+
await checkVersionUpdates.main();
186+
expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining("Blocked compile-agentic version"));
179187
});
180188

181189
it("should fail when version is blocked with exact string match", async () => {

0 commit comments

Comments
 (0)