Skip to content

Commit 9765b87

Browse files
authored
Check for gh_action_ref explicitly and document GHA inputs (#4701)
1 parent 198b7dd commit 9765b87

File tree

5 files changed

+49
-28
lines changed

5 files changed

+49
-28
lines changed

.config/constraints.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# This file was autogenerated by uv via the following command:
22
# tox run -e deps
3-
ansible-compat==25.5.0 # via ansible-lint (pyproject.toml)
3+
ansible-compat==25.6.0 # via ansible-lint (pyproject.toml)
44
ansible-creator==25.6.0 # via ansible-lint (pyproject.toml)
55
astroid==3.3.10 # via pylint
66
asttokens==3.0.0 # via stack-data
7-
attrs==25.3.0 # via jsonschema, referencing
7+
attrs==25.3.0 # via jsonschema, referencing, ansible-lint (pyproject.toml)
88
babel==2.17.0 # via mkdocs-material
99
backrefs==5.9 # via mkdocs-material
1010
beautifulsoup4==4.13.4 # via linkchecker, mkdocs-htmlproofer-plugin
1111
bindep==2.13.0 # via tox-extra
1212
black==25.1.0 # via ansible-lint (pyproject.toml)
1313
boolean-py==5.0 # via license-expression
14-
bracex==2.6 # via wcmatch
14+
bracex==2.6 # via wcmatch, ansible-lint (pyproject.toml)
1515
cachetools==6.1.0 # via tox
1616
cairocffi==1.7.1 # via cairosvg
1717
cairosvg==2.7.1 # via mkdocs-ansible
1818
certifi==2025.7.14 # via requests
19-
cffi==1.17.1 # via cairocffi, cryptography
19+
cffi==1.17.1 # via cairocffi, cryptography, ansible-lint (pyproject.toml)
2020
chardet==5.2.0 # via tox
2121
charset-normalizer==3.4.2 # via requests
22-
click==8.2.1 # via black, mkdocs
22+
click==8.2.1 # via black, mkdocs, ansible-lint (pyproject.toml)
2323
colorama==0.4.6 # via griffe, mkdocs-material, tox
2424
coverage==7.10.0 # via coverage-enable-subprocess, ansible-lint (pyproject.toml)
2525
coverage-enable-subprocess==1.0 # via ansible-lint (pyproject.toml)
26-
cryptography==45.0.5 # via ansible-core
26+
cryptography==45.0.5 # via ansible-core, ansible-lint (pyproject.toml)
2727
csscompressor==0.9.5 # via mkdocs-minify-plugin
2828
cssselect2==0.8.0 # via cairosvg
2929
decorator==5.2.1 # via ipdb, ipython
@@ -48,17 +48,17 @@ ipdb==0.13.13 # via ansible-lint (pyproject.toml)
4848
ipython==8.36.0 # via ipdb, ansible-lint (pyproject.toml)
4949
isort==6.0.1 # via pylint
5050
jedi==0.19.2 # via ipython
51-
jinja2==3.1.6 # via ansible-core, ansible-creator, mkdocs, mkdocs-macros-plugin, mkdocs-material, mkdocstrings
51+
jinja2==3.1.6 # via ansible-core, ansible-creator, mkdocs, mkdocs-macros-plugin, mkdocs-material, mkdocstrings, ansible-lint (pyproject.toml)
5252
jmespath==1.0.1 # via ansible-lint (pyproject.toml)
5353
jsmin==3.0.1 # via mkdocs-minify-plugin
5454
jsonschema==4.24.0 # via ansible-compat, ansible-lint (pyproject.toml)
55-
jsonschema-specifications==2025.4.1 # via jsonschema
55+
jsonschema-specifications==2025.4.1 # via jsonschema, ansible-lint (pyproject.toml)
5656
license-expression==30.4.3 # via ansible-lint (pyproject.toml)
5757
linkchecker==10.5.0 # via mkdocs-ansible
5858
markdown==3.8 # via markdown-include, mkdocs, mkdocs-autorefs, mkdocs-htmlproofer-plugin, mkdocs-material, mkdocstrings, pymdown-extensions
5959
markdown-exec==1.11.0 # via mkdocs-ansible
6060
markdown-include==0.8.1 # via mkdocs-ansible
61-
markupsafe==3.0.2 # via jinja2, mkdocs, mkdocs-autorefs, mkdocstrings
61+
markupsafe==3.0.2 # via jinja2, mkdocs, mkdocs-autorefs, mkdocstrings, ansible-lint (pyproject.toml)
6262
matplotlib-inline==0.1.7 # via ipython
6363
mccabe==0.7.0 # via pylint
6464
mergedeep==1.3.4 # via mkdocs, mkdocs-get-deps
@@ -75,7 +75,7 @@ mkdocs-minify-plugin==0.8.0 # via mkdocs-ansible
7575
mkdocstrings==0.30.0 # via mkdocs-ansible, mkdocstrings-python
7676
mkdocstrings-python==1.16.12 # via mkdocs-ansible
7777
mypy==1.16.1 # via ansible-lint (pyproject.toml)
78-
mypy-extensions==1.1.0 # via black, mypy
78+
mypy-extensions==1.1.0 # via black, mypy, ansible-lint (pyproject.toml)
7979
netaddr==1.3.0 # via ansible-lint (pyproject.toml)
8080
packaging==25.0 # via ansible-compat, ansible-core, bindep, black, mkdocs, mkdocs-macros-plugin, pyproject-api, pytest, pytest-sugar, tox, tox-extra, tox-uv, ansible-lint (pyproject.toml)
8181
paginate==0.5.7 # via mkdocs-material
@@ -85,13 +85,13 @@ pathspec==0.12.1 # via black, mkdocs, mkdocs-macros-plugin, mypy, yamll
8585
pbr==6.1.1 # via bindep
8686
pexpect==4.9.0 # via ipython
8787
pillow==11.3.0 # via cairosvg, mkdocs-ansible
88-
platformdirs==4.3.8 # via black, mkdocs-get-deps, pylint, tox, virtualenv
88+
platformdirs==4.3.8 # via black, mkdocs-get-deps, pylint, tox, virtualenv, ansible-lint (pyproject.toml)
8989
pluggy==1.6.0 # via pytest, tox
9090
prompt-toolkit==3.0.51 # via ipython
9191
psutil==7.0.0 # via pytest-xdist, ansible-lint (pyproject.toml)
9292
ptyprocess==0.7.0 # via pexpect
9393
pure-eval==0.2.3 # via stack-data
94-
pycparser==2.22 # via cffi
94+
pycparser==2.22 # via cffi, ansible-lint (pyproject.toml)
9595
pygments==2.19.2 # via ipython, mkdocs-material, pytest
9696
pylint==3.3.7 # via ansible-lint (pyproject.toml)
9797
pymdown-extensions==10.16 # via markdown-exec, mkdocs-ansible, mkdocs-material, mkdocstrings
@@ -107,8 +107,8 @@ pyyaml==6.0.2 # via ansible-compat, ansible-core, ansible-creator, m
107107
pyyaml-env-tag==1.1 # via mkdocs
108108
referencing==0.36.2 # via jsonschema, jsonschema-specifications, types-jsonschema, ansible-lint (pyproject.toml)
109109
requests==2.32.4 # via linkchecker, mkdocs-htmlproofer-plugin, mkdocs-material
110-
rpds-py==0.26.0 # via jsonschema, referencing
111-
ruamel-yaml==0.18.11 # via ansible-lint (pyproject.toml)
110+
rpds-py==0.26.0 # via jsonschema, referencing, ansible-lint (pyproject.toml)
111+
ruamel-yaml==0.18.14 # via ansible-lint (pyproject.toml)
112112
setproctitle==1.3.6 # via pytest-xdist
113113
setuptools==80.9.0 # via pbr
114114
six==1.17.0 # via python-dateutil
@@ -129,11 +129,11 @@ types-pyyaml==6.0.12.20250516 # via ansible-lint (pyproject.toml)
129129
urllib3==2.5.0 # via requests
130130
virtualenv==20.32.0 # via tox
131131
watchdog==6.0.0 # via mkdocs
132-
wcmatch==10.0 # via ansible-lint (pyproject.toml)
132+
wcmatch==10.1 # via ansible-lint (pyproject.toml)
133133
wcwidth==0.2.13 # via prompt-toolkit
134134
webencodings==0.5.1 # via cssselect2, tinycss2
135135
yamllint==1.37.1 # via ansible-lint (pyproject.toml)
136-
zipp==3.23.0 # via importlib-metadata
136+
zipp==3.23.0 # via importlib-metadata, ansible-lint (pyproject.toml)
137137

138138
# The following packages were excluded from the output:
139139
# ansible-core

.github/workflows/tox.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
GITHUB_ACTIONS_TEST: "true"
5454
steps:
5555
- uses: actions/checkout@v4
56-
- name: Self test 1
56+
- name: Self test 1 # Test without explicit ref - fallback to main
5757
uses: ./
5858
with:
5959
# basically we only lint linter own configuration, which should be passing.
@@ -71,6 +71,12 @@ jobs:
7171
args: .ansible-lint
7272
working_directory: docs
7373
expected_return_code: "2" # expected to fail because the given argument does not exist in this folder
74+
- name: Self test 4 # Test explicit ref override - expect warning message
75+
uses: ./
76+
with:
77+
args: .ansible-lint
78+
gh_action_ref: "v25.5.0"
79+
7480
build:
7581
name: ${{ matrix.name }}
7682
runs-on: ${{ matrix.os || 'ubuntu-24.04' }}

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,31 @@ jobs:
2929
steps:
3030
- uses: actions/checkout@v4
3131
- name: Run ansible-lint
32-
uses: ansible/ansible-lint@main
32+
uses: ansible/ansible-lint@main # or vX.X.X version
3333
# optional (see below):
3434
with:
3535
args: ""
36+
gh_action_ref: "<version - e.g. `v25.5.0`>" # Not recommended for non-composite action use
3637
setup_python: "true"
3738
working_directory: ""
3839
requirements_file: ""
3940
```
4041
41-
All the arguments are optional and most users should not need them:
42+
By default, the workflow uses ansible-lint installed from `main`. For production or stable workflows, it is recommended to specify a particular release tag (in format v.X.X.X).
43+
44+
All the arguments are optional:
4245

4346
- `args`: Arguments to be passed to ansible-lint command.
47+
- `gh_action_ref`: The git branch, tag, or commit to use for ansible-lint.
48+
Not recommended for standard use - only use with composite actions where
49+
`GH_ACTION_REF` is set to the parent action version.
50+
- `requirements_file`: Path to the requirements.yml file to install role and
51+
collection dependencies.
4452
- `setup_python`: If python should be installed. Default is `true`.
4553
- `working_directory`: The directory where to run ansible-lint from. Default is
46-
`github.workspace`. That might be needed if you want to lint only a subset of
54+
`github.workspace`. Needed if you want to lint only a subset of
4755
your repository.
48-
- `requirements_file`: Path to the requirements.yml file to install role and
49-
collection dependencies.
56+
5057

5158
For more details, see [ansible-lint-action].
5259

action.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ inputs:
1313
setup_python:
1414
description: If false, this action will not setup python and will instead rely on the already installed python.
1515
required: false
16-
default: true
16+
default: "true"
1717
working_directory:
1818
description: The directory where to run ansible-lint from. Default is `github.workspace`.
1919
required: false
@@ -23,11 +23,11 @@ inputs:
2323
required: false
2424
default: ""
2525
expected_return_code:
26-
description: Expected return code from ansible-lint. Default is 0. Used for self-testing purposes.
26+
description: (Internal use only) Expected return code from ansible-lint. Default is 0. Used for self-testing purposes.
2727
required: false
2828
default: "0"
2929
gh_action_ref:
30-
description: The branch, tag, or commit to use for ansible-lint.
30+
description: The branch, tag, or commit to use for ansible-lint. Only recommended for use with composite actions where `GH_ACTION_REF` is set to the parent action version.
3131
default: ""
3232
required: false
3333
runs:
@@ -47,10 +47,15 @@ runs:
4747
# This allows a user to override it using the input variable
4848
- name: Determine github action ref
4949
shell: bash
50+
env:
51+
GH_ACTION_REF_INPUT: ${{ inputs.gh_action_ref }}
52+
GITHUB_ACTION_REF: ${{ github.action_ref }}
5053
run: |
51-
action_ref="${{ inputs.gh_action_ref }}"
52-
if [[ -z "${{ inputs.gh_action_ref }}" ]]; then
53-
action_ref="${{ github.action_ref || 'main' }}"
54+
action_ref="${GH_ACTION_REF_INPUT:-${GITHUB_ACTION_REF:-main}}"
55+
if [[ ${GH_ACTION_REF_INPUT} ]]; then
56+
echo "::warning::Using input 'gh_action_ref': Loading ansible-lint version ${action_ref}. This input should only be used in composite actions where built-in 'GH_ACTION_REF' is set to the parent action version. If possible, use the 'uses: ansible-lint@<version>' syntax instead."
57+
else
58+
echo "Using ansible-lint ref: $action_ref"
5459
fi
5560
echo "ACTION_REF=${action_ref}" >> "$GITHUB_ENV"
5661

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ convention = "google"
534534
[tool.setuptools.dynamic]
535535
dependencies = {file = [".config/requirements.in"]}
536536
optional-dependencies.docs = {file = [".config/requirements-docs.in"]}
537+
# 'lock' will work only if you use a python version supported by the latest
538+
# release of ansible-core, otherwise installation will fail
539+
optional-dependencies.lock = {file = [".config/requirements-lock.txt"]}
537540
optional-dependencies.test = {file = [".config/requirements-test.in"]}
538541

539542
[tool.setuptools_scm]

0 commit comments

Comments
 (0)