diff --git a/.gitea/workflows/lint.yaml b/.gitea/workflows/lint.yaml index c222bcc..0945c20 100644 --- a/.gitea/workflows/lint.yaml +++ b/.gitea/workflows/lint.yaml @@ -2,62 +2,47 @@ name: Check with kubeconform on: push: - branches: [ main ] + branches: [main] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - + - uses: bmuschko/setup-kubeconform@v1 name: Setup Kubeconform - - - name: Kubeconform validation + + - name: Validate manifests 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 \ - | xargs -0 kubeconform \ - -summary \ - -verbose \ - -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/refs/heads/master/src/schemas/json/kustomization.json' > $VALIDATION_OUTPUT 2>&1 || true - - # Display output in logs - cat $VALIDATION_OUTPUT - - # 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 + invalid_files=$( + find . -name '*.yaml' ! -name '*values.yaml' ! -path './.gitea/*' -print0 | + xargs -0 kubeconform \ + -summary \ + -output json \ + -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' | + jq -r '.resources[] | select(.status == "invalid") | "- \(.filename): \(.msg)"' + ) + + if [[ -n "$invalid_files" ]]; then + { + echo 'FAILED=true' + echo "INVALID_FILES<> "$GITHUB_ENV" + echo "::error::Validation failed!" exit 1 else - echo "All manifests are valid!" + echo "✅ All manifests are valid!" fi continue-on-error: true - - - 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<> $GITHUB_ENV - echo "$INVALID_FILES" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - - name: Send Telegram message + + - name: Notify Telegram on failure if: env.FAILED == 'true' uses: appleboy/telegram-action@master with: @@ -66,7 +51,8 @@ jobs: format: html message: | ❌ Kubernetes validation failed! - - Invalid files: - ${{ env.INVALID_FILES }} - Check details \ No newline at end of file + + Invalid files: +
${{ env.INVALID_FILES }}
+ + 🔗 Details