Skip to content

feat(apiSmokeTest): legacy-api-key fallback for stacks past TempApiKey#55

Merged
chrisbc merged 3 commits into
mainfrom
fix/smoketest-legacy-api-key
Jun 10, 2026
Merged

feat(apiSmokeTest): legacy-api-key fallback for stacks past TempApiKey#55
chrisbc merged 3 commits into
mainfrom
fix/smoketest-legacy-api-key

Conversation

@chrisbc

@chrisbc chrisbc commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

Unblocks downstream deploys (nshm-toshi-api/deploy-test and any other repo that has migrated past the legacy apiGateway.apiKeys config in serverless).

Currently the action extracts the API key from deploy.out with:

const keyRegex = /(?<=TempApiKey.* )[^ ]*/
const key = keyMatch[0]   // ← TypeError when keyMatch is null

In stacks that have moved past apiGateway.apiKeys to a Lambda authorizer with x-api-key compatibility, deploy.out no longer contains a TempApiKey-… line. The regex misses, keyMatch is null, and the action fails with:

Could not find key
TypeError: Cannot read properties of null (reading '0')
Smoke test failed: Cannot read properties of null (reading '0')

Has been blocking appearing as deployment noise for nshm-toshi-api/deploy-test since 2026-05-11.

Changes

apiSmokeTest action

  • New input legacy-api-key (optional, defaults to ""). Used as the fallback x-api-key value when the TempApiKey regex misses.
  • Null-safety on keyMatch and urlMatch — don't index [0] when the regex didn't match. Failure now reports a clear message via core.setFailed instead of throwing.
  • Secret maskingcore.setSecret(key) regardless of source. The "Key: …" info line now prints "Key: ".
  • dist/index.js rebuilt via yarn build (rollup). The dist diff is large because the local rebuild picked up newer transitive deps; the meaningful src change is small and isolated to src/index.js.

deploy-to-aws-uv.yml

  • New optional secret smoketest-legacy-api-key. Passed through to the action's legacy-api-key input.

Backward compatibility

  • legacy-api-key defaults to "". Stacks still emitting TempApiKey-… in deploy output work unchanged — no caller change required.
  • No required-input changes anywhere.

Downstream

Companion PR in nshm-toshi-api will add secrets.smoketest-legacy-api-key to the local deploy workflow once this merges.

Test plan

  • yarn install + yarn build in apiSmokeTest/ — succeed
  • dist/index.js contains the new fallback logic (grep-verified)
  • Downstream caller PR exercises end-to-end

@chrisbc chrisbc requested review from chrisdicaprio and voj June 10, 2026 00:31
chrisbc added a commit that referenced this pull request Jun 10, 2026
The Setup Yarn2 step hard-coded `yarn set version berry` before
`yarn install --immutable`. This forces the latest 4.x release and
overrides whatever `packageManager` field the consumer has pinned.

When a consumer is on an older yarn (e.g. 4.14.x with yarn.lock
metadata `version: 9`) and `berry` resolves to 4.16.0 (which uses
metadata `version: 10`), `yarn install --immutable` then refuses to
write the metadata bump and the workflow fails:

    YN0028: │ -  version: 9
    YN0028: │ +  version: 10
    YN0028: │ The lockfile would have been modified by this install,
              which is explicitly forbidden.

Causes a self-failure too: the self-tests on this repo use the
`samplePythonProject*` fixtures which pin `yarn@4.14.1` with v9
lockfiles. The PR-test job for #55 was failing for exactly this
reason — has nothing to do with the smoketest changes in the
parent commits.

Fix: drop the `yarn set version berry` line. Corepack already
respects the `packageManager` field in package.json, so consumers
keep their pin. Consumers can use any yarn 4.x (or upgrade to
yarn 5 in future) without needing to wait for a workflow update.

Applies to both `deploy-to-aws-uv.yml` and `deploy-to-aws.yml`.
chrisbc added 3 commits June 10, 2026 14:37
Stacks that have migrated past `apiGateway.apiKeys` in their serverless
config to a Lambda authorizer (which accepts x-api-key via env var)
have no `TempApiKey-*` line in deploy.out. The action's key-extraction
regex misses, `keyMatch` is null, and the action crashes with:

  Could not find key
  TypeError: Cannot read properties of null (reading '0')

apiSmokeTest action
-------------------
- New optional input `legacy-api-key` — used as the x-api-key value
  when the TempApiKey regex misses in deploy.out.
- src/index.js: null-safety on keyMatch and urlMatch; falls back to
  legacy-api-key input when regex misses.
- core.setSecret(key) regardless of source so the value is masked in
  subsequent log output. "Key: …" info line now prints "Key: <masked>".
- dist/index.js + sourcemap rebuilt via yarn build (rollup).

deploy-to-aws-uv.yml
--------------------
- New optional secret `smoketest-legacy-api-key` — passed through to
  the action's `legacy-api-key` input. Callers that have moved past
  TempApiKey can pass their Lambda-authorizer x-api-key value.

Backward-compatible
-------------------
- legacy-api-key defaults to "". Stacks still emitting TempApiKey-* in
  deploy.out work unchanged.

Downstream
----------
- GNS-Science/nshm-toshi-api/deploy-aws-lambda.yaml will pass
  smoketest-legacy-api-key after this lands.
…ted secrets

After review feedback (would have required all callers to switch from
`secrets: inherit` to an explicit secret block — a big breaking change),
revise the design so that the shared workflow reads inherited secrets
directly. Caller workflows keep `secrets: inherit` and need no changes.

The smoketest step's `legacy-api-key` input now picks up the first
non-empty value from a fallback chain of standard GNS-Science API-key
secrets:

    LEGACY_API_KEY
    NZSHM22_TOSHI_API_KEY
    NZSHM22_KORORAA_API_KEY
    NZSHM22_NSHM_MODEL_API_KEY
    NZSHM22_SOLVIS_API_KEY
    NZSHM22_HAZARD_API_KEY

Each consumer's serverless.yml wires its own named secret into the
Lambda authorizer's LEGACY_API_KEY env var; the same value flows
through to the smoketest with no extra plumbing.

The `secrets:` block on the workflow_call is dropped — no new caller-
facing API surface.
The non-uv `deploy-to-aws.yml` had the same Smoke Test step shape as
`deploy-to-aws-uv.yml` but was missing the legacy-api-key fallback that
was added to the uv variant in the previous commit. Adding it here for
parity — consumers using the non-uv workflow with a stack that has
moved past `apiGateway.apiKeys` will otherwise hit the same "Could not
find key" failure.
@chrisbc chrisbc force-pushed the fix/smoketest-legacy-api-key branch from 64e7520 to d86788d Compare June 10, 2026 02:38
@chrisbc chrisbc merged commit 895d956 into main Jun 10, 2026
30 checks passed
@chrisbc chrisbc deleted the fix/smoketest-legacy-api-key branch June 10, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants