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
22 changes: 15 additions & 7 deletions .github/workflows/svcaplbot-run-dyff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ permissions:
jobs:
check-commit:
runs-on: ubuntu-latest
# Skip this pre-check check when triggered manually
if: github.event_name != 'workflow_dispatch'
outputs:
skip: ${{ steps.check.outputs.skip }}
steps:
Expand All @@ -40,7 +42,7 @@ jobs:
run-compare:
runs-on: ubuntu-latest
needs: check-commit
if: ${{ needs.check-commit.outputs.skip != 'true' }}
if: ${{ github.event_name == 'workflow_dispatch' || (success() && needs.check-commit.outputs.skip != 'true') }}
steps:
- name: Debug
run: |
Expand All @@ -49,17 +51,22 @@ jobs:
run: |
sudo apt update
sudo apt install gh -y
- name: Checkout repository
- name: Checkout PR branch
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
path: pr
- name: Checkout base branch
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.ref || 'main' }}
path: base
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
node-version-file: 'pr/.nvmrc'
- name: Install npm dependencies
run: npm install --no-save
run: cd "$GITHUB_WORKSPACE/pr" && npm install --no-save && cd "$GITHUB_WORKSPACE/base" && npm install --no-save
- name: Install Helm and Helmfile
uses: helmfile/helmfile-action@v2.1.1
with:
Expand All @@ -79,12 +86,13 @@ jobs:
env:
GH_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
bin/compare.sh --diff-output tmp/diff-output.txt
mkdir -p tmp
"$GITHUB_WORKSPACE/pr/bin/compare.sh" "$GITHUB_WORKSPACE/base" "$GITHUB_WORKSPACE/pr" --diff-output tmp/diff-output.txt
diff_text=$(cat tmp/diff-output.txt)
format_code_start='```diff'
format_code_end='```'
comment_text="Comparison of Helm chart templating output:
$format_code_start
$diff_text
$format_code_end"
gh pr comment ${{ github.event.pull_request.number }} --body "$comment_text"
cd "$GITHUB_WORKSPACE/pr" && gh pr comment ${{ github.event.pull_request.number }} --body "$comment_text"
75 changes: 56 additions & 19 deletions bin/compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,86 @@
set -ue

# Usage: bin/compare.sh -l name=loki
# Alternative: bin/compare.sh base-branch-copy feat-branch-copy -l name=loki
# Optional: --diff-output <filename> writes the final diff to a file and skips common chart version information
# Deps: dyff, helmfile
# brew install homeport/tap/dyff
# brew install helmfile

export ENV_DIR=$PWD/tests/fixtures

diffOutput=
templateArgs=
srcDirA=
srcDirB=
targetDirA=
targetDirB=
# Process arguments
while [ $# -ne 0 ]; do
case "$1" in
--diff-output)
diffOutput="$2"
shift
;;
*)
# Forward everything else to the template command
-*)
# Forward other options to the template command
templateArgs=("${templateArgs[@]}" "$1")
;;
*)
# Process first two positional arguments as potential working directories
if [ -z "$srcDirA" ]; then
srcDirA=$(realpath "$1")
elif [ -z "$srcDirB" ]; then
srcDirB=$(realpath "$1")
else
# Forward everything else to the template command
templateArgs=("${templateArgs[@]}" "$1")
fi
;;
esac
shift
done

readonly script_dir=$(dirname "$0")
readonly branchA='main'
# branchB current branch
readonly branchB=$(git rev-parse --abbrev-ref HEAD)

targetDirA="tmp/${branchA}"
targetDirB="tmp/${branchB}"
generate_helm_templates() {
local target_dir="$1"
rm -rf "$target_dir"
node --no-warnings --import tsx src/otomi.ts -- values
helmfile template "${templateArgs[@]}" --output-dir-template="$target_dir/{{.Release.Namespace}}-{{.Release.Name}}"
mv tests/fixtures/values-repo.yaml "$target_dir/values-repo.yaml"
}

export NODE_ENV=test
node --no-warnings --import tsx src/otomi.ts -- values
helmfile template "${templateArgs[@]}" --output-dir-template="$targetDirB/{{.Release.Namespace}}-{{.Release.Name }}"
mv tests/fixtures/values-repo.yaml "$targetDirB/values-repo.yaml"
git -c core.hooksPath=/dev/null checkout -f $branchA
# we remove previously rendered manifests so they are not mixed up with newly rendered
rm -rf $targetDirA
node --no-warnings --import tsx src/otomi.ts -- values
helmfile template "${templateArgs[@]}" --output-dir-template="$targetDirA/{{.Release.Namespace}}-{{.Release.Name}}"
mv tests/fixtures/values-repo.yaml "$targetDirA/values-repo.yaml"
git -c core.hooksPath=/dev/null checkout -f $branchB
if [ -z "$srcDirA" ]; then
branchA='main'
# branchB current branch
branchB=$(git rev-parse --abbrev-ref HEAD)

targetDirA="$PWD/tmp/${branchA}"
targetDirB="$PWD/tmp/${branchB}"
export ENV_DIR="$PWD/tests/fixtures"
generate_helm_templates "$targetDirB"
git -c core.hooksPath=/dev/null checkout -f $branchA
generate_helm_templates "$targetDirA"
git -c core.hooksPath=/dev/null checkout -f $branchB
else
if [ -z "$srcDirB" ]; then
echo "Only one directory passed for comparison"
exit 1
fi
startDir=$PWD
pushd "$srcDirB"
export ENV_DIR="$srcDirB/tests/fixtures"
branchB=$(git rev-parse --abbrev-ref HEAD)
targetDirB="$startDir/tmp/${branchB}"
generate_helm_templates "$targetDirB"
popd
pushd "$srcDirA"
export ENV_DIR="$srcDirA/tests/fixtures"
branchA=$(git rev-parse --abbrev-ref HEAD)
targetDirA="$startDir/tmp/${branchA}"
generate_helm_templates "$targetDirA"
popd
fi

# order of arguments matters so new changes are green color
echo "Comparing $targetDirB with $targetDirA"
Expand Down
8 changes: 4 additions & 4 deletions bin/dyff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ while [ $# -ne 0 ]
do
case "$1" in
--exclude-chart-versions)
miscArgs=( "${miscArgs[@]}" --exclude-regexp '.*metadata.labels.helm.sh/chart' --exclude-regexp '.*metadata.labels.app.kubernetes.io/version' )
miscArgs=( "${miscArgs[@]}" --exclude-regexp '.*metadata.labels.helm.sh/chart' --exclude-regexp '.*metadata.labels.chart' --exclude-regexp '.*metadata.labels.app.kubernetes.io/version' )
;;
*)
if [ -z "$targetDirA" ]; then
Expand All @@ -18,18 +18,18 @@ do
targetDirB=$1
else
echo "Extra argument $1"
return 1
exit 1
fi
;;
esac
shift
done
if [ -z "$targetDirA" ]; then
echo "Missing first argument"
return 1
exit 1
elif [ -z "$targetDirB" ]; then
echo "Missing second argument"
return 1
exit 1
fi

set +e
Expand Down