Skip to content

0xdsqr/cdk-diff-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

AWS CDK Diff GitHub Action

typescript

continuous integration coverage lint code base codeql check dist/

Welcome to the AWS CDK Diff GitHub Action repository! This GitHub Action automates the process of reviewing infrastructure changes in AWS Cloud Development Kit (CDK) projects by using the cdk diff command. It aims to enhance pull request reviews by providing a clear and concise summary of proposed infrastructure changes.

Overview

This action runs cdk diff on AWS CDK projects for each pull request, processes the output for readability, and posts it as a comment on the pull request. This facilitates informed and efficient review processes by providing immediate insights into the impact of proposed changes on AWS infrastructure.

Most of the template for the action was taken from here and the general idea taken from here, credit to them.

Usage

Refer to the actions.ymlfor detailed configuration options.

Basic Configuration

- uses: 0xdsqr/cdk-diff-action@v0.1.0
  with:
    repo-token: ${{ secrets.GITHUB_TOKEN }}

Advanced Usage

# Example of referencing the output from the action
- name: Use My Action
  id: myaction
  uses: 0xdsqr/cdk-diff-action@v0.1.0
  with:
    repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Use Output
  run: echo "The output was ${{ steps.myaction.outputs.cdkOutPutPath }}"

Setup Dependencies

For version 1, ensure your CI is set up with AWS credentials and the AWS CDK before calling cdk-diff-action.

- uses: actions/checkout@v4

- uses: actions/setup-python@v4
  with:
    python-version: "3.9"

- uses: actions/setup-node@v4
  with:
    node-version: '20'

- run: npm ci

- run: |
    python -m pip install --upgrade pip
    npm install -g aws-cdk

- uses: aws-actions/configure-aws-credentials@master
  with:
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
    aws-region: "us-east-1"

- uses: 0xdsqr/cdk-diff-action@v0.1.0
  with:
    repo-token: ${{ secrets.GITHUB_TOKEN }}

Key Features

  • Automated Diff Summary: Runs cdk diff for pull requests and provides a readable summary.
  • Clean and Clear Output: Formats the cdk diff output in Markdown for better readability.
  • Enhanced Review Process: Posts the diff summary directly on pull requests for easy access.
  • Detection of Critical Changes: Highlights significant changes and potential risks.
  • Efficient Output Management: Ensures the comment size is within GitHub's constraints.

How It Works

The action comprises several key functions:

  1. Reading and Cleaning Output: Reads the cdk diff output file, cleans it of ANSI escape codes, and converts it into a Markdown-friendly format.
  2. Processing Differences: Identifies the number of stacks with differences and resources requiring replacement, providing a concise summary at the top of the comment.
  3. Commenting on Pull Requests: Utilizes the GitHub API to post the processed cdk diff output as a comment on the relevant pull request.

Example Diffs

See some example diff audits below.

Example Diff Simple

About

Action to update PR with CDK Diff

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •