确保内容最佳实践¶
在 CI 中添加用于 lint 的 tox 条目¶
将 lint 集成到您的持续集成 (CI) 管道中,可确保您的代码库符合编码标准和最佳实践。
添加用于 Lint 的 Tox 条目
- 在项目根目录中创建一个 `tox.ini` 文件。此文件将包含运行各种环境的配置。
# tox.ini
[tox]
env_list = lint
[testenv:lint]
deps =
pre-commit
# Add other linters as needed
commands =
pre-commit run --show-diff-on-failure --all-files
- 更新您的 CI 配置文件(例如,对于 GitHub Actions 为 `.github/workflows/main.yml`),以包含带有 lint 环境的 tox 命令。
- 将更改提交到您的存储库并推送它们,以触发 CI 管道。
您已成功在 CI 设置中添加了用于 lint 的 tox 条目(`tox -e lint`)。这确保了每当将更改推送到存储库时都会自动执行 lint 检查,从而有助于维护干净一致的代码库。
使用 tox-ansible 运行完整性测试¶
Tox-ansible 使用 `ansible-test sanity` 来运行完整性测试。安装 `tox-ansible` 后,在集合的根目录中创建一个空的 `tox-ansible.ini` 文件并列出可用的环境。
将显示动态生成的 Ansible 环境列表。
default environments:
...
integration-py3.11-2.14 -> Integration tests for ansible.scm using ansible-core 2.14 and python 3.11
...
sanity-py3.11-2.14 -> Sanity tests for ansible.scm using ansible-core 2.14 and python 3.11
sanity-py3.11-devel -> Sanity tests for ansible.scm using ansible-core devel and python 3.11
sanity-py3.11-milestone -> Sanity tests for ansible.scm using ansible-core milestone and python 3.11
...
unit-py3.11-2.14 -> Unit tests for ansible.scm using ansible-core 2.14 and python 3.11
要使用单个环境运行测试,请运行以下命令:
要使用多个环境运行测试,请将环境名称添加到命令中:
请参考 tox-ansible 文档 查看更多选项。