Repository navigation
feat(github): add credential-isolated CDK preview workflow - #43
Conversation
Add a reusable workflow that assumes a read-only role through GitHub OIDC, fetches the deployed CloudFormation templates of named stacks, and uploads them as an artifact. It never checks out or runs anything from the caller, so callers can compare pull request synthesis against deployed state with cdk diff --template in a separate job that has no credentials. Inputs are validated before use and reach commands only through environment variables; actions are pinned to commit SHAs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…K preview Rename cdk-deployed-templates.yaml to cdk-preview.yaml and add the credential-free diff job: it checks out the pull request, synthesizes it, and runs cdk diff against each deployed template, reporting every stack in the job summary. Per-stack context values can be fixed or read from the deployed template (for example the currently deployed image tag), so callers need a single reusable-workflow reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e7ba9a7 to
d8a0aa3
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8a0aa3e0f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| done < <(jq -r '(.context // {}) | to_entries[] | [.key, .value] | @tsv' <<<"$entry") | ||
| while IFS=$'\t' read -r key regex; do | ||
| [[ -n "$key" ]] || continue | ||
| value=$(jq -r --arg re "$regex" '[.. | strings | capture($re)?.value] | first // empty' "$deployed") |
There was a problem hiding this comment.
Fix the invalid jq optional-capture expression
Whenever a stack supplies a nonempty contextFromDeployed object—including the documented README example—jq rejects capture($re)?.value with syntax error, unexpected FIELD. Because the step uses set -e, it aborts before running any CDK diff; the optional result must be parenthesized or piped to .value using valid jq syntax.
Useful? React with 👍 / 👎.
| continue 2 | ||
| fi | ||
| args+=(-c "$key=$value") | ||
| done < <(jq -r '(.contextFromDeployed // {}) | to_entries[] | [.key, .value] | @tsv' <<<"$entry") |
There was a problem hiding this comment.
Preserve regex escapes when reading deployed contexts
When a contextFromDeployed regex contains a backslash, as common patterns such as (?<value>\d+) do, @tsv escapes that backslash and read -r intentionally leaves the escape doubled. The altered regex is then passed to jq and fails to match the intended template string; use a transport that round-trips arbitrary JSON strings instead of TSV. The same serialization pattern on line 206 also alters direct context values containing backslashes or tabs.
Useful? React with 👍 / 👎.
| [[ "$name" =~ ^[A-Za-z][A-Za-z0-9-]{0,127}$ ]] || { echo "::error::Invalid CloudFormation stack name: $name"; exit 1; } | ||
| done < <(jq -r '.[].stack' <<<"$STACKS") | ||
| jq -r '.[].stack' <<<"$STACKS" > "$RUNNER_TEMP/stack-names.txt" | ||
| echo "artifactName=cdk-deployed-templates-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
Make artifact names unique per workflow invocation
When a caller invokes this reusable workflow more than once in a run—for example, once per role or region—every fetch job receives the same github.run_id and github.run_attempt, so they upload under the same name. upload-artifact@v7 requires artifact names to be unique within a workflow run and the later upload fails with a conflict (official action documentation); include a value unique to the individual reusable-workflow invocation.
Useful? React with 👍 / 👎.
| STACKS: ${{ inputs.stacks }} | ||
| run: | | ||
| set -euo pipefail | ||
| [[ "$ROLE_ARN" =~ ^arn:aws:iam::[0-9]{12}:role/[A-Za-z0-9+=,.@_/-]{1,64}$ ]] || { echo "::error::roleArn is not an IAM role ARN."; exit 1; } |
There was a problem hiding this comment.
Accept valid IAM role partitions and paths
For callers using China/GovCloud partitions or a role path whose combined path and name exceeds 64 characters, this validation rejects an otherwise valid role ARN before credential setup. IAM ARNs can use partitions such as aws-cn, and AWS permits a role path of up to 512 characters in addition to the 64-character role name (IAM identifier documentation, role limits); validate the partition, path, and role name separately rather than limiting the entire resource suffix.
Useful? React with 👍 / 👎.
Summary
Adds
cdk-preview.yaml, a credential-isolated CDK preview for pull requests (sharedale/sharedale#69). Pairs with #42 for the v11.0.0 release.deployed templatesGetTemplate --template-stage Originalfor each stack; uploads<stack>.json(1-day retention). Never checks out, downloads, or caches anything from the caller; only the runner's AWS CLI/jq and two commit-pinned actions run (configure-aws-credentialsv6.3.0,upload-artifactv7.0.2).diffcontents: readonly)cdk diff <stack> --template <deployed>.jsonwith per-stackcontext, and writes every stack's result to the job summary; fails if any diff failsstacksinput describes each stack:stack, optionalcontext(cdk -cvalues), and optionalcontextFromDeployed(a regex with a(?<value>...)group read from the deployed template, e.g. the currently deployed image tag so only infrastructure changes show).cdkVersion, 1–20 distinct well-formed stack names, single-line context values, capture-group regexes) and reach commands through environment variables or argument arrays.job_workflow_refpinned to a commit SHA and allow onlycloudformation:GetTemplateon the listed stacks.Validation
Could not read the deployed template of <stack>.diffjob, run locally from this workflow's own script against Sharedale with no AWS credentials and the deployed Nonproduction templates: inputs accepted; a regex without a capture group rejected.sharedale-developmentandsharedale-staging-dnsdiffed;contextFromDeployedextracted the deployed image tag (cd094e6a04b9).sharedale-stagingfails until Sharedale consumes feat(cognito): accept an explicit hosted zone for custom domains cdk-constructs#99 (synth-time hosted-zone lookup), and the job reports it.🤖 Generated with Claude Code