Skip to content

Commit 6f43910

Browse files
chalinvitorvasc
authored andcommitted
feat(patch-helper): add max version parameter to applyPatchOrPrintMsgIf function
Signed-off-by: Vitor Vasconcellos <[email protected]>
1 parent 82119b9 commit 6f43910

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

scripts/content-modules/adjust-pages.pl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,31 @@ ($)
9595
return $vers;
9696
}
9797

98-
sub applyPatchOrPrintMsgIf($$$) {
98+
sub applyPatchOrPrintMsgIf($$$;$) {
9999
# Returns truthy if patch should be applied, otherwise prints message (once) as to why not.
100-
# The patch is applied if $submoduleVers starts with $targetVers.
100+
# The patch is applied if $submoduleVers starts with $targetVers and is <= $maxVers (if provided).
101101

102-
my ($patchID, $specName, $targetVers) = @_;
102+
my ($patchID, $specName, $targetVers, $maxVers) = @_;
103103
my $vers = $versions{$specName};
104104
my $submoduleVers = getVersFromGitmodules($specName);
105105
my $key = $specName . $patchID;
106106

107107
return 0 if $patchMsgCount{$key} && $patchMsgCount{$key} ne 'Apply the patch';
108108

109+
if ($maxVers && $submoduleVers && $submoduleVers gt $maxVers) {
110+
print STDOUT "INFO: $0: skipping patch '$patchID' since spec '$specName' " .
111+
"submodule is at version '$submoduleVers' > '$maxVers' (patch max version); " .
112+
"the fix is likely in upstream now\n" unless $patchMsgCount{$key};
113+
$patchMsgCount{$key}++;
114+
return 0;
115+
}
116+
109117
if ($submoduleVers && $submoduleVers =~ /^$targetVers/) {
110118
print STDOUT "INFO: $0: applying patch '$patchID' since spec '$specName' " .
111119
"submodule is at version '$submoduleVers', and it starts with the patch target '$targetVers'" .
112120
"\n" unless $patchMsgCount{$key};
113121
return $patchMsgCount{$key} = 'Apply the patch';
114-
} elsif ($vers ge $targetVers) {
122+
} elsif (($maxVers && $vers gt $maxVers) || $vers ge $targetVers) {
115123
print STDOUT "INFO: $0: patch '$patchID' is probably obsolete now that " .
116124
"spec '$specName' is at version '$vers' >= '$targetVers' (patch target version); " .
117125
"if so, remove the patch\n";
@@ -137,9 +145,13 @@ ()
137145
# Call helper function that will cause the function to return early if the
138146
# current version of the named spec (arg 2) is greater than the target
139147
# version (arg 3). The first argument is a unique id that will be printed if
140-
# the patch is outdated. Otherwise, if the patch is still relevant we fall
141-
# through to the body of this patch function.
148+
# the patch is outdated. An optional 4th argument (maxVers) specifies the
149+
# upper bound - the patch won't apply if submodule version > maxVers.
150+
# Otherwise, if the patch is still relevant we fall through to the body
151+
# of this patch function.
142152
applyPatchOrPrintMsgIf('2026-01-01-some-unique-id', 'semconv', '1.39.0-dev');
153+
# Or with an upper bound:
154+
# applyPatchOrPrintMsgIf('2026-01-01-some-unique-id', 'semconv', '1.39.0', '1.40.0');
143155

144156
# Give infor about the patch:
145157
#
@@ -160,7 +172,7 @@ ()
160172
# Restrict the patch to the proper spec, and section or file:
161173
# Note that here we replace links into semconv from the spec
162174
$ARGV =~ m|^tmp/otel/specification/|
163-
&& applyPatchOrPrintMsgIf('2025-11-26-database-section-renamed-to-db', 'spec', '1.53.0');
175+
&& applyPatchOrPrintMsgIf('2025-11-26-database-section-renamed-to-db', 'spec', '1.53.0', '1.53.0');
164176

165177
# Give infor about the patch, see:
166178
# https://github.com/open-telemetry/opentelemetry.io/pull/8311#issue-3577941378
@@ -172,7 +184,7 @@ ()
172184
sub patchSpec_because_of_SemConv_MetricRPCServerDurationRenamedToMetricRPCServerCallDuration() {
173185
return unless
174186
$ARGV =~ m|^tmp/otel/specification/|
175-
&& applyPatchOrPrintMsgIf('2025-12-05-metric-rpc-server-duration-renamed-to-rpc-server-call-duration', 'spec', '1.53.0');
187+
&& applyPatchOrPrintMsgIf('2025-12-05-metric-rpc-server-duration-renamed-to-rpc-server-call-duration', 'spec', '1.53.0', '1.53.0');
176188

177189
# Give infor about the patch, see:
178190
# https://github.com/open-telemetry/opentelemetry-specification/pull/4778

0 commit comments

Comments
 (0)