Skip to content

Commit cbc6a92

Browse files
authored
fix(release): stop slot rotation corrupting self-referential shellcheck paths (#770)
## Summary Fixes #769. The `env.stub` shellcheck directive in the 8.0.0 init scripts was written as a repo-relative path carrying a version token (`# shellcheck source=docker/openemr/8.0.0/env.stub`). Because the scripts were registered as `current`-slot pins, advancing `current` 8.0.0 → 8.1.0 rewrote that directive to point at a sibling dir that never exists, breaking shellcheck CI on the auto rotation PR (#760). A `# shellcheck source=` comment is a path to the script's own sibling file, not a version pin — it should never carry a rotating token. ## Changes - `docker/openemr/8.0.0/openemr.sh`, `ssl.sh`: use the version-agnostic `SCRIPTDIR/env.stub` form (matching the existing convention already used for `devtoolsLibrary.source`). `SCRIPTDIR` resolves to the script's own dir at lint time and contains no token for the rotator to match. - `tools/release/versions.yml`: drop the two `shellcheck_source` entries. After the change above the files hold no version pin, so the linter no longer flags them — no `excludes:` entry needed. - `tools/release/tests/SlotRotatorTest.php`: regression test seeding a `*.sh` with a `SCRIPTDIR` directive plus a genuine rotating token, asserting the directive survives rotation byte-for-byte. ## Test plan - [x] `php bin/lint-versions.php` — `openemr.sh`/`ssl.sh` no longer flagged (the two remaining `rel_branch_ref` findings pre-exist on `master`, unrelated) - [x] `vendor/bin/phpunit` — 175 tests green, including the new regression - [x] Dry-run rotation reproducing #760 (`--current=8.1 --dry-run`) no longer touches the `# shellcheck source=` line in either script - [x] `shellcheck docker/openemr/8.0.0/openemr.sh ssl.sh` — clean
1 parent 0346602 commit cbc6a92

4 files changed

Lines changed: 47 additions & 13 deletions

File tree

docker/openemr/8.0.0/openemr.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set -e
2020
# source-follower without ever running it — BusyBox ash treats `.` as a
2121
# special builtin and exits the shell on file-not-found even with `|| true`.
2222
if false; then
23-
# shellcheck source=docker/openemr/8.0.0/env.stub
23+
# shellcheck source=SCRIPTDIR/env.stub
2424
. /root/env.stub
2525
fi
2626

docker/openemr/8.0.0/ssl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ set -e
1616
# source-follower without ever running it — BusyBox ash treats `.` as a
1717
# special builtin and exits the shell on file-not-found even with `|| true`.
1818
if false; then
19-
# shellcheck source=docker/openemr/8.0.0/env.stub
19+
# shellcheck source=SCRIPTDIR/env.stub
2020
. /root/env.stub
2121
fi
2222

tools/release/tests/SlotRotatorTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,37 @@ public function testReplacementAvoidsPartialVersionMatches(): void
195195
self::assertStringContainsString('rel-820', $after);
196196
}
197197

198+
public function testRotationLeavesScriptdirShellcheckDirectiveIntact(): void
199+
{
200+
$rotator = new SlotRotator($this->tmpDir, $this->registryPath);
201+
202+
$rotator->rotate([
203+
'current' => [
204+
'minor' => '8.2',
205+
'full' => '8.2.0',
206+
'branch' => 'rel-820',
207+
'docker_dir' => '8.2.0',
208+
],
209+
]);
210+
211+
$script = (string) file_get_contents($this->tmpDir . '/docker/openemr/8.0.0/openemr.sh');
212+
self::assertStringContainsString(
213+
'# shellcheck source=SCRIPTDIR/env.stub',
214+
$script,
215+
'self-referential SCRIPTDIR directive must survive rotation byte-for-byte',
216+
);
217+
self::assertStringNotContainsString(
218+
'source=docker/openemr',
219+
$script,
220+
'rotation must never inject a version path into a shellcheck source directive',
221+
);
222+
self::assertStringContainsString(
223+
"echo 'init for docker/openemr/8.2.0'",
224+
$script,
225+
'sanity: the genuine rotating docker_dir token should have been rewritten',
226+
);
227+
}
228+
198229
private function seedFixtures(): void
199230
{
200231
$this->writeFile('tools/release/versions.yml', <<<'YAML'
@@ -230,6 +261,9 @@ private function seedFixtures(): void
230261
- path: docker/openemr/8.0.0/Dockerfile
231262
slot: current
232263
kinds: [docker_clone_branch]
264+
- path: docker/openemr/8.0.0/openemr.sh
265+
slot: current
266+
kinds: [docker_dir_ref]
233267
- path: docker/openemr/8.1.0/Dockerfile
234268
slot: next
235269
kinds: [docker_arg_branch]
@@ -256,6 +290,17 @@ private function seedFixtures(): void
256290
$this->writeFile('docker/openemr/8.1.0/Dockerfile', "FROM alpine:3.21\nARG OPENEMR_VERSION=rel-810\n");
257291
$this->writeFile('docker/openemr/8.1.1/Dockerfile', "FROM alpine:3.21\nARG OPENEMR_VERSION=master\n");
258292

293+
// In-container init script for the current slot. It carries a rotating
294+
// docker_dir token (the path in the echo line) alongside a
295+
// self-referential `SCRIPTDIR` shellcheck directive that must never be
296+
// rewritten.
297+
$this->writeFile(
298+
'docker/openemr/8.0.0/openemr.sh',
299+
"#!/bin/sh\nset -e\n"
300+
. "# shellcheck source=SCRIPTDIR/env.stub\n. /root/env.stub\n"
301+
. "echo 'init for docker/openemr/8.0.0'\n",
302+
);
303+
259304
$this->writeFile(
260305
'docker/openemr/OVERVIEW.md',
261306
"| 8.0.0 | latest |\n| 8.1.0 | next |\n| 8.1.1 | dev |\n",

tools/release/versions.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ files:
122122
slot: all
123123
kinds: [dependabot_directory]
124124

125-
# In-container init scripts; reference their own dir as shellcheck source
126-
# comments, so they rotate with the slot's docker_dir. Only the 8.0.0/*.sh
127-
# files currently have these refs; the next/dev variants have no path
128-
# comments and will be picked up by the linter only if added later.
129-
- path: docker/openemr/8.0.0/openemr.sh
130-
slot: current
131-
kinds: [shellcheck_source]
132-
- path: docker/openemr/8.0.0/ssl.sh
133-
slot: current
134-
kinds: [shellcheck_source]
135-
136125
# Container-benchmarking docs reference the next-slot version as defaults.
137126
- path: utilities/container_benchmarking/README.md
138127
slot: next

0 commit comments

Comments
 (0)