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