|
| 1 | +# GitHub Action `cdk-synth-and-diff` |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The `cdk-synth-and-diff` action synthesizes AWS CDK templates and performs a diff against the base branch of a pull request. |
| 8 | +This helps detect destructive or unexpected changes early. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +- node@>=24 for github action runner |
| 13 | +- `aws-cdk` must be installed |
| 14 | +- Install the `@shiftcode/iac-utilities` package (version >=1.0.0) in the root of your repository. This package provides |
| 15 | +the `stage-override-to-pr-base` and `aws-env-vars` commands used by the action. |
| 16 | + |
| 17 | +- The Action assumes that the repository is configured to use AWS CDK in the provided `iacDir`. Ensure that the specified |
| 18 | +directory contains a valid AWS CDK project. |
| 19 | + |
| 20 | +## Inputs |
| 21 | + |
| 22 | +| Name | Description | Required | Default Value | |
| 23 | +|--------------------------|-------------------------------------------------------------------------|----------|-----------------------------------| |
| 24 | +| `githubToken` | GitHub token to use for the action | Yes | | |
| 25 | +| `failOnDestructiveChanges` | Whether or not destructive changes should fail the job | No | `true` | |
| 26 | +| `allowedDestroyTypes` | Comma-delimited list of resource types that are allowed to be destroyed | No | `""` | |
| 27 | +| `iacDir` | The location of the IAC package | No | `packages/iac` | |
| 28 | +| `cdkOutFilename` | The name of the `cdk.out` file | No | `pr-base.cdk.out` | |
| 29 | +| `cloudFormationTemplate` | The CloudFormation template to use for the diff | No | `""` | |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +Below is an example of how to use the `cdk-synth-and-diff` action in a GitHub Actions workflow: |
| 34 | + |
| 35 | +```yaml |
| 36 | +name: Example Workflow |
| 37 | + |
| 38 | +on: |
| 39 | + pull_request: |
| 40 | + branches: |
| 41 | + - '**' |
| 42 | + |
| 43 | +jobs: |
| 44 | + synth-and-diff: |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - name: Checkout Repository |
| 48 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 49 | + |
| 50 | + - name: Install Dependencies |
| 51 | + run: npm ci |
| 52 | + |
| 53 | + - name: CDK synth and diff with PR base branch stage |
| 54 | + if: github.event_name == 'pull_request' |
| 55 | + uses: shiftcode/cdk-synth-and-diff-action@SHA # vX.Y.Z |
| 56 | + with: |
| 57 | + failOnDestructiveChanges: false |
| 58 | + allowedDestroyTypes: 'AWS::ECS::TaskDefinition' |
| 59 | + githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + cloudFormationTemplate: 'project-name-*' |
| 61 | +``` |
| 62 | +
|
| 63 | +## Key Features |
| 64 | +
|
| 65 | +1. **Stage Override**: The action uses the `stage-override-to-pr-base` command to ensure the synthesized templates are |
| 66 | +based on the pull request's base branch. |
| 67 | +2. **Destructive Change Detection**: The action can fail the job if destructive changes are detected, ensuring safe |
| 68 | +deployments. |
| 69 | +3. **Customizable Allowed Destroy Types**: Consumers can specify resource types that are allowed to be destroyed during |
| 70 | +the diff process. |
| 71 | + |
| 72 | +## Outputs |
| 73 | + |
| 74 | +The action does not produce any explicit outputs but provides diff results for the synthesized templates in form of |
| 75 | +a comment on the pull request. |
0 commit comments