Skip to content

Commit c24d6cf

Browse files
authored
Merge pull request #1 from supplypike/test
implement diff with diffoscope
2 parents da6965e + 00ed15d commit c24d6cf

File tree

11 files changed

+117
-11
lines changed

11 files changed

+117
-11
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
1214
- id: test-action
1315
uses: ./
14-
- run: echo "${{ steps.test-action.outputs.diff }}"
16+
with:
17+
base_ref: 027b33661ae3211230e8cd03d19df49ba620b379
18+
head_ref: 182a672418c5bae4d6b7ca1244da5f28bf5ff6f0
19+
kustomizations: |-
20+
testdata/prod
21+
testdata/stage
22+
- uses: mshick/add-pr-comment@v2
23+
with:
24+
message: ${{ steps.test-action.outputs.diff }}

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
FROM debian:bookworm-slim
1+
FROM registry.k8s.io/kustomize/kustomize:v5.0.0
22

3-
COPY entrypoint.sh .
3+
RUN apk add --no-cache \
4+
sed \
5+
diffoscope
46

7+
COPY entrypoint.sh .
58
ENTRYPOINT [ "./entrypoint.sh" ]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# GitHub Action for Kustomize Build+Diff
1+
# GitHub Action for Kustomize Build+Diff

action.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@ name: "kustomize-diff"
22
description: "Kustomize build and diff action"
33
inputs:
44
base_ref:
5-
description: "Ref for PR base"
5+
description: "Git ref for PR base"
66
required: true
77
default: ${{ github.base_ref }}
88
head_ref:
9-
description: "Ref for PR head"
9+
description: "Git ref for PR head"
1010
required: true
1111
default: ${{ github.head_ref }}
12+
kustomizations:
13+
description: |-
14+
Kustomization directories
15+
16+
You can specify multiple directories by separating them with a newline:
17+
```yaml
18+
kustomizations: |-
19+
testdata/prod
20+
testdata/stage
21+
```
22+
required: true
23+
default: ""
1224
outputs:
1325
diff:
14-
description: "Git diff"
26+
description: "Kustomize diff in markdown"
1527
runs:
1628
using: "docker"
1729
image: "Dockerfile"

entrypoint.sh

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,44 @@
11
#!/bin/sh
22

3-
set -x
3+
set -eux
44

5-
echo "Hello World"
6-
echo "head $INPUT_HEAD_REF base $INPUT_BASE_REF"
5+
build_dir=$(mktemp -d)
76

8-
echo "diff=foo" >>"$GITHUB_OUTPUT"
7+
build() {
8+
ref="$1"
9+
git checkout "$1" --quiet
10+
11+
for target in $INPUT_KUSTOMIZATIONS; do
12+
echo "Building $target" to "$build_dir/$ref/$target"
13+
mkdir -p "$build_dir/$ref/$target"
14+
kustomize build "$target" -o "$build_dir/$ref/$target/"
15+
done
16+
}
17+
18+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
19+
20+
build "$INPUT_BASE_REF"
21+
build "$INPUT_HEAD_REF"
22+
23+
base_ref_build_dir="$build_dir/$INPUT_BASE_REF"
24+
head_ref_build_dir="$build_dir/$INPUT_HEAD_REF"
25+
26+
set +e
27+
for target in $INPUT_KUSTOMIZATIONS; do
28+
diffoscope "$base_ref_build_dir/$target" "$head_ref_build_dir/$target" \
29+
--markdown - \
30+
--exclude-directory-metadata=yes | tee -a diff.md
31+
done
32+
33+
set -e
34+
35+
# Formatting hacks
36+
output=$(cat diff.md | sed "s|$base_ref_build_dir/||" | sed '/Comparing/ s/&.*$//' | sed "s|^#\{2,\} Comparing| Comparing|" | sed "s|^# Comparing|## Comparing|")
37+
38+
{
39+
echo 'diff<<EOF'
40+
echo "$output"
41+
echo 'EOF'
42+
} >>"$GITHUB_OUTPUT"
943

1044
exit 0

testdata/base/kustomization.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- release.yml

testdata/base/release.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: helm.toolkit.fluxcd.io/v2
2+
kind: HelmRelease
3+
metadata:
4+
name: testapp
5+
spec:
6+
releaseName: testapp
7+
chart:
8+
spec:
9+
chart: charts/internal-service
10+
sourceRef:
11+
kind: GitRepository
12+
name: gitops
13+
interval: 1h
14+
values:
15+
foo: true

testdata/prod/kustomization.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- ../base
5+
patches:
6+
- path: patch.yml

testdata/prod/patch.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: helm.toolkit.fluxcd.io/v2
2+
kind: HelmRelease
3+
metadata:
4+
name: testapp
5+
spec:
6+
values:
7+
deployment:
8+
useServiceAccount: false

testdata/stage/kustomization.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- ../base
5+
patches:
6+
- path: patch.yml

testdata/stage/patch.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: helm.toolkit.fluxcd.io/v2
2+
kind: HelmRelease
3+
metadata:
4+
name: testapp
5+
spec:
6+
values:
7+
deployment:
8+
useServiceAccount: true

0 commit comments

Comments
 (0)