Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/self-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: 'self-test'
on:
pull_request:
push:
branches:
- main
- 'releases/*'
workflow_dispatch:

permissions:
contents: read

jobs:
changed:
name: Detects changes between charts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- uses: azure/setup-helm@v5

- name: Diff Helm Chart
uses: ./
id: diff
with:
currentChartPath: ./__tests__/fixtures/charts/current
targetChartPath: ./__tests__/fixtures/charts/target
valuesPath: __tests__/fixtures/values.yaml
currentValuesRepo: ${{ github.repository }}
currentValuesBranch: ${{ github.sha }}
targetValuesBranch: ${{ github.sha }}

- name: Assert outputs
env:
CHANGED: ${{ steps.diff.outputs.changed }}
DIFF: ${{ steps.diff.outputs.diff }}
TARGET_TEMPLATE: ${{ steps.diff.outputs.targetTemplate }}
run: |
set -euo pipefail
test "$CHANGED" = "true" || { echo "expected changed=true, got '$CHANGED'"; exit 1; }
grep -q '^+ replicas: "2"' <<< "$DIFF" || { echo "diff is missing the added line:"; echo "$DIFF"; exit 1; }
grep -q '^```diff' <<< "$DIFF" || { echo "diff is not formatted as markdown"; exit 1; }
grep -q 'replicas: "2"' <<< "$TARGET_TEMPLATE" || { echo "targetTemplate is missing the target render:"; echo "$TARGET_TEMPLATE"; exit 1; }

unchanged:
name: Detects identical charts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- uses: azure/setup-helm@v5

- name: Diff Helm Chart
uses: ./
id: diff
with:
currentChartPath: ./__tests__/fixtures/charts/current
targetChartPath: ./__tests__/fixtures/charts/current
valuesPath: __tests__/fixtures/values.yaml
currentValuesRepo: ${{ github.repository }}
currentValuesBranch: ${{ github.sha }}
targetValuesBranch: ${{ github.sha }}

- name: Assert outputs
env:
CHANGED: ${{ steps.diff.outputs.changed }}
DIFF: ${{ steps.diff.outputs.diff }}
run: |
set -euo pipefail
test "$CHANGED" = "false" || { echo "expected changed=false, got '$CHANGED'"; exit 1; }
test -z "$DIFF" || { echo "expected empty diff, got:"; echo "$DIFF"; exit 1; }
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Add the following step to your workflow:
currentValuesRepo: fivekoalas/diff-helm-chart
targetValuesRepo: fivekoalas/diff-helm-chart # optional, defaults to currentValuesRepo
currentValuesBranch: main # optional, defaults to develop
targetValuesBranch: main # optional, defaults to develop, overridden by targetBranchRegex on pull requests
token: ${{ secrets.GITHUB_TOKEN }} # required PAT for private repos, optional for public repos defaults to GITHUB_TOKEN
targetBranchRegex: 'release-.*' # optional, defaults to 'target: (.*)'
asMarkdown: true # optional, defaults to true
Expand Down
5 changes: 5 additions & 0 deletions __tests__/fixtures/charts/current/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: fixture
description: Chart used to self-test the action
type: application
version: 0.1.0
6 changes: 6 additions & 0 deletions __tests__/fixtures/charts/current/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-config
data:
greeting: {{ .Values.greeting | quote }}
5 changes: 5 additions & 0 deletions __tests__/fixtures/charts/target/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: fixture
description: Chart used to self-test the action
type: application
version: 0.1.0
7 changes: 7 additions & 0 deletions __tests__/fixtures/charts/target/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-config
data:
greeting: {{ .Values.greeting | quote }}
replicas: {{ .Values.replicas | quote }}
2 changes: 2 additions & 0 deletions __tests__/fixtures/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
greeting: hello
replicas: 2
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ inputs:
description: 'The branch containing the current values'
required: false
default: 'develop'
targetValuesBranch:
description: 'The branch containing the target values, used when the pull request body does not match targetBranchRegex'
required: false
default: 'develop'
token:
description: 'The Github token'
default: '${{ github.token }}'
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Input {
getInput('targetValuesRepo') || getInput('currentValuesRepo')
const [owner, repo] = ownerWithRepo.split('/')
const path = getInput('valuesPath')
let ref = 'develop'
let ref = getInput('targetValuesBranch') || 'develop'

if (context.eventName === 'pull_request') {
const regex = new RegExp(getInput('targetBranchRegex'))
Expand Down
Loading