Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(ci): check the repo out in boot-smoke so the non-root gate can run

Yudhi Armyndharisdec887d306ad
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index f76737e16..34040bbc1 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -487,6 +487,11 @@ jobs:
packages: read
needs: [docker]
steps:
+ # Required by the non-root check below, which runs a script from the repo. Without it the
+ # step exits 127 and this job — the only gate between a root image and `latest` — fails on
+ # every tag instead of guarding anything.
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
+
- name: Set up QEMU
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4
diff --git a/src/common/ci-privilege-gate.spec.ts b/src/common/ci-privilege-gate.spec.ts
index 6158e022e..bf2f76fad 100644
--- a/src/common/ci-privilege-gate.spec.ts
+++ b/src/common/ci-privilege-gate.spec.ts
@@ -16,11 +16,26 @@ import * as yaml from 'js-yaml';
const workflowDir = path.join(__dirname, '..', '..', '.github', 'workflows');
-type Workflow = { jobs?: Record<string, { steps?: Array<{ name?: string; run?: string; with?: unknown }> }> };
+type Step = { name?: string; run?: string; uses?: string; with?: unknown };
+type Workflow = { jobs?: Record<string, { steps?: Step[] }> };
+
+function workflowOf(file: string): Workflow {
+ return yaml.load(fs.readFileSync(path.join(workflowDir, file), 'utf8')) as Workflow;
+}
function runCommandsOf(file: string): string[] {
- const doc = yaml.load(fs.readFileSync(path.join(workflowDir, file), 'utf8')) as Workflow;
- return Object.values(doc.jobs ?? {}).flatMap(job => (job.steps ?? []).map(step => step.run ?? ''));
+ return Object.values(workflowOf(file).jobs ?? {}).flatMap(job => (job.steps ?? []).map(step => step.run ?? ''));
+}
+
+/** Jobs that execute a repo-relative path, paired with whether the job ever checks the repo out. */
+function jobsRunningRepoScripts(file: string): Array<{ job: string; scripts: string[]; hasCheckout: boolean }> {
+ return Object.entries(workflowOf(file).jobs ?? {})
+ .map(([job, def]) => {
+ const steps = def.steps ?? [];
+ const scripts = steps.flatMap(step => [...(step.run ?? '').matchAll(/(?:^|\s)(\.\/[\w./-]+)/g)].map(m => m[1]));
+ return { job, scripts, hasCheckout: steps.some(step => (step.uses ?? '').startsWith('actions/checkout')) };
+ })
+ .filter(entry => entry.scripts.length > 0);
}
describe('the non-root drop is enforced, not merely documented', () => {
@@ -45,3 +60,32 @@ describe('the non-root drop is enforced, not merely documented', () => {
expect(entrypoint).toMatch(/exec\s+gosu\s+openwa/);
});
});
+
+/**
+ * Invoking the script is not the same as being able to run it. `boot-smoke` in release.yml called
+ * `./scripts/smoke-test-non-root.sh` from a job that never checks the repo out — the file is simply
+ * absent from the workspace, so the step exits 127 and the ONLY path that publishes `latest` fails
+ * at every tag. Fail-closed, but the release path was broken rather than guarded.
+ *
+ * The gate above could not see it: it binds the text of `run:`, and the text was correct. This binds
+ * the precondition instead, for every job in every workflow — a repo-relative command needs the repo.
+ */
+describe('a job that runs a repo script checks the repo out', () => {
+ const workflows = fs.readdirSync(workflowDir).filter(f => f.endsWith('.yml') || f.endsWith('.yaml'));
+
+ // Non-vacuity control: the finder must actually see jobs, or every assertion below passes on an
+ // empty set. Anchor on a workflow known to run repo scripts.
+ it('finds jobs that run repo-relative scripts', () => {
+ expect(workflows.length).toBeGreaterThan(0);
+ const all = workflows.flatMap(f => jobsRunningRepoScripts(f));
+ expect(all.length).toBeGreaterThan(0);
+ expect(all.some(e => e.scripts.some(s => s.includes('scripts/')))).toBe(true);
+ });
+
+ it.each(workflows)('%s: every job running ./… also runs actions/checkout', file => {
+ const offenders = jobsRunningRepoScripts(file)
+ .filter(entry => !entry.hasCheckout)
+ .map(entry => `${entry.job} runs ${entry.scripts.join(', ')} without actions/checkout`);
+ expect(offenders).toEqual([]);
+ });
+});