diff --git a/.gitea/workflows/lint.yaml b/.gitea/workflows/lint.yaml index d0ed566..0015878 100644 --- a/.gitea/workflows/lint.yaml +++ b/.gitea/workflows/lint.yaml @@ -13,64 +13,49 @@ jobs: - uses: bmuschko/setup-kubeconform@v1 name: Setup Kubeconform - # This is the step that was missing in your workflow execution - name: Kubeconform validation id: kubeconform run: | - # Create a temporary file to store validation output - VALIDATION_OUTPUT_FILE=$(mktemp) + # Create a temporary file for storing validation output + VALIDATION_OUTPUT=$(mktemp) - # Run kubeconform and capture output and exit code + # 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_FILE 2>&1 || true + -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 - # Save the validation output to a step output - VALIDATION_OUTPUT=$(cat $VALIDATION_OUTPUT_FILE) - echo "VALIDATION_OUTPUT<> $GITHUB_ENV - echo "$VALIDATION_OUTPUT" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV + # Display output in logs + cat $VALIDATION_OUTPUT - # Display the output in the logs - cat $VALIDATION_OUTPUT_FILE - - # Check if there were validation errors - if grep -q "Error" $VALIDATION_OUTPUT_FILE; then - echo "VALIDATION_FAILED=true" >> $GITHUB_ENV + # 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!" fi continue-on-error: true - - name: Extract invalid files - if: env.VALIDATION_FAILED == 'true' - id: extract_errors - run: | - echo "INVALID_FILES<> $GITHUB_ENV - grep -o "[^ ]*.yaml:.*Error:" <<< "${{ env.VALIDATION_OUTPUT }}" | sort | uniq >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - - name: Telegram notify on validation failure - if: env.VALIDATION_FAILED == 'true' + - name: Telegram notify on failure + if: env.FAILED == 'true' uses: appleboy/telegram-action@master with: to: ${{ secrets.TELEGRAM_TO }} token: ${{ secrets.TELEGRAM_TOKEN }} message: | - 🚨 Kubernetes manifest validation failed! + ❌ Kubernetes validation failed! - Repository: ${{ github.repository }} - Files with errors: - ${{ env.INVALID_FILES }} - - Check action: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \ No newline at end of file + Invalid files: + $(cat invalid_files.txt) \ No newline at end of file