Skip to content

Commit c3948f3

Browse files
committed
Enhance adjust-pages patch logic to target only one version; add patches
1 parent 893e0e3 commit c3948f3

File tree

1 file changed

+87
-13
lines changed

1 file changed

+87
-13
lines changed

scripts/content-modules/adjust-pages.pl

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,37 +75,96 @@ ()
7575
print "---\n";
7676
}
7777

78+
sub getVersFromGitmodules($) {
79+
# Returns the pinned version of the submodule $specName from .gitmodules, or undef if not found.
80+
my ($specName) = @_;
81+
my $pinKey = "$specName-pin";
82+
83+
open(my $fh, '<', '.gitmodules') or return undef;
84+
my $vers;
85+
86+
while (my $line = <$fh>) {
87+
if ($line =~ /^\s*$pinKey\s*=\s*(.+)/) {
88+
$vers = $1;
89+
chomp($vers);
90+
$vers =~ s/^v//; # Remove leading v
91+
last;
92+
}
93+
}
94+
close($fh);
95+
return $vers;
96+
}
97+
7898
sub applyPatchOrPrintMsgIf($$$) {
7999
# 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.
80101

81102
my ($patchID, $specName, $targetVers) = @_;
82-
my $vers;
103+
my $vers = $versions{$specName};
104+
my $submoduleVers = getVersFromGitmodules($specName);
83105
my $key = $specName . $patchID;
84106

85-
return 0 if $patchMsgCount{$key};
86-
87-
if (($vers = $versions{$specName}) gt $targetVers) {
88-
print STDOUT "INFO: remove obsolete patch '$patchID' now that spec '$specName' is at v$vers > v$targetVers - $0\n";
89-
} elsif (($vers = $versFromSubmod{$specName}) gt $targetVers) {
90-
print STDOUT "INFO [$patchID]: skipping patch '$patchID' since spec '$specName' submodule is at v$vers > v$targetVers - $0\n";
107+
return 0 if $patchMsgCount{$key} && $patchMsgCount{$key} ne 'Apply the patch';
108+
109+
if ($submoduleVers && $submoduleVers =~ /^$targetVers/) {
110+
print STDOUT "INFO: $0: applying patch '$patchID' since spec '$specName' " .
111+
"submodule is at version '$submoduleVers', and it starts with the patch target '$targetVers'" .
112+
"\n" unless $patchMsgCount{$key};
113+
return $patchMsgCount{$key} = 'Apply the patch';
114+
} elsif ($vers ge $targetVers) {
115+
print STDOUT "INFO: $0: patch '$patchID' is probably obsolete now that " .
116+
"spec '$specName' is at version '$vers' >= '$targetVers' (patch target version); " .
117+
"if so, remove the patch\n";
91118
} else {
92-
return 'Apply the patch';
119+
print STDOUT "INFO: $0: skipping patch '$patchID' since spec '$specName' " .
120+
"submodule is at version '$vers' < '$targetVers' (patch target version); " .
121+
"and submodule version '$submoduleVers' doesn't start with the patch target '$targetVers'\n";
93122
}
94123
$patchMsgCount{$key}++;
95124
return 0;
96125
}
97126

127+
# =================================================================================
128+
# KEEP THE FOLLOWING AS A TEMPLATE; copy it and modify it as needed.
129+
# =================================================================================
130+
sub patchSpec_because_of_SemConv_DockerAPIVersions_AsTemplate() {
131+
return unless
132+
# Restrict the patch to the proper spec, and section or file:
133+
$ARGV =~ m|^tmp/semconv/docs/|
134+
&&
135+
# Call helper function that will cause the function to return early if the
136+
# patch should not be applied. The patch is applied if the submodule version
137+
# (from .gitmodules) starts with the target version (arg 3). The first
138+
# argument is a unique id that will be printed if the patch is outdated.
139+
# Otherwise, if the patch is still relevant we fall through to the body of
140+
# this patch function.
141+
#
142+
# Specify the target version as, e.g., '1.38.0', or to apply only to dev
143+
# versions, use '1.38.0-' with a trailing hyphen.
144+
applyPatchOrPrintMsgIf('2025-11-21-docker-api-versions', 'semconv', '1.38.0');
145+
146+
# Give infor about the patch:
147+
#
148+
# For the problematic links, see:
149+
# https://github.com/open-telemetry/semantic-conventions/issues/3103
150+
#
151+
# Replace older Docker API versions with the latest one like in:
152+
# https://github.com/open-telemetry/semantic-conventions/pull/3093
153+
154+
# This is the actual regex-based patch code:
155+
s{
156+
(https://docs.docker.com/reference/api/engine/version)/v1.(43|51)/(\#tag/)
157+
}{$1/v1.52/$3}gx;
158+
}
159+
98160
sub patchSpec_because_of_SemConv_DockerAPIVersions() {
99161
return unless
100162
# Restrict the patch to the proper spec, and section or file:
101163
$ARGV =~ m|^tmp/semconv/docs/|
102164
&&
103165
# Call helper function that will cause the function to return early if the
104-
# current version of the named spec (arg 2) is greater than the target
105-
# version (arg 3). The first argument is a unique id that will be printed if
106-
# the patch is outdated. Otherwise, if the patch is still relevant we fall
107-
# through to the body of this patch function.
108-
applyPatchOrPrintMsgIf('2025-11-21-docker-api-versions', 'semconv', '1.39.0-dev');
166+
# patch should not be applied. See patch template above for details.
167+
applyPatchOrPrintMsgIf('2025-11-21-docker-api-versions', 'semconv', '1.38.0');
109168

110169
# Give infor about the patch:
111170
#
@@ -121,6 +180,19 @@ ()
121180
}{$1/v1.52/$3}gx;
122181
}
123182

183+
sub patchSpec_because_of_SemConv_DatabaseRenamedToDb() {
184+
return unless
185+
# Restrict the patch to the proper spec, and section or file:
186+
# Note that here we replace links into semconv from the spec
187+
$ARGV =~ m|^tmp/otel/specification/|
188+
&& applyPatchOrPrintMsgIf('2025-11-26-database-section-renamed-to-db', 'semconv', '1.38.0-');
189+
190+
# Give infor about the patch, see:
191+
# https://github.com/open-telemetry/opentelemetry.io/pull/8311#issue-3577941378
192+
193+
s|(/semconv)/database(/database-)|$1/db$2|g;
194+
}
195+
124196
sub getVersFromSubmodule() {
125197
my %repoNames = qw(
126198
otlp opentelemetry-proto
@@ -244,6 +316,8 @@ ()
244316
)
245317
}{$otelSpecRepoUrl/tree/v$otelSpecVers/$2}gx;
246318

319+
patchSpec_because_of_SemConv_DatabaseRenamedToDb();
320+
247321
s|\.\./((?:examples/)?README\.md)|$otlpSpecRepoUrl/tree/v$otlpSpecVers/$1|g if $ARGV =~ /^tmp\/otlp/;
248322

249323
# Make website-local page references local:

0 commit comments

Comments
 (0)