Use configdiff in your GitHub Actions workflows to compare configuration files and detect changes in pull requests.
name: Config Diff
on: [pull_request]
jobs:
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for comparing branches
- name: Compare configs
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: config/production.yaml
new-file: config/staging.yaml| Input | Description | Required | Default |
|---|---|---|---|
old-file |
Path to old configuration file or directory | Yes | - |
new-file |
Path to new configuration file or directory | Yes | - |
format |
Input format (yaml, json, hcl, toml, auto) | No | auto |
output-format |
Output format (report, compact, json, patch, stat, side-by-side, git-diff) | No | report |
ignore-paths |
Comma-separated list of paths to ignore | No | '' |
array-keys |
Comma-separated list of array key specs | No | '' |
numeric-strings |
Coerce numeric strings to numbers | No | false |
bool-strings |
Coerce bool strings to booleans | No | false |
no-color |
Disable colored output | No | false |
exit-code |
Exit with code 1 if differences found | No | false |
recursive |
Recursively compare directories | No | false |
| Output | Description |
|---|---|
has-changes |
Whether any changes were detected (true/false) |
diff-output |
The diff output text |
name: PR Config Diff
on:
pull_request:
paths:
- 'config/**'
jobs:
config-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check config changes
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: config/production.yaml
new-file: config/staging.yaml
output-format: report- name: Verify configs match
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: expected.yaml
new-file: actual.yaml
exit-code: 'true' # Fail if differences found- name: Compare config directories
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: ./config-v1
new-file: ./config-v2
recursive: 'true'- name: Compare with ignored paths
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: old.yaml
new-file: new.yaml
ignore-paths: '/metadata/generation,/status/*'- name: Get diff statistics
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: old.yaml
new-file: new.yaml
output-format: statname: Compare Against Main
on:
pull_request:
branches: [main]
jobs:
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout base branch file
run: |
git show origin/main:config.yaml > /tmp/base-config.yaml
- name: Compare with PR changes
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: /tmp/base-config.yaml
new-file: config.yamlname: Config Diff Comment
on: [pull_request]
jobs:
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run configdiff
id: diff
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: config/base.yaml
new-file: config/updated.yaml
continue-on-error: true
- name: Comment PR
uses: actions/github-script@v7
if: steps.diff.outputs.has-changes == 'true'
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## Configuration Changes\n\n```\n${{ steps.diff.outputs.diff-output }}\n```'
})jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
format: [yaml, json, toml]
steps:
- uses: actions/checkout@v4
- name: Compare ${{ matrix.format }} configs
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: test/old.${{ matrix.format }}
new-file: test/new.${{ matrix.format }}name: Validate K8s Manifests
on:
pull_request:
paths:
- 'k8s/**'
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Compare deployment configs
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: k8s/production
new-file: k8s/staging
recursive: 'true'
ignore-paths: '/metadata/creationTimestamp,/metadata/generation,/status/*'
array-keys: '/spec/containers=name,/spec/volumes=name'name: Release
on:
push:
branches: [main]
jobs:
check-config:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get previous config
run: git show HEAD~1:config.yaml > /tmp/prev-config.yaml
- name: Check for breaking changes
id: diff
uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: /tmp/prev-config.yaml
new-file: config.yaml
output-format: json
- name: Determine version bump
run: |
# Parse JSON diff output to determine if breaking changes
# Set RELEASE_TYPE=major if breaking, minor if new features, patch otherwise
echo "RELEASE_TYPE=minor" >> $GITHUB_ENVuses: pfrederiksen/configdiff@v0.2.0uses: pfrederiksen/configdiff@mainuses: pfrederiksen/configdiff@abc123...Ensure you've checked out the repository first:
- uses: actions/checkout@v4
- uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: path/to/file
new-file: path/to/other/fileUse git show or checkout the other branch:
- run: |
git fetch origin
git show origin/main:config.yaml > /tmp/main-config.yaml
- uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: /tmp/main-config.yaml
new-file: config.yamlThe action uses the published Docker image. If you encounter permission issues, ensure the files are readable:
- run: chmod -R +r ./config
- uses: pfrederiksen/configdiff@v0.2.0
with:
old-file: ./config/old
new-file: ./config/new