Skip to content

Commit 8d1ca81

Browse files
authored
Modernize codebase (#38)
- Require python 3.9 or newer - Adopt new PEP517 packaging - Update linters - rename lib/ to src/
1 parent 9e7d41f commit 8d1ca81

24 files changed

+483
-452
lines changed

.config/requirements.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
click-help-colors>=0.6
2+
click>=8.1.4
3+
enrich>=1.2.1
4+
pygithub
5+
pyyaml>=5.3.1
6+
requests

.github/workflows/ack.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
# See https://github.com/ansible/devtools/blob/main/.github/workflows/ack.yml
3+
name: ack
4+
"on":
5+
pull_request_target:
6+
types: [opened, labeled, unlabeled, synchronize]
7+
8+
jobs:
9+
ack:
10+
uses: ansible/devtools/.github/workflows/ack.yml@main

.github/workflows/push.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
# See https://github.com/ansible/devtools/blob/main/.github/workflows/push.yml
3+
name: push
4+
"on":
5+
push:
6+
branches:
7+
- main
8+
- "releases/**"
9+
- "stable/**"
10+
11+
jobs:
12+
ack:
13+
uses: ansible/devtools/.github/workflows/push.yml@main

.github/workflows/release.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
# cspell:ignore mislav
3+
name: release
4+
5+
"on":
6+
release:
7+
types: [published]
8+
workflow_dispatch:
9+
10+
jobs:
11+
# https://github.com/marketplace/actions/actions-tagger
12+
actions-tagger:
13+
runs-on: windows-latest
14+
steps:
15+
- uses: Actions-R-Us/actions-tagger@latest
16+
env:
17+
GITHUB_TOKEN: "${{ github.token }}"
18+
pypi:
19+
name: Publish to PyPI registry
20+
environment: release
21+
runs-on: ubuntu-22.04
22+
permissions:
23+
id-token: write
24+
25+
env:
26+
FORCE_COLOR: 1
27+
PY_COLORS: 1
28+
TOXENV: pkg
29+
30+
steps:
31+
- name: Switch to using Python 3.9 by default
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: 3.9
35+
36+
- name: Install tox
37+
run: python3 -m pip install --user "tox>=4.0.0"
38+
39+
- name: Check out src from Git
40+
uses: actions/checkout@v4
41+
with:
42+
fetch-depth: 0 # needed by setuptools-scm
43+
submodules: true
44+
45+
- name: Build dists
46+
run: python -m tox
47+
48+
- name: Publish to pypi.org
49+
if: >- # "create" workflows run separately from "push" & "pull_request"
50+
github.event_name == 'release'
51+
uses: pypa/gh-action-pypi-publish@release/v1
52+
53+
homebrew:
54+
name: Bump homebrew formula
55+
environment: release
56+
runs-on: ubuntu-22.04
57+
needs: pypi
58+
59+
env:
60+
FORCE_COLOR: 1
61+
PY_COLORS: 1
62+
TOXENV: pkg
63+
64+
steps:
65+
- name: Check out src from Git
66+
uses: actions/checkout@v4
67+
with:
68+
fetch-depth: 0 # needed by setuptools-scm
69+
submodules: true

.github/workflows/tox.yml

Lines changed: 144 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,165 @@
1+
---
12
name: tox
23

34
on:
4-
create: # is used for publishing to PyPI and TestPyPI
5-
tags: # any tag regardless of its name, no branches
6-
push: # only publishes pushes to the main branch to TestPyPI
7-
branches: # any integration branch but not tag
8-
- "master"
9-
tags-ignore:
10-
- "**"
5+
push: # only publishes pushes to the main branch to TestPyPI
6+
branches: # any integration branch but not tag
7+
- "main"
118
pull_request:
12-
schedule:
13-
- cron: 1 0 * * * # Run daily at 0:01 UTC
9+
branches:
10+
- "main"
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
14+
cancel-in-progress: true
15+
16+
env:
17+
FORCE_COLOR: 1 # tox, pytest, ansible-lint
18+
PY_COLORS: 1
1419

1520
jobs:
21+
pre:
22+
name: pre
23+
runs-on: ubuntu-22.04
24+
outputs:
25+
matrix: ${{ steps.generate_matrix.outputs.matrix }}
26+
steps:
27+
- name: Determine matrix
28+
id: generate_matrix
29+
uses: coactions/dynamic-matrix@v1
30+
with:
31+
min_python: "3.9"
32+
max_python: "3.11"
33+
other_names: |
34+
lint
35+
pkg
36+
37+
platforms: linux,macos
1638
build:
17-
name: ${{ matrix.tox_env }}
18-
runs-on: ubuntu-latest
39+
name: ${{ matrix.name }}
40+
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
41+
needs:
42+
- pre
43+
defaults:
44+
run:
45+
shell: ${{ matrix.shell || 'bash'}}
1946
strategy:
2047
fail-fast: false
21-
matrix:
22-
include:
23-
- tox_env: lint
24-
# - tox_env: docs
25-
- tox_env: py36
26-
PREFIX: PYTEST_REQPASS=0
27-
- tox_env: py37
28-
PREFIX: PYTEST_REQPASS=0
29-
- tox_env: py38
30-
PREFIX: PYTEST_REQPASS=0
31-
- tox_env: packaging
32-
48+
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
49+
# max-parallel: 5
50+
# The matrix testing goal is to cover the *most likely* environments
51+
# which are expected to be used by users in production. Avoid adding a
52+
# combination unless there are good reasons to test it, like having
53+
# proof that we failed to catch a bug by not running it. Using
54+
# distribution should be preferred instead of custom builds.
55+
env:
56+
# vars safe to be passed to wsl:
57+
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
58+
# Number of expected test passes, safety measure for accidental skip of
59+
# tests. Update value if you add/remove tests.
60+
PYTEST_REQPASS: 0
3361
steps:
34-
- uses: actions/checkout@v1
35-
- name: Find python version
36-
id: py_ver
37-
shell: python
38-
if: ${{ contains(matrix.tox_env, 'py') }}
39-
run: |
40-
v = '${{ matrix.tox_env }}'.split('-')[0].lstrip('py')
41-
print('::set-output name=version::{0}.{1}'.format(v[0],v[1:]))
42-
# Even our lint and other envs need access to tox
43-
- name: Install a default Python
44-
uses: actions/setup-python@v2
45-
if: ${{ ! contains(matrix.tox_env, 'py') }}
46-
# Be sure to install the version of python needed by a specific test, if necessary
47-
- name: Set up Python version
48-
uses: actions/setup-python@v2
49-
if: ${{ contains(matrix.tox_env, 'py') }}
62+
63+
- uses: actions/checkout@v4
64+
with:
65+
fetch-depth: 0 # needed by setuptools-scm
66+
submodules: true
67+
68+
- name: Set pre-commit cache
69+
uses: actions/cache@v3
70+
if: ${{ matrix.passed_name == 'lint' }}
71+
with:
72+
path: |
73+
~/.cache/pre-commit
74+
key: pre-commit-${{ matrix.name || matrix.passed_name }}-${{ hashFiles('.pre-commit-config.yaml') }}
75+
76+
- name: Set ansible cache(s)
77+
uses: actions/cache@v3
5078
with:
51-
python-version: ${{ steps.py_ver.outputs.version }}
52-
- name: Install dependencies
79+
path: |
80+
.cache/eco
81+
examples/playbooks/collections/ansible_collections
82+
~/.cache/ansible-compat
83+
~/.ansible/collections
84+
~/.ansible/roles
85+
key: ${{ matrix.name || matrix.passed_name }}-${{ hashFiles('tools/test-eco.sh', 'requirements.yml', 'examples/playbooks/collections/requirements.yml') }}
86+
87+
- name: Set up Python ${{ matrix.python_version || '3.9' }}
88+
uses: actions/setup-python@v4
89+
with:
90+
cache: pip
91+
python-version: ${{ matrix.python_version || '3.9' }}
92+
93+
- name: Install tox
5394
run: |
54-
docker version
55-
docker info
56-
python -m pip install -U pip
57-
pip install tox
58-
- name: Run tox -e ${{ matrix.tox_env }}
95+
python3 -m pip install --upgrade pip
96+
python3 -m pip install --upgrade "tox>=4.0.0"
97+
98+
- name: Log installed dists
99+
run: python3 -m pip freeze --all
100+
101+
- name: Initialize tox envs ${{ matrix.passed_name }}
102+
run: python3 -m tox --notest --skip-missing-interpreters false -vv -e ${{ matrix.passed_name }}
103+
timeout-minutes: 5 # average is under 1, but macos can be over 3
104+
105+
# sequential run improves browsing experience (almost no speed impact)
106+
- name: tox -e ${{ matrix.passed_name }}
107+
run: python3 -m tox -e ${{ matrix.passed_name }}
108+
109+
# - name: Combine coverage data
110+
# if: ${{ startsWith(matrix.passed_name, 'py') }}
111+
# # produce a single .coverage file at repo root
112+
# run: tox -e coverage
113+
114+
# - name: Upload coverage data
115+
# if: ${{ startsWith(matrix.passed_name, 'py') }}
116+
# uses: codecov/codecov-action@v3
117+
# with:
118+
# name: ${{ matrix.passed_name }}
119+
# fail_ci_if_error: false # see https://github.com/codecov/codecov-action/issues/598
120+
# token: ${{ secrets.CODECOV_TOKEN }}
121+
# verbose: true # optional (default = false)
122+
123+
- name: Archive logs
124+
uses: actions/upload-artifact@v3
125+
with:
126+
name: logs.zip
127+
path: .tox/**/log/
128+
# https://github.com/actions/upload-artifact/issues/123
129+
continue-on-error: true
130+
131+
- name: Report failure if git reports dirty status
59132
run: |
60-
echo "${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}"
61-
${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}
133+
if [[ -n $(git status -s) ]]; then
134+
# shellcheck disable=SC2016
135+
echo -n '::error file=git-status::'
136+
printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY"
137+
exit 99
138+
fi
139+
# https://github.com/actions/toolkit/issues/193
140+
141+
check: # This job does nothing and is only used for the branch protection
142+
if: always()
143+
permissions:
144+
pull-requests: write # allow codenotify to comment on pull-request
62145

63-
publish:
64-
name: Publish to PyPI registry
65146
needs:
66147
- build
67-
runs-on: ubuntu-latest
68148

69-
env:
70-
PY_COLORS: 1
71-
TOXENV: packaging
149+
runs-on: ubuntu-latest
72150

73151
steps:
74-
- name: Switch to using Python 3.6 by default
75-
uses: actions/setup-python@v2
152+
- name: Decide whether the needed jobs succeeded or failed
153+
uses: re-actors/alls-green@release/v1
76154
with:
77-
python-version: 3.6
78-
- name: Install tox
79-
run: python -m pip install --user tox
155+
jobs: ${{ toJSON(needs) }}
156+
80157
- name: Check out src from Git
81-
uses: actions/checkout@v2
82-
with:
83-
# Get shallow Git history (default) for tag creation events
84-
# but have a complete clone for any other workflows.
85-
# Both options fetch tags but since we're going to remove
86-
# one from HEAD in non-create-tag workflows, we need full
87-
# history for them.
88-
fetch-depth: >-
89-
${{
90-
(
91-
github.event_name == 'create' &&
92-
github.event.ref_type == 'tag'
93-
) &&
94-
1 || 0
95-
}}
96-
- name: Drop Git tags from HEAD for non-tag-create events
97-
if: >-
98-
github.event_name != 'create' ||
99-
github.event.ref_type != 'tag'
100-
run: >-
101-
git tag --points-at HEAD
102-
|
103-
xargs git tag --delete
104-
- name: Build dists
105-
run: python -m tox
106-
- name: Publish to test.pypi.org
107-
if: >-
108-
(
109-
github.event_name == 'push' &&
110-
github.ref == format(
111-
'refs/heads/{0}', github.event.repository.default_branch
112-
)
113-
) ||
114-
(
115-
github.event_name == 'create' &&
116-
github.event.ref_type == 'tag'
117-
)
118-
uses: pypa/gh-action-pypi-publish@master
119-
with:
120-
password: ${{ secrets.testpypi_password }}
121-
repository_url: https://test.pypi.org/legacy/
122-
- name: Publish to pypi.org
123-
if: >- # "create" workflows run separately from "push" & "pull_request"
124-
github.event_name == 'create' &&
125-
github.event.ref_type == 'tag'
126-
uses: pypa/gh-action-pypi-publish@master
127-
with:
128-
password: ${{ secrets.pypi_password }}
158+
uses: actions/checkout@v4
159+
160+
- name: Notify repository owners about lint change affecting them
161+
uses: sourcegraph/codenotify@v0.6.4
162+
env:
163+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+
# https://github.com/sourcegraph/codenotify/issues/19
165+
continue-on-error: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ pip-wheel-metadata
3030
credentials.json
3131

3232
pip-wheel-metadata
33+
src/gri/_version.py
34+
report.html

.isort.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)