Skip to content

Commit

Permalink
Modernize codebase (#38)
Browse files Browse the repository at this point in the history
- Require python 3.9 or newer
- Adopt new PEP517 packaging
- Update linters
- rename lib/ to src/
  • Loading branch information
ssbarnea authored Sep 12, 2023
1 parent 9e7d41f commit 8d1ca81
Show file tree
Hide file tree
Showing 24 changed files with 483 additions and 452 deletions.
6 changes: 6 additions & 0 deletions .config/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
click-help-colors>=0.6
click>=8.1.4
enrich>=1.2.1
pygithub
pyyaml>=5.3.1
requests
10 changes: 10 additions & 0 deletions .github/workflows/ack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# See https://github.com/ansible/devtools/blob/main/.github/workflows/ack.yml
name: ack
"on":
pull_request_target:
types: [opened, labeled, unlabeled, synchronize]

jobs:
ack:
uses: ansible/devtools/.github/workflows/ack.yml@main
13 changes: 13 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# See https://github.com/ansible/devtools/blob/main/.github/workflows/push.yml
name: push
"on":
push:
branches:
- main
- "releases/**"
- "stable/**"

jobs:
ack:
uses: ansible/devtools/.github/workflows/push.yml@main
69 changes: 69 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
# cspell:ignore mislav
name: release

"on":
release:
types: [published]
workflow_dispatch:

jobs:
# https://github.com/marketplace/actions/actions-tagger
actions-tagger:
runs-on: windows-latest
steps:
- uses: Actions-R-Us/actions-tagger@latest
env:
GITHUB_TOKEN: "${{ github.token }}"
pypi:
name: Publish to PyPI registry
environment: release
runs-on: ubuntu-22.04
permissions:
id-token: write

env:
FORCE_COLOR: 1
PY_COLORS: 1
TOXENV: pkg

steps:
- name: Switch to using Python 3.9 by default
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install tox
run: python3 -m pip install --user "tox>=4.0.0"

- name: Check out src from Git
uses: actions/checkout@v4
with:
fetch-depth: 0 # needed by setuptools-scm
submodules: true

- name: Build dists
run: python -m tox

- name: Publish to pypi.org
if: >- # "create" workflows run separately from "push" & "pull_request"
github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1

homebrew:
name: Bump homebrew formula
environment: release
runs-on: ubuntu-22.04
needs: pypi

env:
FORCE_COLOR: 1
PY_COLORS: 1
TOXENV: pkg

steps:
- name: Check out src from Git
uses: actions/checkout@v4
with:
fetch-depth: 0 # needed by setuptools-scm
submodules: true
251 changes: 144 additions & 107 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -1,128 +1,165 @@
---
name: tox

on:
create: # is used for publishing to PyPI and 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"
tags-ignore:
- "**"
push: # only publishes pushes to the main branch to TestPyPI
branches: # any integration branch but not tag
- "main"
pull_request:
schedule:
- cron: 1 0 * * * # Run daily at 0:01 UTC
branches:
- "main"

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

env:
FORCE_COLOR: 1 # tox, pytest, ansible-lint
PY_COLORS: 1

jobs:
pre:
name: pre
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.generate_matrix.outputs.matrix }}
steps:
- name: Determine matrix
id: generate_matrix
uses: coactions/dynamic-matrix@v1
with:
min_python: "3.9"
max_python: "3.11"
other_names: |
lint
pkg
platforms: linux,macos
build:
name: ${{ matrix.tox_env }}
runs-on: ubuntu-latest
name: ${{ matrix.name }}
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
needs:
- pre
defaults:
run:
shell: ${{ matrix.shell || 'bash'}}
strategy:
fail-fast: false
matrix:
include:
- tox_env: lint
# - tox_env: docs
- tox_env: py36
PREFIX: PYTEST_REQPASS=0
- tox_env: py37
PREFIX: PYTEST_REQPASS=0
- tox_env: py38
PREFIX: PYTEST_REQPASS=0
- tox_env: packaging

matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
# max-parallel: 5
# The matrix testing goal is to cover the *most likely* environments
# which are expected to be used by users in production. Avoid adding a
# combination unless there are good reasons to test it, like having
# proof that we failed to catch a bug by not running it. Using
# distribution should be preferred instead of custom builds.
env:
# vars safe to be passed to wsl:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 0
steps:
- uses: actions/checkout@v1
- 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') }}

