Skip to content

Commit 607cb23

Browse files
committed
ci(runners): log in before the README walkthrough pulls its database
e2e/tests/prisma-example-readme.e2e.test.ts runs the Prisma example's README, and the README runs `docker compose up -d`, which pulls postgres:16 from Docker Hub. The login test cannot see a pull made from test code. Two RunsOn jobs run that test: the README walkthrough job, and tests.yml's e2e-tests, whose login came after the step. The walkthrough job now logs in before the step, and e2e-tests logs in before "Run E2E tests". HIDDEN_PULLS in the login test names both steps as pulls, and the test fails when an entry names a step that is gone.
1 parent cc68e38 commit 607cb23

3 files changed

Lines changed: 64 additions & 18 deletions

File tree

‎.github/workflows/prisma-example-readme-e2e.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,24 @@ jobs:
158158
- name: Build @cipherstash/stack-prisma
159159
run: pnpm exec turbo run build --filter @cipherstash/stack-prisma
160160

161+
# Docker Hub refuses pulls without a login after too many from one
162+
# address, and RunsOn machines reach that limit. With either secret empty,
163+
# as on a fork's pull request, this step does nothing and pulls stay
164+
# anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs
165+
# requires it.
166+
- name: Log in to Docker Hub
167+
env:
168+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
169+
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
170+
run: |
171+
set -euo pipefail
172+
if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then
173+
echo "No Docker Hub credentials, so image pulls stay anonymous."
174+
exit 0
175+
fi
176+
printf '%s' "$DOCKER_HUB_PASSWORD" |
177+
docker login --username "$DOCKER_HUB_USERNAME" --password-stdin
178+
161179
- name: Run README walkthrough e2e
162180
run: pnpm exec turbo run test:e2e --filter @cipherstash/e2e -- --run tests/prisma-example-readme.e2e.test.ts
163181

‎.github/workflows/tests.yml‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -468,23 +468,6 @@ jobs:
468468
id: auth-binding
469469
uses: ./.github/actions/build-auth-binding
470470

471-
# Run the standalone `e2e/` workspace via turbo so the `^build`
472-
# dep on the `test:e2e` task builds cli + wizard first. CLI's own
473-
# E2E (`languages/typescript/packages/cli/tests/e2e/**`) is covered by the `run-tests`
474-
# job above; we filter to the new workspace here to avoid duplication.
475-
- name: Run E2E tests
476-
run: pnpm exec turbo run test:e2e --filter @cipherstash/e2e
477-
478-
# The step above runs under turbo's strict env mode, which filters out
479-
# every env var `turbo.json` does not declare, so the job-level CS_*
480-
# never reach vitest there and auth-gated suites skip. The
481-
# protect-dynamodb compatibility suite proves a migration claim made to
482-
# customers, so the default e2e config leaves it out and it runs here
483-
# with `--env-mode=loose`, which lets the credentials through. It fails
484-
# rather than skips if they are missing.
485-
- name: Run the protect-dynamodb compatibility suite
486-
run: pnpm exec turbo run test:protect-compat --filter @cipherstash/e2e --env-mode=loose
487-
488471
# Docker Hub refuses pulls without a login after too many from one
489472
# address, and RunsOn machines reach that limit. With either secret empty,
490473
# as on a fork's pull request, this step does nothing and pulls stay
@@ -503,6 +486,23 @@ jobs:
503486
printf '%s' "$DOCKER_HUB_PASSWORD" |
504487
docker login --username "$DOCKER_HUB_USERNAME" --password-stdin
505488
489+
# Run the standalone `e2e/` workspace via turbo so the `^build`
490+
# dep on the `test:e2e` task builds cli + wizard first. CLI's own
491+
# E2E (`languages/typescript/packages/cli/tests/e2e/**`) is covered by the `run-tests`
492+
# job above; we filter to the new workspace here to avoid duplication.
493+
- name: Run E2E tests
494+
run: pnpm exec turbo run test:e2e --filter @cipherstash/e2e
495+
496+
# The step above runs under turbo's strict env mode, which filters out
497+
# every env var `turbo.json` does not declare, so the job-level CS_*
498+
# never reach vitest there and auth-gated suites skip. The
499+
# protect-dynamodb compatibility suite proves a migration claim made to
500+
# customers, so the default e2e config leaves it out and it runs here
501+
# with `--env-mode=loose`, which lets the credentials through. It fails
502+
# rather than skips if they are missing.
503+
- name: Run the protect-dynamodb compatibility suite
504+
run: pnpm exec turbo run test:protect-compat --filter @cipherstash/e2e --env-mode=loose
505+
506506
# The DynamoDB <-> Postgres cross-store suite moves protect-dynamodb
507507
# 6.0.1 items into EQL v3 columns and back, so it needs a database.
508508
# `integration-db` gives this job its own compose project and ephemeral

‎scripts/__tests__/workflow-docker-hub-login.test.mjs‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ function pullingTasks(index) {
212212

213213
const PULLING_TASKS = pullingTasks(taskIndex())
214214

215+
// Pulls this file cannot find, because test code or a README the test runs
216+
// starts the container. Each named step counts as a pull.
217+
export const HIDDEN_PULLS = {
218+
'.github/workflows/prisma-example-readme-e2e.yml#walkthrough': {
219+
step: 'Run README walkthrough e2e',
220+
reason:
221+
"e2e/tests/prisma-example-readme.e2e.test.ts runs the Prisma example's README, whose `docker compose up -d` pulls postgres:16.",
222+
},
223+
'.github/workflows/tests.yml#e2e-tests': {
224+
step: 'Run E2E tests',
225+
reason: 'e2e/vitest.config.ts includes the same README walkthrough test.',
226+
},
227+
}
228+
215229
// ---------------------------------------------------------------------------
216230
// Steps and jobs
217231
// ---------------------------------------------------------------------------
@@ -297,7 +311,10 @@ export function jobFindings(where, job, ref) {
297311
)
298312
}
299313
const steps = job.steps ?? []
300-
const firstPull = steps.findIndex((step) => stepPulls(step))
314+
const hidden = HIDDEN_PULLS[ref]?.step
315+
const firstPull = steps.findIndex(
316+
(step) => stepPulls(step) || (hidden && step?.name === hidden),
317+
)
301318
if (firstPull === -1) return findings
302319
const logins = steps
303320
.map((step, i) => ({ i, finding: loginFinding(step) }))
@@ -385,6 +402,17 @@ describe('Docker Hub login on RunsOn', () => {
385402
expect(callerFindings()).toEqual([])
386403
})
387404

405+
it('names a RunsOn job and a real step for every hidden pull', () => {
406+
// A stale entry would stop guarding the pull it was written for.
407+
const stale = Object.entries(HIDDEN_PULLS)
408+
.filter(([ref, { step }]) => {
409+
const entry = jobs.find((j) => j.ref === ref)
410+
return !(entry?.job.steps ?? []).some((s) => s?.name === step)
411+
})
412+
.map(([ref]) => ref)
413+
expect(stale).toEqual([])
414+
})
415+
388416
// Every job in the tree is correct, so the test above runs none of the
389417
// branches that report a wrong one. These do.
390418
const runsOn = 'runs-on=1/family=c8a+m8a/cpu=8'

0 commit comments

Comments
 (0)