From 15786eefcc8f5441d767d923b108abe5f7dd8882 Mon Sep 17 00:00:00 2001 From: Kazuma Arimura Date: Wed, 15 Jan 2025 21:26:51 +0900 Subject: [PATCH] add support for `fail-on-invalid-resource` (#29) --- .github/workflows/self-test.yml | 25 +++++++++++++++++++++++++ README.md | 1 + action.yml | 13 ++++++++++++- sample/non-kubernetes-yaml/food.yaml | 2 ++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 sample/non-kubernetes-yaml/food.yaml diff --git a/.github/workflows/self-test.yml b/.github/workflows/self-test.yml index 77de9bc..644adf2 100644 --- a/.github/workflows/self-test.yml +++ b/.github/workflows/self-test.yml @@ -73,3 +73,28 @@ jobs: - name: Upload SARIF output file to GitHub uses: github/codeql-action/upload-sarif@v3 + + test-fail-on-invalid-resource: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Scan 1 - should succeed + uses: ./ + with: + directory: sample/non-kubernetes-yaml + config: sample/.kube-linter-config.yaml + + - name: Scan 2 - should fail + id: failing-scan + uses: ./ + with: + directory: sample/non-kubernetes-yaml + config: sample/.kube-linter-config.yaml + fail-on-invalid-resource: "true" + continue-on-error: true + + - name: Verify Scan 2 should have failed + shell: bash + run: | + echo "Verifying that kube-linter-action outcome (${{ steps.failing-scan.outcome }}) from Scan 2 is failure." + [[ "${{ steps.failing-scan.outcome }}" == "failure" ]] diff --git a/README.md b/README.md index 4222ebd..46455fa 100755 --- a/README.md +++ b/README.md @@ -35,3 +35,4 @@ The workflow will fail if kube-linter detects issues. You'll find issues in the | `format` | (optional) | Output format. Allowed values: `sarif`, `plain`, `json`. Default is `plain`. | | `output-file` | (optional) | Path to a file where kube-linter output will be stored. Default is `kube-linter.log`. File will be overwritten if it exists. | | `version` | (optional) | kube-linter release version to use, e.g. "0.2.4". The latest available version is used by default. | +| `fail-on-invalid-resource` | (optional) | Set `true` to error out when we have an invalid resource. | diff --git a/action.yml b/action.yml index d754df0..77fa3a1 100755 --- a/action.yml +++ b/action.yml @@ -22,6 +22,10 @@ inputs: description: 'Version of kube-linter to use. E.g. "0.2.4". Default: "latest"' required: false default: 'latest' + fail-on-invalid-resource: + description: 'Error out when we have an invalid resource. Default: false' + required: false + default: 'false' runs: using: "composite" steps: @@ -65,4 +69,11 @@ runs: else CONFIG="--config ${{ inputs.config }}" fi - ./kube-linter $CONFIG lint "${{ inputs.directory }}" --format "${{ inputs.format }}" | tee "${{ inputs.output-file }}" + + if [[ "${{ inputs.fail-on-invalid-resource }}" == "true" ]]; then + FLAG_ARGS="--fail-on-invalid-resource " + else + FLAG_ARGS="" + fi + + ./kube-linter $CONFIG lint "${{ inputs.directory }}" --format "${{ inputs.format }}" $FLAG_ARGS | tee "${{ inputs.output-file }}" diff --git a/sample/non-kubernetes-yaml/food.yaml b/sample/non-kubernetes-yaml/food.yaml new file mode 100755 index 0000000..be09380 --- /dev/null +++ b/sample/non-kubernetes-yaml/food.yaml @@ -0,0 +1,2 @@ +food: + - vegetables: tomatoes \ No newline at end of file