Skip to content

This action automatically generates and posts diffs of your Kustomize changes directly in your PR comments.

License

Notifications You must be signed in to change notification settings

swade1987/github-action-kustomize-diff

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

Kustomize Diff GitHub Action

This GitHub Action builds and compares Kustomize configurations between the base and head of a Pull Request, posting the differences as a PR comment. This helps reviewers easily identify configuration changes in Kubernetes manifests.

Why Use This Action?

Managing Kubernetes configurations across multiple environments and PRs can be challenging. This action automatically generates and posts clear diffs of your Kustomize changes directly in your PR comments. This helps:

  • 🔍 Catch Configuration Mistakes - Easily spot unintended changes before they hit production
  • ⏱️ Speed Up Reviews - Reviewers can instantly see what's changing without checking out the code
  • 🔄 Validate Changes - Confirm your Kustomize overlays are working as expected
  • 📝 Document Changes - Automatically track and document configuration changes in PR history

Features

Inputs

Name Description Required Default
base_ref Reference (branch/SHA) for PR base Yes ${{ github.base_ref }}
head_ref Reference (branch/SHA) for PR head Yes ${{ github.head_ref }}
pr_num Pull Request number/ID Yes ${{ github.event.number }}
token GitHub token for authentication Yes ${{ github.token }}
root_dir Root directory containing kustomize files No ./kustomize
max_depth Maximum depth to search for kustomization files No 2

Outputs

Name Description
diff Generated diff between kustomize built head and base

Usage

The below example will run kustomize-diff against your branch and commit the changes due to be applied back to your Pull Request.

name: kustomize-diff
on:
  pull_request:
    paths:
      - 'kustomize/**'

jobs:
  kustomize-diff:
    permissions:
      pull-requests: write
      contents: write
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        with:
          fetch-depth: 0
      - id: kustomize-diff
        uses: swade1987/[email protected]
        with:
          root_dir: "./kustomize"
          max_depth: "2"
      - id: comment
        uses: actions/[email protected]
        env:
          OUTPUT: ${{ steps.kustomize-diff.outputs.diff }}
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const rawOutput = process.env.OUTPUT;
            const noDiffMessage = "No differences found between";

            const formattedOutput = rawOutput.includes(noDiffMessage)
              ? `### ${rawOutput}`
              : `### Kustomize Changes\n<details><summary>Show Diff</summary>\n\n\`\`\`diff\n${rawOutput}\n\`\`\`\n</details>`;

            await github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: formattedOutput
            })

An example of the commented output can be found here.

Contributing to the repository

To contribute, please read the contribution guidelines. You may also report an issue.

About

This action automatically generates and posts diffs of your Kustomize changes directly in your PR comments.

Resources

License

Stars

Watchers

Forks