Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct use of working directory with ansible-lint github action #4340

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
17 changes: 14 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the \n for?

It's causing the following issue for me. See that the cache-dependency-path passed to setup-python includes this \n and appears to be the reason for its failure:

2024-09-19T14:58:48.8798941Z ##[group]Run ansible/ansible-lint@main
2024-09-19T14:58:48.8799414Z with:
2024-09-19T14:58:48.8799782Z   working_directory: ansible
2024-09-19T14:58:48.8800234Z   requirements_file: ansible/requirements.yml
2024-09-19T14:58:48.8800686Z   setup_python: true
2024-09-19T14:58:48.8801086Z   expected_return_code: 0
2024-09-19T14:58:48.8801416Z env:
2024-09-19T14:58:48.8801714Z   ANSIBLE_DIR: ansible
2024-09-19T14:58:48.8802111Z ##[endgroup]
2024-09-19T14:58:48.8994286Z ##[group]Run if [[ -n "ansible" ]]; then
2024-09-19T14:58:48.8994848Z �[36;1mif [[ -n "ansible" ]]; then�[0m
2024-09-19T14:58:48.8995531Z �[36;1m  echo "working_directory=ansible" >> $GITHUB_OUTPUT�[0m
2024-09-19T14:58:48.8996001Z �[36;1melse�[0m
2024-09-19T14:58:48.8996696Z �[36;1m  echo "working_directory=/home/runner/work/Infrastructure/Infrastructure" >> $GITHUB_OUTPUT�[0m
2024-09-19T14:58:48.8997379Z �[36;1mfi�[0m
2024-09-19T14:58:48.9022776Z shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
2024-09-19T14:58:48.9023509Z env:
2024-09-19T14:58:48.9023798Z   ANSIBLE_DIR: ansible
2024-09-19T14:58:48.9024156Z ##[endgroup]
2024-09-19T14:58:48.9137107Z ##[group]Run reqs_file=$(git rev-parse --show-toplevel)/.git/ansible-lint-requirements.txt
2024-09-19T14:58:48.9138042Z �[36;1mreqs_file=$(git rev-parse --show-toplevel)/.git/ansible-lint-requirements.txt�[0m
2024-09-19T14:58:48.9138755Z �[36;1mecho "reqs_file=$reqs_file\n" >> $GITHUB_OUTPUT�[0m
2024-09-19T14:58:48.9139735Z �[36;1mwget --output-document=$reqs_file https://raw.githubusercontent.com/ansible/ansible-lint/$GH_ACTION_REF/.config/requirements-lock.txt�[0m
2024-09-19T14:58:48.9162652Z shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
2024-09-19T14:58:48.9163168Z env:
2024-09-19T14:58:48.9163559Z   ANSIBLE_DIR: ansible
2024-09-19T14:58:48.9163886Z   GH_ACTION_REF: main
2024-09-19T14:58:48.9164253Z ##[endgroup]
2024-09-19T14:58:48.9269413Z --2024-09-19 14:58:48--  https://raw.githubusercontent.com/ansible/ansible-lint/main/.config/requirements-lock.txt
2024-09-19T14:58:48.9326901Z Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.109.133, ...
2024-09-19T14:58:48.9440840Z Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected.
2024-09-19T14:58:49.0746183Z HTTP request sent, awaiting response... 200 OK
2024-09-19T14:58:49.0748853Z Length: 991 [text/plain]
2024-09-19T14:58:49.0751181Z Saving to: ‘/home/runner/work/Infrastructure/Infrastructure/.git/ansible-lint-requirements.txt’
2024-09-19T14:58:49.0752331Z 
2024-09-19T14:58:49.0752685Z      0K                                                       100% 69.5M=0s
2024-09-19T14:58:49.0753203Z 
2024-09-19T14:58:49.0754447Z 2024-09-19 14:58:49 (69.5 MB/s) - ‘/home/runner/work/Infrastructure/Infrastructure/.git/ansible-lint-requirements.txt’ saved [991/991]
2024-09-19T14:58:49.0756101Z 
2024-09-19T14:58:49.0839635Z ##[group]Run actions/setup-python@v5
2024-09-19T14:58:49.0840175Z with:
2024-09-19T14:58:49.0840451Z   cache: pip
2024-09-19T14:58:49.0841147Z   cache-dependency-path: /home/runner/work/Infrastructure/Infrastructure/.git/ansible-lint-requirements.txt\n
2024-09-19T14:58:49.0841982Z   python-version: 3.11
2024-09-19T14:58:49.0842347Z   check-latest: false
2024-09-19T14:58:49.0842891Z   token: ***
2024-09-19T14:58:49.0843217Z   update-environment: true
2024-09-19T14:58:49.0843602Z   allow-prereleases: false
2024-09-19T14:58:49.0844032Z env:
2024-09-19T14:58:49.0844329Z   ANSIBLE_DIR: ansible
2024-09-19T14:58:49.0844638Z ##[endgroup]
2024-09-19T14:58:49.2516582Z ##[group]Installed versions
2024-09-19T14:58:49.2593636Z Successfully set up CPython (3.11.10)
2024-09-19T14:58:49.2596613Z ##[endgroup]
2024-09-19T14:58:49.4989609Z ##[error]No file in /home/runner/work/Infrastructure/Infrastructure matched to [/home/runner/work/Infrastructure/Infrastructure/.git/ansible-lint-requirements.txt\n or **/pyproject.toml], make sure you have checked out the target repository

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved by #4342.

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
Expand All @@ -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
16 changes: 16 additions & 0 deletions docs/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/schemas/__store__.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Loading