Skip to content

fix(ci): Add kubeconform testing #7

fix(ci): Add kubeconform testing

fix(ci): Add kubeconform testing #7

Workflow file for this run

name: Flux Helm Diff
on:
pull_request:
jobs:
flux-diff:
runs-on: ubuntu-latest
permissions:
contents: read
concurrency:
group: flux-diff-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set changed helm releases
id: changed
run: |
# Get all helm-release.yaml files changed in this PR
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep 'helm-release.yaml' || true)
echo "changed_files=$files" >> $GITHUB_OUTPUT
- name: Check if there are helm-release.yaml changes
if: ${{ steps.changed.outputs.changed_files == '' }}
run: echo "No helm-release.yaml changes detected. Skipping flux-local diff."
- name: Run Flux Local Diff
if: ${{ steps.changed.outputs.changed_files != '' }}
id: flux
uses: docker://ghcr.io/allenporter/flux-local:v8.1.0@sha256:37c3c4309a351830b04f93c323adfcb0e28c368001818cd819cbce3e08828261
with:
entrypoint: /bin/sh
args: >-
-c ": > diff.patch;
for file in ${{ steps.changed.outputs.changed_files }}; do
name=$(awk '/^metadata:/ {inmeta=1; next} inmeta && /^[^ ]/ {exit} inmeta && $1==\"name:\" {print $2; exit}' \"$file\");
namespace=$(awk '/^metadata:/ {inmeta=1; next} inmeta && /^[^ ]/ {exit} inmeta && $1==\"namespace:\" {print $2; exit}' \"$file\");
if [ -z \"$name\" ]; then
echo \"⚠️ Could not detect name in $file\";
continue;
fi;
if [ -z \"$namespace\" ]; then
namespace=default;
fi;
echo \"Diffing $namespace/$name from $file\";
flux-local diff helmrelease \"$name\" -n \"$namespace\" --path embed/generic/kubernetes >> diff.patch || true;
done;
cat diff.patch"
env:
GITHUB_SHA: ${{ github.sha }}
- name: Generate Diff Output
if: ${{ steps.changed.outputs.changed_files != '' }}
id: diff
run: |
if [ -f diff.patch ] && [ -s diff.patch ]; then
echo "diff<<EOF" >> $GITHUB_OUTPUT
cat diff.patch >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "## Flux diff" >> $GITHUB_STEP_SUMMARY
echo '```diff' >> $GITHUB_STEP_SUMMARY
cat diff.patch >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
fi
- if: ${{ steps.diff.outputs.diff != '' }}
name: Generate Token
uses: actions/create-github-app-token@v2.2.1
id: app-token
with:
app-id: ${{ secrets.BOT_APP_ID }}
private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
- if: ${{ steps.diff.outputs.diff != '' }}
name: Add PR Comment
continue-on-error: true
uses: mshick/add-pr-comment@v2
with:
repo-token: "${{ steps.app-token.outputs.token }}"
message-id: "${{ github.event.pull_request.number }}/kubernetes/flux-diff"
header: "${{ github.event.pull_request.number }}/kubernetes/flux-diff"
message-failure: Diff was not successful
message: |
```diff
${{ steps.diff.outputs.diff }}
```