Created
June 2, 2022 20:46
-
-
Save cidrblock/2e68028e95830c9518bc518d847cacec to your computer and use it in GitHub Desktop.
Sample pypyr CI pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample pypyr file for running CI jobs locally | |
# example usage: | |
# - run with default parameters (python3.10 and ansible 2.13) | |
# $ pypyr run | |
# - run with default paramters, but stop at the first error | |
# $ pypyr run continue_on_error=False | |
# - run with py3.8 and ansible 2.12 | |
# $ pypyr run python_version=3.8 ansible_version=stable-2.12 | |
# - run with py3.10 and milestone, but only unit and sanity | |
# $ pypyr run python_version=3.10 ansible_version=stable-2.12 --groups unit sanity | |
context_parser: pypyr.parser.keyvaluepairs | |
defaults: | |
- comment: Set default values for optional cli inputs | |
name: pypyr.steps.default | |
in: | |
defaults: | |
ansible_version: "stable-2.13" | |
ansible_versions: | |
- devel | |
- milestone | |
- "stable-2.13" | |
- "stable-2.12" | |
- "stable-2.11" | |
- "stable-2.10" | |
- "stable-2.9" | |
continue_on_error: true | |
python_version: "3.10" | |
venv_path: ".pypyr/{python_version}-{ansible_version}/venv" | |
bin_path: "{venv_path}/bin" | |
- comment: Set the ansible package name | |
name: pypyr.steps.py | |
in: | |
py: | | |
_major, minor = ansible_version.split('.') | |
if int(minor) > 10: | |
ansible_package = 'ansible-core' | |
elif int(minor) == 10: | |
ansible_package = 'ansible-base' | |
else: | |
ansible_package = 'ansible' | |
save('ansible_package') | |
- comment: Ensure the ansible version is sane | |
name: pypyr.steps.assert | |
in: | |
assert: !py "ansible_version in ansible_versions" | |
onError: !py 'f"ansible_version must be one of {ansible_versions}"' | |
steps: | |
- comment: Run the ansible-lint group | |
name: pypyr.steps.call | |
in: | |
call: ansible-lint | |
swallow: "{continue_on_error}" | |
- comment: Run the pre-commit group | |
name: pypyr.steps.call | |
in: | |
call: pre-commit | |
swallow: "{continue_on_error}" | |
- comment: Run the ansible-test sanity group | |
name: pypyr.steps.call | |
in: | |
call: sanity | |
swallow: "{continue_on_error}" | |
- comment: Run the unit tests | |
name: pypyr.steps.call | |
in: | |
call: unit | |
swallow: "{continue_on_error}" | |
initialize: | |
- comment: Initialize the environment, if not already done | |
name: pypyr.steps.stopstepgroup | |
run: !py "locals().get('initialized', False)" | |
- comment: Set the default variables | |
name: pypyr.steps.call | |
in: | |
call: defaults | |
- comment: Initialize the virtual environment | |
name: pypyr.steps.cmd | |
in: | |
cmd: | |
- run: "python{python_version} -m venv {venv_path}" | |
stdout: /dev/null | |
- run: "{bin_path}/python3 -m pip install --upgrade pip" | |
stdout: /dev/null | |
- run: "{bin_path}/python3 -m pip -q install https://github.com/ansible/ansible/archive/{ansible_version}.tar.gz --disable-pip-version-check" | |
stdout: /dev/null | |
- run: "{bin_path}/python3 -m pip -q install -r requirements.txt -r test-requirements.txt pre-commit" | |
stdout: /dev/null | |
- comment: Set the virtual environment built state | |
name: pypyr.steps.set | |
in: | |
set: | |
initialized: True | |
ansible-lint: | |
- comment: Initialize the environment | |
name: pypyr.steps.call | |
in: | |
call: | |
groups: initialize | |
failure: on_failure | |
- comment: Print the start status | |
name: pypyr.steps.echo | |
in: | |
echoMe: "ansible-lint: running" | |
- comment: Run ansible-lint | |
name: pypyr.steps.cmd | |
in: | |
cmd: | |
- run: ansible-lint tests/integration | |
- comment: Print the end status | |
name: pypyr.steps.echo | |
in: | |
echoMe: "ansible-lint: success" | |
pre-commit: | |
- comment: Initialize the environment | |
name: pypyr.steps.call | |
in: | |
call: | |
groups: initialize | |
failure: on_failure | |
- comment: Print the start status | |
name: pypyr.steps.echo | |
in: | |
echoMe: "pre-commit: running" | |
- comment: Run pre-commit | |
name: pypyr.steps.cmd | |
in: | |
cmd: | |
- run: pre-commit run --all-files | |
- comment: Print the end status | |
name: pypyr.steps.echo | |
in: | |
echoMe: "pre-commit: success" | |
sanity: | |
- comment: Initialize the environment | |
name: pypyr.steps.call | |
in: | |
call: | |
groups: initialize | |
failure: on_failure | |
- comment: Print the start status | |
name: pypyr.steps.echo | |
in: | |
echoMe: "ansible-test sanity: running" | |
- comment: Run ansible-test sanity | |
name: pypyr.steps.cmd | |
in: | |
cmd: | |
- run: "{bin_path}/ansible-test sanity --requirements --color --python {python_version}" | |
- comment: Print the end status | |
name: pypyr.steps.echo | |
in: | |
echoMe: "ansible-test sanity: success" | |
unit: | |
- comment: Initialize the environment | |
name: pypyr.steps.call | |
in: | |
call: | |
groups: initialize | |
failure: on_failure | |
- comment: Print the start status | |
name: pypyr.steps.echo | |
in: | |
echoMe: "unit tests: running" | |
- comment: Run unit tests | |
name: pypyr.steps.cmd | |
in: | |
cmd: | |
- run: "{bin_path}/pytest tests/unit" | |
- comment: Print the end status | |
name: pypyr.steps.echo | |
in: | |
echoMe: "unit tests: success" | |
on_failure: | |
- name: pypyr.steps.echo | |
comment: Print the error message | |
in: | |
echoMe: "the error was: {runErrors[0][customError]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment