forked from ab/homelab
Update .gitea/workflows/lint.yaml
This commit is contained in:
@ -13,36 +13,52 @@ jobs:
|
||||
- uses: bmuschko/setup-kubeconform@v1
|
||||
name: Setup Kubeconform
|
||||
|
||||
- name: Validate manifests
|
||||
id: validation
|
||||
- name: Kubeconform validation
|
||||
id: kubeconform
|
||||
run: |
|
||||
# Create a temporary file for storing validation output
|
||||
VALIDATION_OUTPUT=$(mktemp)
|
||||
|
||||
# Run kubeconform and capture output
|
||||
find . -name '*.yaml' \
|
||||
! -name '*values.yaml' \
|
||||
! -path './.gitea/*' -print0 \
|
||||
! -path './.gitea/*' \
|
||||
-print0 \
|
||||
| xargs -0 kubeconform \
|
||||
-summary \
|
||||
-verbose \
|
||||
-output json \
|
||||
-output pretty \
|
||||
-ignore-missing-schemas \
|
||||
-schema-location default \
|
||||
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' \
|
||||
-schema-location 'https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/kustomization.json' \
|
||||
> kubeconform_output.json
|
||||
-schema-location 'https://raw.githubusercontent.com/SchemaStore/schemastore/refs/heads/master/src/schemas/json/kustomization.json' > $VALIDATION_OUTPUT 2>&1 || true
|
||||
|
||||
invalid_count=$(jq '[.resources[] | select(.status=="invalid")] | length' kubeconform_output.json)
|
||||
# Display output in logs
|
||||
cat $VALIDATION_OUTPUT
|
||||
|
||||
if [[ "$invalid_count" -gt 0 ]]; then
|
||||
echo "❌ Found $invalid_count invalid manifests:"
|
||||
jq -r '.resources[] | select(.status=="invalid") | "- \(.filename): \(.msg)"' kubeconform_output.json \
|
||||
| tee invalid_files.txt
|
||||
echo "::error::Validation failed with $invalid_count errors."
|
||||
# Extract invalid files to a list
|
||||
if grep -q "invalid" $VALIDATION_OUTPUT; then
|
||||
grep -o "[^ ]*.yaml:.*invalid" $VALIDATION_OUTPUT | sort | uniq > invalid_files.txt
|
||||
echo "FAILED=true" >> $GITHUB_ENV
|
||||
echo "::error::Kubernetes manifest validation failed!"
|
||||
cat invalid_files.txt
|
||||
exit 1
|
||||
else
|
||||
echo "✅ All manifests are valid!"
|
||||
echo "All manifests are valid!"
|
||||
fi
|
||||
continue-on-error: true
|
||||
|
||||
- name: Send Telegram notification on failure
|
||||
if: failure()
|
||||
- name: Build notification message
|
||||
if: env.FAILED == 'true'
|
||||
run: |
|
||||
# Read invalid files and format them for the message
|
||||
INVALID_FILES=$(cat invalid_files.txt)
|
||||
echo "INVALID_FILES<<EOF" >> $GITHUB_ENV
|
||||
echo "$INVALID_FILES" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
|
||||
- name: Send Telegram message
|
||||
if: env.FAILED == 'true'
|
||||
uses: appleboy/telegram-action@master
|
||||
with:
|
||||
to: ${{ secrets.TELEGRAM_TO }}
|
||||
@ -51,7 +67,6 @@ jobs:
|
||||
message: |
|
||||
❌ <b>Kubernetes validation failed!</b>
|
||||
|
||||
📝 <b>Errors:</b>
|
||||
<pre>${{ join(files('invalid_files.txt'), '\n') }}</pre>
|
||||
|
||||
🔗 <a href="https://gt.hexor.cy/${{ github.repository }}/actions/runs/${{ github.run_number }}">Check details</a>
|
||||
Invalid files:
|
||||
${{ env.INVALID_FILES }}
|
||||
<a href="https://gt.hexor.cy/${{ github.repository }}/actions/runs/${{ github.run_number }}">🔗 Check details</a>
|
Reference in New Issue
Block a user