-
Notifications
You must be signed in to change notification settings - Fork 387
[code-simplifier] refactor: extract awfVersionAtLeast helper to deduplicate version-check functions #31627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[code-simplifier] refactor: extract awfVersionAtLeast helper to deduplicate version-check functions #31627
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -633,111 +633,43 @@ func addCliProxyGHTokenToEnv(env map[string]string, workflowData *WorkflowData) | |
| } | ||
| } | ||
|
|
||
| // awfSupportsExcludeEnv returns true when the effective AWF version supports --exclude-env. | ||
| // | ||
| // The --exclude-env flag was introduced in AWF v0.25.3. Any workflow that pins an explicit | ||
| // version older than v0.25.3 must not emit --exclude-env or the run will fail at startup. | ||
| // | ||
| // Special cases: | ||
| // - No version override (firewallConfig is nil or has no Version): use DefaultFirewallVersion | ||
| // which is always ≥ AWFExcludeEnvMinVersion → returns true. | ||
| // - "latest": always returns true (latest is always a new release). | ||
| // - Any semver string ≥ AWFExcludeEnvMinVersion: returns true. | ||
| // - Any semver string < AWFExcludeEnvMinVersion: returns false. | ||
| // - Non-semver string (e.g. a branch name): returns false (conservative). | ||
| // awfSupportsExcludeEnv returns true when the effective AWF version supports --exclude-env | ||
| // (introduced in AWF v0.25.3). | ||
| func awfSupportsExcludeEnv(firewallConfig *FirewallConfig) bool { | ||
| var versionStr string | ||
| if firewallConfig != nil && firewallConfig.Version != "" { | ||
| versionStr = firewallConfig.Version | ||
| } else { | ||
| // No override → use the default, which is always ≥ the minimum. | ||
| return true | ||
| } | ||
|
|
||
| // "latest" means the newest release — always supports the flag. | ||
| if strings.EqualFold(versionStr, "latest") { | ||
| return true | ||
| } | ||
|
|
||
| // Normalise the v-prefix for semverutil.Compare. | ||
| minVersion := string(constants.AWFExcludeEnvMinVersion) | ||
| return semverutil.Compare(versionStr, minVersion) >= 0 | ||
| return awfVersionAtLeast(firewallConfig, constants.AWFExcludeEnvMinVersion) | ||
| } | ||
|
|
||
| // awfSupportsCliProxy returns true when the effective AWF version supports --difc-proxy-host | ||
| // and --difc-proxy-ca-cert. | ||
| // awfVersionAtLeast returns true when the effective AWF version is at or above minVersion. | ||
| // | ||
| // These flags were introduced in AWF v0.26.0 (replacing the earlier --enable-cli-proxy). | ||
| // Any workflow that pins an explicit version older than v0.26.0 must not emit CLI proxy | ||
| // flags or the run will fail at startup. | ||
| // | ||
| // Special cases: | ||
| // - No version override (firewallConfig is nil or has no Version): use DefaultFirewallVersion | ||
| // and compare against AWFCliProxyMinVersion. | ||
| // - "latest": always returns true (latest is always a new release). | ||
| // - Any semver string ≥ AWFCliProxyMinVersion: returns true. | ||
| // - Any semver string < AWFCliProxyMinVersion: returns false. | ||
| // - Non-semver string (e.g. a branch name): returns false (conservative). | ||
| func awfSupportsCliProxy(firewallConfig *FirewallConfig) bool { | ||
| // If firewallConfig has no version set, DefaultFirewallVersion is used. "latest" always | ||
| // returns true. Non-semver strings (e.g. branch names) return false (conservative). | ||
| func awfVersionAtLeast(firewallConfig *FirewallConfig, minVersion constants.Version) bool { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/improve-codebase-architecture] The helper is declared after its first caller ( |
||
| var versionStr string | ||
| if firewallConfig != nil && firewallConfig.Version != "" { | ||
| versionStr = firewallConfig.Version | ||
| } else { | ||
| // No override → use the default version for comparison. | ||
| versionStr = string(constants.DefaultFirewallVersion) | ||
| } | ||
|
|
||
| // "latest" means the newest release — always supports the flag. | ||
| if strings.EqualFold(versionStr, "latest") { | ||
| return true | ||
| } | ||
| return semverutil.Compare(versionStr, string(minVersion)) >= 0 | ||
| } | ||
|
|
||
| // Normalise the v-prefix for semverutil.Compare. | ||
| minVersion := string(constants.AWFCliProxyMinVersion) | ||
| return semverutil.Compare(versionStr, minVersion) >= 0 | ||
| // awfSupportsCliProxy returns true when the effective AWF version supports --difc-proxy-host | ||
| // and --difc-proxy-ca-cert (introduced in AWF v0.26.0). | ||
|
|
||
| func awfSupportsCliProxy(firewallConfig *FirewallConfig) bool { | ||
| return awfVersionAtLeast(firewallConfig, constants.AWFCliProxyMinVersion) | ||
| } | ||
|
|
||
| // awfSupportsAllowHostPorts returns true when the effective AWF version supports | ||
| // --allow-host-ports. | ||
| // | ||
| // Special cases: | ||
| // - No version override (firewallConfig is nil or has no Version): use DefaultFirewallVersion | ||
| // and compare against AWFAllowHostPortsMinVersion (currently this returns true because | ||
| // DefaultFirewallVersion is at or above the minimum supported version). | ||
| // - "latest": always returns true (latest is always a new release). | ||
| // - Any semver string ≥ AWFAllowHostPortsMinVersion: returns true. | ||
| // - Any semver string < AWFAllowHostPortsMinVersion: returns false. | ||
| // - Non-semver string (e.g. a branch name): returns false (conservative). | ||
| func awfSupportsAllowHostPorts(firewallConfig *FirewallConfig) bool { | ||
| var versionStr string | ||
| if firewallConfig != nil && firewallConfig.Version != "" { | ||
| versionStr = firewallConfig.Version | ||
| } else { | ||
| versionStr = string(constants.DefaultFirewallVersion) | ||
| } | ||
|
|
||
| if strings.EqualFold(versionStr, "latest") { | ||
| return true | ||
| } | ||
|
|
||
| minVersion := string(constants.AWFAllowHostPortsMinVersion) | ||
| return semverutil.Compare(versionStr, minVersion) >= 0 | ||
| return awfVersionAtLeast(firewallConfig, constants.AWFAllowHostPortsMinVersion) | ||
| } | ||
|
|
||
| // awfSupportsDockerHostPathPrefix returns true when the effective AWF version supports | ||
| // --docker-host-path-prefix. | ||
| func awfSupportsDockerHostPathPrefix(firewallConfig *FirewallConfig) bool { | ||
| var versionStr string | ||
| if firewallConfig != nil && firewallConfig.Version != "" { | ||
| versionStr = firewallConfig.Version | ||
| } else { | ||
| versionStr = string(constants.DefaultFirewallVersion) | ||
| } | ||
|
|
||
| if strings.EqualFold(versionStr, "latest") { | ||
| return true | ||
| } | ||
|
|
||
| minVersion := string(constants.AWFDockerHostPathPrefixMinVersion) | ||
| return semverutil.Compare(versionStr, minVersion) >= 0 | ||
| return awfVersionAtLeast(firewallConfig, constants.AWFDockerHostPathPrefixMinVersion) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/zoom-out] The behavioral equivalence for
awfSupportsExcludeEnvwith a nil/empty config relies on the invariantDefaultFirewallVersion >= AWFExcludeEnvMinVersion(currentlyv0.25.43 >= v0.25.3✅). This invariant is implicit — nothing enforces it at compile-time or in tests.If
DefaultFirewallVersionwere ever rolled back belowv0.25.3, this function would silently returnfalsefor unconfigured workflows instead oftrue, a subtle behavioral regression. Consider asserting it in the constants spec test:This makes the invariant visible and caught at test time rather than discovered in production.