diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 623653b..1e1c554 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -111,3 +111,65 @@ jobs: - name: Run chart-testing (install) if: steps.list-changed.outputs.changed == 'true' run: ct install --chart-dirs=testdata --target-branch ${{ github.event.repository.default_branch }} + + test_ct_action_with_lint_config: + runs-on: ubuntu-latest + + name: run action with a custom yamllint config + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Set up Helm + uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + with: + version: v3.17.0 + + - name: Install chart-testing + uses: ./ + + - name: Run chart-testing (lint) with the default config + run: ct lint --charts testdata/simple-deployment --check-version-increment=false --validate-maintainers=false + + - name: Install chart-testing with lint_config + uses: ./ + with: + lint_config: testdata/custom-lintconf.yaml + + - name: Check CT_LINT_CONF + run: | + if [[ "${CT_LINT_CONF}" != "$(realpath testdata/custom-lintconf.yaml)" ]]; then + echo "CT_LINT_CONF should point to testdata/custom-lintconf.yaml, got '${CT_LINT_CONF}'" + exit 1 + fi + shell: bash + + - name: Run chart-testing (lint) with the custom config + run: | + log="${RUNNER_TEMP}/ct-lint.log" + if ct lint --charts testdata/simple-deployment --check-version-increment=false --validate-maintainers=false > "${log}" 2>&1; then + cat "${log}" + echo 'ct lint should fail on the document-start rule from lint_config' + exit 1 + fi + if ! grep -q 'missing document start' "${log}"; then + cat "${log}" + echo 'ct lint failed, but not because of lint_config' + exit 1 + fi + echo 'ct lint failed on the document-start rule from lint_config, as expected' + shell: bash + + - name: Install chart-testing with a missing lint_config + id: missing_lint_config + continue-on-error: true + uses: ./ + with: + lint_config: testdata/does-not-exist.yaml + + - name: Check the missing lint_config failed + run: | + if [[ '${{ steps.missing_lint_config.outcome }}' != 'failure' ]]; then + echo 'a missing lint_config should fail the action' + exit 1 + fi + shell: bash diff --git a/README.md b/README.md index adf1de2..ec0156f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ For more information on inputs, see the [API Documentation](https://developer.gi - `version`: The chart-testing version to install (default: `3.14.0`) - `yamllint_version`: The `yamllint` version to install (default: `1.33.0`) - `yamale_version`: The `yamale` version to install (default: `6.0.0`) +- `lint_config`: Path to a custom yamllint config file. If set, `ct lint` uses it instead of the default `lintconf.yaml` (default: none) ### Example Workflow diff --git a/action.yml b/action.yml index 9c003d2..e0ae5d6 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,10 @@ inputs: description: "GitHub token for authenticating with the GitHub API (default: github.token)" required: false default: ${{ github.token }} + lint_config: + description: "Path to a custom yamllint config file. If set, ct lint uses it instead of the default lintconf.yaml." + required: false + default: '' runs: using: composite steps: @@ -40,3 +44,14 @@ runs: --yamllint-version ${{ inputs.yamllint_version }} \ --yamale-version ${{ inputs.yamale_version }} shell: bash + - if: inputs.lint_config != '' + env: + LINT_CONFIG: ${{ inputs.lint_config }} + run: | + if [[ ! -f "${LINT_CONFIG}" ]]; then + echo "::error::lint_config file not found: ${LINT_CONFIG}" + exit 1 + fi + echo "CT_LINT_CONF=$(realpath "${LINT_CONFIG}")" >> "${GITHUB_ENV}" + echo "Using custom yamllint config: ${LINT_CONFIG}" + shell: bash diff --git a/testdata/custom-lintconf.yaml b/testdata/custom-lintconf.yaml new file mode 100644 index 0000000..d91e227 --- /dev/null +++ b/testdata/custom-lintconf.yaml @@ -0,0 +1,8 @@ +--- +# Used by the lint_config test in .github/workflows/test-action.yml. +# The default ct config disables document-start, and +# simple-deployment/Chart.yaml has no "---", so ct lint only fails +# when this file is the one in use. +rules: + document-start: + present: true