Skip to content

Commit

Permalink
update dev workflow, consolidate task files, add molecule tests (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
trfore committed May 5, 2024
2 parents bba2f36 + 73bf3fc commit 13af297
Show file tree
Hide file tree
Showing 29 changed files with 512 additions and 156 deletions.
9 changes: 9 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
profile: production
exclude_paths:
- .github/workflows/
- .tox/
- .venv/
- changelogs/changelog.yaml
warn_list:
- command-instead-of-shell
- yaml[line-length]
37 changes: 31 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
name: CI
on:
workflow_dispatch:
pull_request:
branches: ["*"]
paths-ignore:
- "**.md"
- "LICENSE"
- "README.md"
workflow_dispatch:

concurrency:
group: ${{ github.workflow}}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint_ansible:
uses: trfore/ansible-role/.github/workflows/lint_ansible.yml@main # remote repo
format:
uses: trfore/ansible-role/.github/workflows/format.yml@main

molecule_test:
lint:
needs:
- lint_ansible
- format
uses: trfore/ansible-role/.github/workflows/lint_ansible.yml@main

test:
needs:
- format
- lint
strategy:
fail-fast: false
matrix:
Expand All @@ -32,3 +42,18 @@ jobs:
distro: ${{ matrix.distro }}
experimental: ${{ matrix.experimental }}
molecule_scenario: ${{ matrix.molecule_scenario }}
requirements_file: "requirements/dev-requirements.txt"

check:
needs:
- format
- lint
- test
runs-on: ubuntu-latest
steps:
- run: >-
python -c "assert set([
'${{ needs.format.result }}',
'${{ needs.lint.result }}',
'${{ needs.test.result }}',
]) == {'success'}"
28 changes: 23 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
name: Lint
on:
workflow_dispatch:
pull_request:
branches: ["main"]
paths:
- "**.md"
- "LICENSE"
push:
branches: ["*"]
paths-ignore:
paths:
- "**.md"
- "LICENSE"
- "README.md"

concurrency:
group: ${{ github.workflow}}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint_ansible:
uses: trfore/ansible-role/.github/workflows/lint_ansible.yml@main # remote repo
format:
uses: trfore/ansible-role/.github/workflows/format.yml@main

check:
needs:
- format
runs-on: ubuntu-latest
steps:
- run: >-
python -c "assert set([
'${{ needs.format.result }}',
]) == {'success'}"
143 changes: 142 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,154 @@
# ansible
*.retry
*/__pycache__
*.pyc
*.py[cod]
*$py.class
.cache
/tests/output/
/changelogs/.plugin-cache.yaml

# ansible extras - typical development
*.deb
*.tgz
*.tar.gz*

# ansible docs - sphinx local build files
docs/rst
docs/.gitignore
docs/antsibull-docs.cfg
docs/build.sh
docs/conf.py
docs/requirements.txt

# general extras
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
35 changes: 20 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,17 @@ repos:
hooks:
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
args: [--allow-multiple-documents]
- id: debug-statements
- id: end-of-file-fixer
- id: no-commit-to-branch
args: [--branch, main]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-yaml
args: [--allow-multiple-documents]

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.0.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/adrienverge/yamllint
rev: v1.31.0
hooks:
- id: yamllint
args: [-c=.yamllint]

- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.2
- repo: https://github.com/trfore/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_find_unused_variable
- id: ansible_role_fix_readability
Expand All @@ -34,3 +23,19 @@ repos:
- id: ansible_role_find_horizontal_when
- id: ansible_role_find_empty_files
- id: ansible_role_find_empty_directories

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier

- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
args: [-c=.yamllint]

- repo: https://github.com/ansible/ansible-lint
rev: v24.2.2
hooks:
- id: ansible-lint
15 changes: 11 additions & 4 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# linted by yamllint
*.yaml
*.yml
.pylintrc
# environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# formatted by antsibull-changelog
changelogs/changelog.yaml
10 changes: 10 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# .prettierrc.yaml
bracketSpacing: true
endOfLine: "lf"
printWidth: 160
proseWrap: "preserve"
quoteProps: "as-needed"
semi: true
singleQuote: false
tabWidth: 2
trailingComma: "es5"
7 changes: 6 additions & 1 deletion .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Based on ansible-lint config
extends: default

ignore:
- .tox/
- .venv/

rules:
braces:
max-spaces-inside: 1
Expand All @@ -15,7 +19,8 @@ rules:
commas:
max-spaces-after: -1
level: error
comments: disable
comments:
min-spaces-from-content: 1 # prettier compatibility
comments-indentation: disable
document-start: disable
empty-lines:
Expand Down
41 changes: 41 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contributing

## Contribute

### Setup a Dev Environment

```sh
python3 -m venv .venv && source .venv/bin/activate
python3 -m pip install -r requirements/dev-requirements.txt
pre-commit install
```

### Running Test

```sh
pre-commit run --all-files

# list environments and test
tox list
# lint all files
tox -e lint run
# run a specific test environment
tox -e py-ansible2.16-ubuntu20 run
# run all test in parallel
tox run-parallel
```

- For iterative development and testing, the tox molecule environments are written to accept `molecule` arguments. This allows for codebase changes to be tested as you write across multiple distros and versions of `ansible-core`.

```sh
# molecule converge
tox -e py-ansible2.16-ubuntu20 run -- converge -s default
# molecule test w/o destroying the container
tox -r -e py-ansible2.16-ubuntu20-jre8 -- test -s ubuntu20-jre8 --destroy=never
```

## Additional References

- [Ansible community guide](https://docs.ansible.com/ansible/devel/community/index.html)
- [Github Docs: Forking a repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo#forking-a-repository)
- [Ansible Docs: `ansible-core` support matrix](https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix)
Loading

0 comments on commit 13af297

Please sign in to comment.