File tree Expand file tree Collapse file tree 11 files changed +117
-11
lines changed Expand file tree Collapse file tree 11 files changed +117
-11
lines changed Original file line number Diff line number Diff line change 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 }}
Original file line number Diff line number Diff line change 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 .
58ENTRYPOINT [ "./entrypoint.sh" ]
Original file line number Diff line number Diff line change 1- # GitHub Action for Kustomize Build+Diff
1+ # GitHub Action for Kustomize Build+Diff
Original file line number Diff line number Diff line change @@ -2,16 +2,28 @@ name: "kustomize-diff"
22description : " Kustomize build and diff action"
33inputs :
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 : " "
1224outputs :
1325 diff :
14- description : " Git diff"
26+ description : " Kustomize diff in markdown "
1527runs :
1628 using : " docker"
1729 image : " Dockerfile"
Original file line number Diff line number Diff line change 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
1044exit 0
Original file line number Diff line number Diff line change 1+ apiVersion : kustomize.config.k8s.io/v1beta1
2+ kind : Kustomization
3+ resources :
4+ - release.yml
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ apiVersion : kustomize.config.k8s.io/v1beta1
2+ kind : Kustomization
3+ resources :
4+ - ../base
5+ patches :
6+ - path : patch.yml
Original file line number Diff line number Diff line change 1+ apiVersion : helm.toolkit.fluxcd.io/v2
2+ kind : HelmRelease
3+ metadata :
4+ name : testapp
5+ spec :
6+ values :
7+ deployment :
8+ useServiceAccount : false
Original file line number Diff line number Diff line change 1+ apiVersion : kustomize.config.k8s.io/v1beta1
2+ kind : Kustomization
3+ resources :
4+ - ../base
5+ patches :
6+ - path : patch.yml
You can’t perform that action at this time.
0 commit comments