diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 59f10d3810..15ae9080b6 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -47,11 +47,24 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Self test for ansible-lint@${{ github.action_ref || 'main' }} + - name: Self test 1 uses: ./ with: # basically we only lint linter own configuration, which should be passing. args: .ansible-lint + - name: Self test 2 + uses: ./ + with: + # basically we only lint linter own configuration, which should be passing. + args: .ansible-lint + working_directory: . + - name: Self test 3 + uses: ./ + with: + # basically we only lint linter own configuration, which should be passing. + args: .ansible-lint + working_directory: docs + expected_return_code: "2" # expected to fail because the given argument does not exist in this folder build: name: ${{ matrix.name }} runs-on: ${{ matrix.os || 'ubuntu-22.04' }} diff --git a/README.md b/README.md index 653534038d..892d1a020f 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,25 @@ jobs: steps: - uses: actions/checkout@v4 - name: Run ansible-lint - uses: ansible/ansible-lint@main # or version tag instead of 'main' + uses: ansible/ansible-lint@main + # optional (see below): + with: + args: "" + setup_python: "true" + working_directory: "" + requirements_file: "" ``` +All the arguments are optional and most users should not need them: + +- `args`: Arguments to be passed to ansible-lint command. +- `setup_python`: If python should be installed. Default is `true`. +- `working_directory`: The directory where to run ansible-lint from. Default is + `github.workspace`. That might be needed if you want to lint only a subset of + your repository. +- `requirements_file`: Path to the requirements.yml file to install role and + collection dependencies. + For more details, see [ansible-lint-action]. # Communication @@ -63,8 +79,8 @@ original [MIT] license. # Authors -ansible-lint was created by [Will Thames] and is now maintained as part of the -[Ansible] by [Red Hat] project. +ansible-lint was created by [Will Thames] and is now maintained as part of the [Ansible] +by [Red Hat] project. [ansible]: https://ansible.com [contribution guidelines]: diff --git a/action.yml b/action.yml index 34e7279abc..63bcf79dee 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,10 @@ inputs: description: Path to the requirements YAML file to install role and collection dependencies. required: false default: "" + expected_return_code: + description: Expected return code from ansible-lint. Default is 0. Used for self-testing purposes. + required: false + default: "0" runs: using: composite steps: @@ -41,19 +45,22 @@ runs: # https://github.com/actions/toolkit/issues/1035 # https://github.com/actions/setup-python/issues/361 - name: Generate .git/ansible-lint-requirements.txt + id: get_reqs shell: bash env: GH_ACTION_REF: ${{ github.action_ref || 'main' }} working-directory: ${{ steps.inputs.outputs.working_directory }} run: | - wget --output-document=${{ steps.inputs.outputs.working_directory }}/.git/ansible-lint-requirements.txt https://raw.githubusercontent.com/ansible/ansible-lint/$GH_ACTION_REF/.config/requirements-lock.txt + reqs_file=$(git rev-parse --show-toplevel)/.git/ansible-lint-requirements.txt + echo "reqs_file=$reqs_file\n" >> $GITHUB_OUTPUT + wget --output-document=$reqs_file https://raw.githubusercontent.com/ansible/ansible-lint/$GH_ACTION_REF/.config/requirements-lock.txt - name: Set up Python if: inputs.setup_python == 'true' uses: actions/setup-python@v5 with: cache: pip - cache-dependency-path: ${{ steps.inputs.outputs.working_directory }}/.git/ansible-lint-requirements.txt + cache-dependency-path: ${{ steps.get_reqs.outputs.reqs_file }} python-version: "3.11" - name: Install ansible-lint @@ -78,4 +85,8 @@ runs: - name: Run ansible-lint shell: bash working-directory: ${{ steps.inputs.outputs.working_directory }} - run: ansible-lint ${{ inputs.args }} + run: | + exit_code=0 + expected_exit_code=${{ inputs.expected_return_code }} + ansible-lint ${{ inputs.args }} || exit_code=$? + if [ "$exit_code" != "$expected_exit_code" ]; then echo "Command failed: got '$exit_code', expected '$expected_exit_code'"; exit 1; fi diff --git a/docs/installing.md b/docs/installing.md index c7e4719b13..2e5628d701 100644 --- a/docs/installing.md +++ b/docs/installing.md @@ -116,8 +116,24 @@ jobs: - uses: actions/checkout@v4 - name: Run ansible-lint uses: ansible/ansible-lint@main + # optional (see below): + with: + args: "" + setup_python: "true" + working_directory: "" + requirements_file: "" ``` +All the arguments are optional and most users should not need them: + +- `args`: Arguments to be passed to ansible-lint command. +- `setup_python`: If python should be installed. Default is `true`. +- `working_directory`: The directory where to run ansible-lint from. Default is + `github.workspace`. That might be needed if you want to lint only a subset of + your repository. +- `requirements_file`: Path to the requirements.yml file to install role and + collection dependencies. + Due to limitations on how GitHub Actions are processing arguments, we do not plan to provide extra options. You will have to make use of [ansible-lint own configuration file](https://ansible.readthedocs.io/projects/lint/configuring/) diff --git a/src/ansiblelint/schemas/__store__.json b/src/ansiblelint/schemas/__store__.json index 784f530bc9..d8a797149d 100644 --- a/src/ansiblelint/schemas/__store__.json +++ b/src/ansiblelint/schemas/__store__.json @@ -24,7 +24,7 @@ "url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json" }, "meta": { - "etag": "fdff861b226b13b711dd7f94301ed5becd6dc5d8d4e872f909d4a3d8133d600a", + "etag": "57fd2147c4c70dfd7dea6b3960bb8ed910c01c693de168cc7ac2b8cf527a1166", "url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/meta.json" }, "meta-runtime": {