|
75 | 75 | print "---\n"; |
76 | 76 | } |
77 | 77 |
|
| 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 | + |
78 | 98 | sub applyPatchOrPrintMsgIf($$$) { |
79 | 99 | # 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. |
80 | 101 |
|
81 | 102 | my ($patchID, $specName, $targetVers) = @_; |
82 | | - my $vers; |
| 103 | + my $vers = $versions{$specName}; |
| 104 | + my $submoduleVers = getVersFromGitmodules($specName); |
83 | 105 | my $key = $specName . $patchID; |
84 | 106 |
|
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"; |
91 | 118 | } 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"; |
93 | 122 | } |
94 | 123 | $patchMsgCount{$key}++; |
95 | 124 | return 0; |
96 | 125 | } |
97 | 126 |
|
| 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 | + |
98 | 160 | sub patchSpec_because_of_SemConv_DockerAPIVersions() { |
99 | 161 | return unless |
100 | 162 | # Restrict the patch to the proper spec, and section or file: |
101 | 163 | $ARGV =~ m|^tmp/semconv/docs/| |
102 | 164 | && |
103 | 165 | # 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'); |
109 | 168 |
|
110 | 169 | # Give infor about the patch: |
111 | 170 | # |
|
121 | 180 | }{$1/v1.52/$3}gx; |
122 | 181 | } |
123 | 182 |
|
| 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 | + |
124 | 196 | sub getVersFromSubmodule() { |
125 | 197 | my %repoNames = qw( |
126 | 198 | otlp opentelemetry-proto |
|
244 | 316 | ) |
245 | 317 | }{$otelSpecRepoUrl/tree/v$otelSpecVers/$2}gx; |
246 | 318 |
|
| 319 | + patchSpec_because_of_SemConv_DatabaseRenamedToDb(); |
| 320 | + |
247 | 321 | s|\.\./((?:examples/)?README\.md)|$otlpSpecRepoUrl/tree/v$otlpSpecVers/$1|g if $ARGV =~ /^tmp\/otlp/; |
248 | 322 |
|
249 | 323 | # Make website-local page references local: |
|
0 commit comments