From 35829a5bceb473dc0bea5bcda9e3ca77ae7c6690 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 29 Oct 2020 16:27:15 +0000 Subject: [PATCH] Made driver compatible with molecule 3.2 --- .github/release-drafter.yml | 23 ++-- .github/workflows/release-drafter.yml | 18 ++++ .github/workflows/tox.yml | 146 ++++++++++++++++++++++++++ .pre-commit-config.yaml | 14 +-- molecule_lxd/driver.py | 2 +- playbooks/ensure-lxd.yaml | 7 +- pytest.ini | 2 +- setup.cfg | 23 +--- tox.ini | 71 ++++++------- 9 files changed, 232 insertions(+), 74 deletions(-) create mode 100644 .github/workflows/release-drafter.yml create mode 100644 .github/workflows/tox.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index c5a15a7..a444deb 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,15 +1,24 @@ +# Format and labels used aim to match those used by Ansible project categories: - - title: 'Features' + - title: 'Major Changes' labels: - - 'feature' - - 'enhancement' - - title: 'Bug Fixes' + - 'major' # c6476b + - title: 'Minor Changes' + labels: + - 'feature' # 006b75 + - 'enhancement' # ededed + - 'performance' # 555555 + - title: 'Bugfixes' labels: - 'fix' - 'bugfix' - - 'bug' - - title: 'Maintenance' - label: 'chore' + - 'bug' # fbca04 + - 'docs' # 4071a5 + - 'packaging' # 4071a5 + - 'test' # #0e8a16 + - title: 'Deprecations' + labels: + - 'deprecated' # fef2c0 exclude-labels: - 'skip-changelog' template: | diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..7d3004a --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,18 @@ +name: Release Drafter + +on: + push: + # branches to consider in the event; optional, defaults to all + branches: + - master + - 'releases/**' + - 'stable/**' + +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + # Drafts your next Release notes as Pull Requests are merged into "master" + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml new file mode 100644 index 0000000..1882bce --- /dev/null +++ b/.github/workflows/tox.yml @@ -0,0 +1,146 @@ +name: tox + +on: + create: # is used for publishing to TestPyPI + tags: # any tag regardless of its name, no branches + - "**" + push: # only publishes pushes to the main branch to TestPyPI + branches: # any integration branch but not tag + - "master" + pull_request: + release: + types: + - published # It seems that you can publish directly without creating + schedule: + - cron: 1 0 * * * # Run daily at 0:01 UTC + +jobs: + build: + name: ${{ matrix.tox_env }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - tox_env: lint + # - tox_env: docs + - tox_env: py36 + PREFIX: PYTEST_REQPASS=1 + - tox_env: py36-devel + PREFIX: PYTEST_REQPASS=1 + - tox_env: py37 + PREFIX: PYTEST_REQPASS=1 + - tox_env: py38 + PREFIX: PYTEST_REQPASS=1 + - tox_env: py39 + PREFIX: PYTEST_REQPASS=1 + - tox_env: py39-devel + PREFIX: PYTEST_REQPASS=1 + - tox_env: packaging + + steps: + - uses: actions/checkout@v1 + - name: Install system dependencies + run: | + sudo apt-get update \ + && sudo apt-get install -y ansible \ + && ansible-doc -l | grep docker_container + - name: Find python version + id: py_ver + shell: python + if: ${{ contains(matrix.tox_env, 'py') }} + run: | + v = '${{ matrix.tox_env }}'.split('-')[0].lstrip('py') + print('::set-output name=version::{0}.{1}'.format(v[0],v[1:])) + # Even our lint and other envs need access to tox + - name: Install a default Python + uses: actions/setup-python@v2 + if: ${{ ! contains(matrix.tox_env, 'py') }} + # Be sure to install the version of python needed by a specific test, if necessary + - name: Set up Python version + uses: actions/setup-python@v2 + if: ${{ contains(matrix.tox_env, 'py') }} + with: + python-version: ${{ steps.py_ver.outputs.version }} + - name: Install dependencies + run: | + docker version + docker info + python -m pip install -U pip + pip install tox + - name: Run tox -e ${{ matrix.tox_env }} + run: | + echo "${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}" + ${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }} + + publish: + name: Publish to PyPI registry + needs: + - build + runs-on: ubuntu-latest + + env: + PY_COLORS: 1 + TOXENV: packaging + + steps: + - name: Switch to using Python 3.6 by default + uses: actions/setup-python@v2 + with: + python-version: 3.6 + - name: Install tox + run: python -m pip install --user tox + - name: Check out src from Git + uses: actions/checkout@v2 + with: + # Get shallow Git history (default) for release events + # but have a complete clone for any other workflows. + # Both options fetch tags but since we're going to remove + # one from HEAD in non-create-tag workflows, we need full + # history for them. + fetch-depth: >- + ${{ + ( + ( + github.event_name == 'create' && + github.event.ref_type == 'tag' + ) || + github.event_name == 'release' + ) && + 1 || 0 + }} + - name: Drop Git tags from HEAD for non-tag-create and non-release events + if: >- + ( + github.event_name != 'create' || + github.event.ref_type != 'tag' + ) && + github.event_name != 'release' + run: >- + git tag --points-at HEAD + | + xargs git tag --delete + - name: Build dists + run: python -m tox + - name: Publish to test.pypi.org + if: >- + ( + github.event_name == 'push' && + github.ref == format( + 'refs/heads/{0}', github.event.repository.default_branch + ) + ) || + ( + github.event_name == 'create' && + github.event.ref_type == 'tag' + ) + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{ secrets.testpypi_password }} + repository_url: https://test.pypi.org/legacy/ + - name: Publish to pypi.org + if: >- # "create" workflows run separately from "push" & "pull_request" + github.event_name == 'release' + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{ secrets.pypi_password }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cde5447..1f0009d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ default_language_version: minimum_pre_commit_version: "1.14.0" repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.5.0 + rev: v3.3.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace @@ -19,22 +19,22 @@ repos: # https://github.com/pre-commit/pre-commit-hooks/issues/273 args: ["--unsafe"] - repo: https://github.com/PyCQA/doc8.git - rev: 0.8.1rc3 + rev: 0.9.0a1 hooks: - id: doc8 - repo: https://github.com/python/black.git - rev: 19.10b0 + rev: 20.8b1 hooks: - id: black language_version: python3 - repo: https://gitlab.com/pycqa/flake8.git - rev: 3.7.9 + rev: 3.8.4 hooks: - id: flake8 additional_dependencies: - flake8-black - repo: https://github.com/codespell-project/codespell.git - rev: v1.16.0 + rev: v1.17.1 hooks: - id: codespell name: codespell @@ -46,7 +46,7 @@ repos: require_serial: false additional_dependencies: [] - repo: https://github.com/adrienverge/yamllint.git - rev: v1.21.0 + rev: v1.25.0 hooks: - id: yamllint files: \.(yaml|yml)$ @@ -65,7 +65,7 @@ repos: # use jinja templating, this will often fail and the syntax # error will be discovered in execution anyway) - repo: https://github.com/ansible/ansible-lint.git - rev: v4.2.0 + rev: v4.3.5 hooks: - id: ansible-lint always_run: true diff --git a/molecule_lxd/driver.py b/molecule_lxd/driver.py index a964e4d..344a420 100644 --- a/molecule_lxd/driver.py +++ b/molecule_lxd/driver.py @@ -113,7 +113,7 @@ def sanity_checks(self): pass def template_dir(self): - """ Return path to its own cookiecutterm templates. It is used by init + """Return path to its own cookiecutterm templates. It is used by init command in order to figure out where to load the templates from. """ return os.path.join(os.path.dirname(__file__), "cookiecutter") diff --git a/playbooks/ensure-lxd.yaml b/playbooks/ensure-lxd.yaml index 29c439c..5bfbcb5 100644 --- a/playbooks/ensure-lxd.yaml +++ b/playbooks/ensure-lxd.yaml @@ -2,7 +2,7 @@ tasks: - name: Install LXD as a snap - shell: snap install lxd + command: snap install lxd register: _snap_install_result changed_when: not(_snap_install_result.stderr is search('already installed')) @@ -43,8 +43,11 @@ copy: content: "{{ _lxd_preseed_config | to_nice_yaml }}" dest: /tmp/lxd-preseed.yml + mode: 0600 register: _lxd_preseed_file_result - name: Configure LXD with preseed file - shell: cat /tmp/lxd-preseed.yml | lxd init --preseed + shell: | + set -euo pipefail + cat /tmp/lxd-preseed.yml | lxd init --preseed when: _lxd_preseed_file_result is changed diff --git a/pytest.ini b/pytest.ini index d802ca3..b464482 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,5 @@ [pytest] -addopts = -v -rxXs --doctest-modules --durations 10 --cov=molecule_* --cov-report term-missing:skip-covered --cov-report xml +addopts = -v -rxXs --doctest-modules --durations 10 doctest_optionflags = ALLOW_UNICODE ELLIPSIS junit_suite_name = molecule_test_suite norecursedirs = dist doc build .tox .eggs test/scenarios test/resources diff --git a/setup.cfg b/setup.cfg index bf7f660..12136fd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,6 @@ [aliases] dists = clean --all sdist bdist_wheel -[bdist_wheel] -universal = 1 - [metadata] name = molecule-lxd url = https://github.com/ansible-community/molecule-lxd @@ -33,9 +30,10 @@ classifiers = Natural Language :: English Operating System :: OS Independent Programming Language :: Python :: 3 - Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 Topic :: System :: Systems Administration Topic :: Utilities @@ -62,25 +60,12 @@ setup_requires = # These are required in actual runtime: install_requires = - ansible - molecule >= 3.0.2 + molecule >= 3.2.0a0 pyyaml >= 5.1, < 6 [options.extras_require] test = - ansi2html # soft-dependency of pytest-html - flake8>=3.6.0, < 4 - - mock>=3.0.5, < 4 - pytest-cov>=2.7.1, < 3 - pytest-dependency - pytest-helpers-namespace>=2019.1.8, < 2020 - pytest-html - pytest-mock>=1.10.4, < 2 - pytest-plus - pytest-verbose-parametrize>=1.7.0, < 2 - pytest-xdist>=1.29.0, < 2 - pytest>=4.6.3 + molecule[test] [options.entry_points] molecule.driver = diff --git a/tox.ini b/tox.ini index 9fea38c..f85065b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,14 @@ # For more information about tox, see https://tox.readthedocs.io/en/latest/ [tox] -minversion = 3.9.0 +minversion = 3.18.0 envlist = - linters + lint packaging - py{36,37,38} - devel -skipsdist = True + py{36,37,38,39} + py{36,37,38,39}-{devel} + +# do not enable skip missing to avoid CI false positives +skip_missing_interpreters = False isolated_build = True [testenv] @@ -50,52 +52,47 @@ passenv = TWINE_* USER ZUUL* -whitelist_externals = +deps = + py{36,37,38,39}: molecule[test] + py{36,37,38,39}-{devel}: git+https://github.com/ansible-community/molecule.git@master#egg=molecule[test] +allowlist_externals = bash twine pytest pre-commit rm + sh +[testenv:lint] +description = Runs all linting tasks +commands = + # to run a single linter you can do "pre-commit run flake8" + python -m pre_commit run {posargs:--all} +deps = pre-commit>=1.18.1 +extras = +skip_install = true +usedevelop = false [testenv:packaging] +description = + Do packaging/distribution. If tag is not present or PEP440 compliant upload to + PYPI could fail +# `usedevelop = true` overrides `skip_install` instruction, it's unwanted usedevelop = false +# don't install molecule itself in this env skip_install = true deps = collective.checkdocs >= 0.2 - pep517 >= 0.5.0 - twine >= 2.0.0 + pep517 >= 0.8.2 + pip >= 20.2.2 + toml >= 0.10.1 + twine >= 3.2.0 # pyup: ignore +setenv = commands = - bash -c "rm -rf {toxinidir}/dist/ {toxinidir}/build/ && mkdir -p {toxinidir}/dist/" + rm -rfv {toxinidir}/dist/ python -m pep517.build \ --source \ --binary \ --out-dir {toxinidir}/dist/ \ {toxinidir} - twine check dist/* - -[testenv:devel] -description= Unit testing using master branches of molecule and ansible -extras = test -commands = - {[testenv]commands} -deps = - git+https://github.com/ansible/ansible.git#egg=ansible - git+https://github.com/ansible-community/molecule#egg=molecule - -[testenv:linters] -description = Performs linting, style checks -skip_install = true -sitepackages = false -deps = - pre-commit -commands = - pre-commit run -a - -[testenv:upload] -description = Builds the packages and uploads them to https://pypi.org -envdir={toxworkdir}/dist -deps= - {[testenv:packaging]deps} -commands = - {[testenv:packaging]commands} - twine upload --verbose dist/* + # metadata validation + sh -c "python -m twine check {toxinidir}/dist/*"