Skip to content

Commit c6bd9a7

Browse files
authored
Address parallel install errors with ansible-galaxy on GHA (#3585)
1 parent 1a50eb7 commit c6bd9a7

File tree

6 files changed

+15
-26
lines changed

6 files changed

+15
-26
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,7 @@ jobs:
9595
~/.cache/ansible-compat
9696
~/.ansible/collections
9797
~/.ansible/roles
98-
key: ${{ matrix.name || matrix.passed_name }}-${{ hashFiles('tools/test-eco.sh', 'requirements.yml') }}
99-
100-
- name: Set galaxy cache
101-
uses: actions/cache@v3
102-
if: ${{ startsWith(matrix.passed_name, 'py') }}
103-
with:
104-
path: |
105-
examples/playbooks/collections/*.tar.gz
106-
examples/playbooks/collections/ansible_collections
107-
key: galaxy-${{ hashFiles('examples/playbooks/collections/requirements.yml') }}
98+
key: ${{ matrix.name || matrix.passed_name }}-${{ hashFiles('tools/test-eco.sh', 'requirements.yml', 'examples/playbooks/collections/requirements.yml') }}
10899

109100
- name: Set up Python ${{ matrix.python_version || '3.9' }}
110101
if: "!contains(matrix.shell, 'wsl')"

src/ansiblelint/__main__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767

6868
_logger = logging.getLogger(__name__)
69+
cache_dir_lock: None | FileLock = None
6970

7071

7172
class LintLogHandler(logging.Handler):
@@ -130,11 +131,12 @@ def initialize_options(arguments: list[str] | None = None) -> None:
130131
if options.cache_dir:
131132
options.cache_dir.mkdir(parents=True, exist_ok=True)
132133

133-
options.cache_dir_lock = None
134134
if not options.offline: # pragma: no cover
135-
options.cache_dir_lock = FileLock(f"{options.cache_dir}/.lock")
135+
cache_dir_lock = FileLock( # pylint: disable=redefined-outer-name
136+
f"{options.cache_dir}/.lock",
137+
)
136138
try:
137-
options.cache_dir_lock.acquire(timeout=180)
139+
cache_dir_lock.acquire(timeout=180)
138140
except Timeout: # pragma: no cover
139141
_logger.error(
140142
"Timeout waiting for another instance of ansible-lint to release the lock.",
@@ -294,9 +296,9 @@ def main(argv: list[str] | None = None) -> int:
294296
app.render_matches(result.matches)
295297

296298
_perform_mockings_cleanup(app.options)
297-
if options.cache_dir_lock:
298-
options.cache_dir_lock.release()
299-
pathlib.Path(options.cache_dir_lock.lock_file).unlink(missing_ok=True)
299+
if cache_dir_lock:
300+
cache_dir_lock.release()
301+
pathlib.Path(cache_dir_lock.lock_file).unlink(missing_ok=True)
300302
if options.mock_filters:
301303
_logger.warning(
302304
"The following filters were mocked during the run: %s",

src/ansiblelint/config.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@
1212
from functools import lru_cache
1313
from importlib.metadata import PackageNotFoundError, distribution, version
1414
from pathlib import Path
15-
from typing import TYPE_CHECKING, Any
15+
from typing import Any
1616
from urllib.error import HTTPError, URLError
1717

1818
from packaging.version import Version
1919

2020
from ansiblelint import __version__
2121
from ansiblelint.loaders import yaml_from_file
2222

23-
if TYPE_CHECKING:
24-
from filelock import BaseFileLock
25-
26-
2723
_logger = logging.getLogger(__name__)
2824

2925

@@ -152,7 +148,6 @@ class Options: # pylint: disable=too-many-instance-attributes,too-few-public-me
152148
config_file: str | None = None
153149
generate_ignore: bool = False
154150
rulesdir: list[Path] = field(default_factory=list)
155-
cache_dir_lock: BaseFileLock | None = None
156151
use_default_rules: bool = False
157152
version: bool = False # display version command
158153
list_profiles: bool = False # display profiles command

src/ansiblelint/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _run(self) -> list[MatchError]:
219219
)
220220

221221
# -- phase 1 : syntax check in parallel --
222-
app = get_app(offline=None)
222+
app = get_app(offline=True)
223223

224224
def worker(lintable: Lintable) -> list[MatchError]:
225225
# pylint: disable=protected-access

src/ansiblelint/schemas/__store__.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json"
2525
},
2626
"meta": {
27-
"etag": "230d2476c1e1f60cd05cba2ac7c42ef658588b1f502e68e85404fd524ef3b3b2",
27+
"etag": "0f376059285181985711b4271a6ff34a8dde662b9fc221d09bdcd64e4fbf86bf",
2828
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/meta.json"
2929
},
3030
"meta-runtime": {

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ deps =
2626
extras =
2727
test
2828
commands_pre =
29-
# fail if submodules are not initialized
30-
sh -c 'git submodule status --cached | grep "^ -" && { echo "Repository was not cloned recursively, please run: git submodule update --init" && exit 99; } || true'
3129
sh -c "rm -f .tox/.coverage.* 2>/dev/null || true"
30+
bash ./tools/install-reqs.sh
3231
commands =
3332
# safety measure to assure we do not accidentally run tests with broken dependencies
3433
{envpython} -m pip check
@@ -69,6 +68,7 @@ setenv =
6968
PRE_COMMIT_COLOR = always
7069
FORCE_COLOR = 1
7170
allowlist_externals =
71+
bash
7272
find
7373
git
7474
pwd
@@ -220,6 +220,7 @@ skip_install = true
220220
usedevelop = false
221221
setenv =
222222
COVERAGE_PROCESS_START={toxinidir}/pyproject.toml
223+
commands_pre =
223224
commands =
224225
python3 -m coverage --version
225226
# needed by codecov github actions, also ignored result to reach report one.

0 commit comments

Comments
 (0)