- uses: actions/checkout@v4
with:
fetch-depth: 0 # needed by setuptools-scm
submodules: true

- name: Set pre-commit cache
uses: actions/cache@v3
if: ${{ matrix.passed_name == 'lint' }}
with:
path: |
~/.cache/pre-commit
key: pre-commit-${{ matrix.name || matrix.passed_name }}-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set ansible cache(s)
uses: actions/cache@v3
with:
python-version: ${{ steps.py_ver.outputs.version }}
- name: Install dependencies
path: |
.cache/eco
examples/playbooks/collections/ansible_collections
~/.cache/ansible-compat
~/.ansible/collections
~/.ansible/roles
key: ${{ matrix.name || matrix.passed_name }}-${{ hashFiles('tools/test-eco.sh', 'requirements.yml', 'examples/playbooks/collections/requirements.yml') }}

- name: Set up Python ${{ matrix.python_version || '3.9' }}
uses: actions/setup-python@v4
with:
cache: pip
python-version: ${{ matrix.python_version || '3.9' }}

- name: Install tox
run: |
docker version
docker info
python -m pip install -U pip
pip install tox
- name: Run tox -e ${{ matrix.tox_env }}
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade "tox>=4.0.0"
- name: Log installed dists
run: python3 -m pip freeze --all

- name: Initialize tox envs ${{ matrix.passed_name }}
run: python3 -m tox --notest --skip-missing-interpreters false -vv -e ${{ matrix.passed_name }}
timeout-minutes: 5 # average is under 1, but macos can be over 3

# sequential run improves browsing experience (almost no speed impact)
- name: tox -e ${{ matrix.passed_name }}
run: python3 -m tox -e ${{ matrix.passed_name }}

# - name: Combine coverage data
# if: ${{ startsWith(matrix.passed_name, 'py') }}
# # produce a single .coverage file at repo root
# run: tox -e coverage

# - name: Upload coverage data
# if: ${{ startsWith(matrix.passed_name, 'py') }}
# uses: codecov/codecov-action@v3
# with:
# name: ${{ matrix.passed_name }}
# fail_ci_if_error: false # see https://github.com/codecov/codecov-action/issues/598
# token: ${{ secrets.CODECOV_TOKEN }}
# verbose: true # optional (default = false)

- name: Archive logs
uses: actions/upload-artifact@v3
with:
name: logs.zip
path: .tox/**/log/
# https://github.com/actions/upload-artifact/issues/123
continue-on-error: true

- name: Report failure if git reports dirty status
run: |
echo "${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}"
${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}
if [[ -n $(git status -s) ]]; then
# shellcheck disable=SC2016
echo -n '::error file=git-status::'
printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY"
exit 99
fi
# https://github.com/actions/toolkit/issues/193

check: # This job does nothing and is only used for the branch protection
if: always()
permissions:
pull-requests: write # allow codenotify to comment on pull-request

publish:
name: Publish to PyPI registry
needs:
- build
runs-on: ubuntu-latest

env:
PY_COLORS: 1
TOXENV: packaging
runs-on: ubuntu-latest

steps:
- name: Switch to using Python 3.6 by default
uses: actions/setup-python@v2
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
python-version: 3.6
- name: Install tox
run: python -m pip install --user tox
jobs: ${{ toJSON(needs) }}

- name: Check out src from Git
uses: actions/checkout@v2
with:
# Get shallow Git history (default) for tag creation 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'
) &&
1 || 0
}}
- name: Drop Git tags from HEAD for non-tag-create events
if: >-
github.event_name != 'create' ||
github.event.ref_type != 'tag'
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 == 'create' &&
github.event.ref_type == 'tag'
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
uses: actions/checkout@v4

- name: Notify repository owners about lint change affecting them
uses: sourcegraph/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/sourcegraph/codenotify/issues/19
continue-on-error: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ pip-wheel-metadata
credentials.json

pip-wheel-metadata
src/gri/_version.py
report.html
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

Loading

0 comments on commit 8d1ca81

Please sign in to comment.