Skip to content

Commit

Permalink
Allow use as a reusable action
Browse files Browse the repository at this point in the history
- add self testing
- fixes current problems preventing use as an action
- make use of pip caching for linter requirements
  • Loading branch information
ssbarnea committed Jun 1, 2023
1 parent b430fcb commit 8c686e6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,21 @@ jobs:
eco
py-devel
platforms: linux,macos

test-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Self test for ansible-lint@${{ github.action_ref || 'main' }}
uses: ./
with:
# basically we only lint linter own configuration, which should be passing.
args: .ansible-lint
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
needs: pre
needs:
- pre
- test-action
defaults:
run:
shell: ${{ matrix.shell || 'bash'}}
Expand Down Expand Up @@ -210,6 +220,7 @@ jobs:

needs:
- build
- test-action

runs-on: ubuntu-latest

Expand Down
32 changes: 11 additions & 21 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
---
name: ansible-lint
name: run-ansible-lint
description: Run Ansible Lint
author: Ansible by Red Hat <info@ansible.com>
branding:
icon: shield
color: red
inputs:
path:
description: >
Specific path to lint instead of the default `.`. Multiple arguments are
not supported and you will need to alter linter configuration to
accommodate other use cases.
required: false
# That default is just a placeholder workaround for no arguments use-case
# Feeding "." or empty string to ansible-lint makes it believe it is a role
default: --show-relpath
args:
description: deprecated
deprecationMessage: >
Arbitrary args are no longer accepted, please use path instead and
linter own configuration file to change its behavior.
description: Arguments to be passed to ansible-lint command
required: false
default: ""
runs:
Expand All @@ -30,27 +18,29 @@ runs:
fetch-depth: 0 # needed by setuptools-scm
submodules: true

- name: Generate ansible-lint-requirements.txt
shell: bash
run: |
wget --output-file=$HOME/requirements.txt https://raw.githubusercontent.com/ansible/ansible-lint/${{ github.action_ref || 'main' }}/.config/requirements-lock.txt
- name: Set up Python
uses: actions/setup-python@v4
with:
cache: pip
# As setting cache to pip fails if there is no requirements.txt, we
# trick it to also load /dev/null to avoid failure for no requirements.
cache-dependency-path: |
**/requirements*.txt
/dev/null
cache-dependency-path: ~/requirements.txt
python-version: "3.11"

- name: Install ansible-lint
shell: bash
# We need to set the version manually because $GITHUB_ACTION_PATH is not
# a git clone and setuptools-scm would not be able to determine the version.
# git+https://github.com/ansible/ansible-lint@${{ github.action_ref || 'main' }}
# SETUPTOOLS_SCM_PRETEND_VERSION=${{ github.action_ref || 'main' }}
run: |
cd $GITHUB_ACTION_PATH
SETUPTOOLS_SCM_PRETEND_VERSION=${{ github.action_ref || 'main' }} pip install ".[lock]"
pip install "ansible-lint[lock] @ git+https://github.com/ansible/ansible-lint@${{ github.action_ref || 'main' }}"
ansible-lint --version
- name: Run ansible-lint
shell: bash
run: ansible-lint ${{ inputs.path }}
run: ansible-lint ${{ inputs.args }}
9 changes: 9 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# This is used during the ansible-lint own testing.
collections:
- ansible.posix
- ansible.windows
- community.crypto
- community.docker
- community.general
- community.molecule
2 changes: 1 addition & 1 deletion src/ansiblelint/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from _pytest.fixtures import SubRequest


@pytest.fixture(name="default_rules_collection")
@pytest.fixture(name="default_rules_collection", scope="session")
def fixture_default_rules_collection() -> RulesCollection:
"""Return default rule collection."""
assert DEFAULT_RULESDIR.is_dir()
Expand Down
12 changes: 11 additions & 1 deletion test/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from ansiblelint.rules import RulesCollection, filter_rules_with_profile
from ansiblelint.rules.risky_shell_pipe import ShellWithoutPipefail
from ansiblelint.text import strip_ansi_escape


def test_profile_min() -> None:
Expand Down Expand Up @@ -43,7 +44,16 @@ def test_profile_listing(capfd: CaptureFixture[str]) -> None:
# [WARNING]: Ansible is being run in a world writable directory
# WSL2 has "WSL2" in platform name but WSL1 has "microsoft":
platform_name = platform.platform().lower()
err_lines = [line for line in err.splitlines() if "SyntaxWarning:" not in line]
err_lines = []
for line in strip_ansi_escape(err).splitlines():
if "SyntaxWarning:" in line:
continue
if (
"Skipped installing collection dependencies due to running in offline mode."
in line
):
continue
err_lines.append(line)
if all(word not in platform_name for word in ["wsl", "microsoft"]) and err_lines:
assert (
not err_lines
Expand Down
22 changes: 1 addition & 21 deletions tools/install-reqs.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
#!/bin/bash
set -euo pipefail
pushd examples/playbooks/collections >/dev/null
MISSING=()
export ANSIBLE_COLLECTIONS_PATH=.
for COLLECTION in ansible.posix community.docker community.general community.molecule ansible.windows community.crypto;
do
COL_NAME=${COLLECTION//\./-}
FILENAME=$(find . -maxdepth 1 -name "$COL_NAME*" -print -quit)
if test -n "$FILENAME"
then
echo "Already cached $COL_NAME as $FILENAME"
else
MISSING+=("${COLLECTION}")
fi
if [ ${#MISSING[@]} -ne 0 ]; then
ansible-galaxy collection download -p . -v "${MISSING[@]}"
fi
done

echo "Install requirements.yml ..."
ansible-galaxy collection install *.tar.gz -p .
ansible-galaxy collection list
popd >/dev/null
ansible-galaxy collection install -r requirements.yml

0 comments on commit 8c686e6

Please # to comment.