Skip to content

Commit 1a160ee

Browse files
committed
tests: add testing
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Update .github/workflows/ci.yml Update ci.yml chore: update to b3 Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent b2ce7de commit 1a160ee

11 files changed

Lines changed: 141 additions & 31 deletions

File tree

.github/workflows/cd.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CD
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types:
7+
- published
8+
9+
jobs:
10+
dist:
11+
name: Distribution build
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Build sdist and wheel
22+
run: pipx run build
23+
24+
- uses: actions/upload-artifact@v3
25+
with:
26+
path: dist
27+
28+
- name: Check products
29+
run: pipx run twine check dist/*
30+
31+
publish:
32+
name: Publish
33+
needs: [dist]
34+
environment:
35+
name: pypi
36+
url: https://pypi.org/p/sp-repo-review
37+
permissions:
38+
id-token: write
39+
runs-on: ubuntu-latest
40+
if: github.event_name == 'release' && github.event.action == 'published'
41+
steps:
42+
- uses: actions/download-artifact@v3
43+
with:
44+
name: artifact
45+
path: dist
46+
47+
- uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ jobs:
1717

1818
cookie:
1919
needs: change-detection
20-
if: fromJSON(needs.change-detection.outputs.run-tests)
20+
if: fromJSON(needs.change-detection.outputs.run-cookie)
2121
uses: ./.github/workflows/reusable-cookie.yml
2222

23+
rr-tests:
24+
needs: change-detection
25+
if: fromJSON(needs.change-detection.outputs.run-rr)
26+
uses: ./.github/workflows/reusable-rr-tests.yml
27+
2328
pass:
2429
if: always()
2530
needs:
2631
- change-detection
2732
- cookie
33+
- rr-tests
2834
runs-on: ubuntu-latest
2935

3036
steps:
@@ -33,10 +39,16 @@ jobs:
3339
with:
3440
allowed-skips: >-
3541
${{
36-
fromJSON(needs.change-detection.outputs.run-tests)
42+
fromJSON(needs.change-detection.outputs.run-cookie)
3743
&& ''
3844
|| '
3945
cookie,
4046
'
47+
}} ${{
48+
fromJSON(needs.change-detection.outputs.run-rr)
49+
&& ''
50+
|| '
51+
rr-tests,
52+
'
4153
}}
4254
jobs: ${{ toJSON(needs) }}

.github/workflows/reusable-change-detection.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@ name: Change detection
22
on:
33
workflow_call:
44
outputs:
5-
run-tests:
5+
run-cookie:
66
description: Whether or not run the cookiecutter tests
7-
value: ${{ jobs.change-detection.outputs.run-tests || false }}
7+
value: ${{ jobs.change-detection.outputs.run-cookie || false }}
8+
run-rr:
9+
description: Whether or not run the repo-review tests
10+
value: ${{ jobs.change-detection.outputs.run-cookie || false }}
811

912
jobs:
1013
change-detection:
1114
name: Identify source changes
1215
runs-on: ubuntu-latest
1316
timeout-minutes: 1
1417
outputs:
15-
run-tests: ${{ steps.tests-changes.outputs.run-tests || false }}
18+
run-cookie: ${{ steps.cookie-changes.outputs.run-cookie || false }}
19+
run-rr: ${{ steps.rr-changes.outputs.run-rr || false }}
1620
steps:
1721
- uses: actions/checkout@v3
1822

1923
- name: Get a list of the changed runtime-related files
2024
if: github.event_name == 'pull_request'
21-
id: changed-testable-files
25+
id: changed-cookie-files
2226
uses: Ana06/get-changed-files@v2.2.0
2327
with:
2428
filter: |
@@ -31,6 +35,25 @@ jobs:
3135
- name: Set a flag for running the tests
3236
if: >-
3337
github.event_name != 'pull_request' ||
34-
steps.changed-testable-files.outputs.added_modified_renamed != ''
35-
id: tests-changes
36-
run: echo "run-tests=true" >> "${GITHUB_OUTPUT}"
38+
steps.changed-cookie-files.outputs.added_modified_renamed != ''
39+
id: cookie-changes
40+
run: echo "run-cookie=true" >> "${GITHUB_OUTPUT}"
41+
42+
- name: Get a list of the changed runtime-related files
43+
if: github.event_name == 'pull_request'
44+
id: changed-rr-files
45+
uses: Ana06/get-changed-files@v2.2.0
46+
with:
47+
filter: |
48+
tests/**
49+
.github/workflows/ci.yml
50+
.github/workflows/reusable-rr-tests.yml
51+
noxfile.py
52+
src/**
53+
pyproject.toml
54+
- name: Set a flag for running the tests
55+
if: >-
56+
github.event_name != 'pull_request' ||
57+
steps.changed-rr-files.outputs.added_modified_renamed != ''
58+
id: rr-changes
59+
run: echo "run-rr=true" >> "${GITHUB_OUTPUT}"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: RR
2+
3+
on:
4+
workflow_call:
5+
6+
env:
7+
FORCE_COLOR: 3
8+
9+
jobs:
10+
checks:
11+
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
12+
runs-on: ${{ matrix.runs-on }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python-version: ["3.10", "3.11", "3.12-dev"]
17+
runs-on: [ubuntu-latest, macos-latest, windows-latest]
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
- uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install package
27+
run: python -m pip install .[test,cli]
28+
29+
- name: Test package
30+
run: python -m pytest -ra
31+
env:
32+
PYTHONUTF8: "1"

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ repos:
5050
hooks:
5151
- id: mypy
5252
files: "(src|web|tests)"
53-
args:
53+
args: []
54+
additional_dependencies:
5455
- click
5556
- markdown-it-py
5657
- pytest
5758
- repo-review
5859
- rich
5960
- tomli
6061
- types-PyYAML
61-
additional_dependencies:
6262

6363
- repo: https://github.com/pre-commit/mirrors-prettier
6464
rev: "v2.7.1"

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ classifiers = [
2929
dynamic = ["version"]
3030
dependencies = [
3131
"pyyaml",
32-
"repo-review",
32+
"repo-review>=0.7.0b3,<0.8",
3333
]
3434

3535
[project.optional-dependencies]
3636
cli = [
37-
"click>=8",
38-
"rich>=12.2",
37+
"repo-review[cli]",
3938
]
4039
test = [
4140
"pytest >=7",

src/sp_repo_review/checks/general.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class PY002(General):
2626
"Has a README.(md|rst) file"
2727

2828
@staticmethod
29-
def check(package: Traversable) -> bool:
29+
def check(root: Traversable) -> bool:
3030
"Projects must have a readme file"
3131
return (
32-
package.joinpath("README.md").is_file()
33-
or package.joinpath("README.rst").is_file()
32+
root.joinpath("README.md").is_file()
33+
or root.joinpath("README.rst").is_file()
3434
)
3535

3636

@@ -65,22 +65,21 @@ class PY006(General):
6565
"Has pre-commit config"
6666

6767
@staticmethod
68-
def check(package: Traversable) -> bool:
68+
def check(root: Traversable) -> bool:
6969
"Projects must have a `.pre-commit-config.yaml` file"
70-
return package.joinpath(".pre-commit-config.yaml").is_file()
70+
return root.joinpath(".pre-commit-config.yaml").is_file()
7171

7272

7373
class PY007(General):
7474
"Supports an easy task runner (nox or tox)"
7575

7676
@staticmethod
77-
def check(package: Traversable) -> bool:
77+
def check(root: Traversable) -> bool:
7878
"""
7979
Projects must have a `noxfile.py` or `tox.ini` to encourage new contributors.
8080
"""
8181
return (
82-
package.joinpath("noxfile.py").is_file()
83-
or package.joinpath("tox.ini").is_file()
82+
root.joinpath("noxfile.py").is_file() or root.joinpath("tox.ini").is_file()
8483
)
8584

8685

src/sp_repo_review/checks/github.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from .._compat.importlib.resources.abc import Traversable
1212

1313

14-
def workflows(package: Traversable) -> dict[str, Any]:
15-
workflows_base_path = package.joinpath(".github/workflows")
14+
def workflows(root: Traversable) -> dict[str, Any]:
15+
workflows_base_path = root.joinpath(".github/workflows")
1616
workflows_dict: dict[str, Any] = {}
1717
if workflows_base_path.is_dir():
1818
for workflow_path in workflows_base_path.iterdir():
@@ -23,8 +23,8 @@ def workflows(package: Traversable) -> dict[str, Any]:
2323
return workflows_dict
2424

2525

26-
def dependabot(package: Traversable) -> dict[str, Any]:
27-
dependabot_path = package.joinpath(".github/dependabot.yml")
26+
def dependabot(root: Traversable) -> dict[str, Any]:
27+
dependabot_path = root.joinpath(".github/dependabot.yml")
2828
if dependabot_path.is_file():
2929
with dependabot_path.open("rb") as f:
3030
result: dict[str, Any] = yaml.safe_load(f)

src/sp_repo_review/checks/precommit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from .._compat.importlib.resources.abc import Traversable
1111

1212

13-
def precommit(package: Traversable) -> dict[str, Any]:
14-
precommit_path = package.joinpath(".pre-commit-config.yaml")
13+
def precommit(root: Traversable) -> dict[str, Any]:
14+
precommit_path = root.joinpath(".pre-commit-config.yaml")
1515
if precommit_path.is_file():
1616
with precommit_path.open("rb") as f:
1717
return yaml.safe_load(f) # type: ignore[no-any-return]
@@ -29,7 +29,7 @@ class PreCommit:
2929

3030
@classmethod
3131
def check(cls: type[PreCommitMixin], precommit: dict[str, Any]) -> bool | None:
32-
"Must have `{cls.repo}` repo in `.pre-commit-config.yaml`"
32+
"Must have `{self.repo}` repo in `.pre-commit-config.yaml`"
3333
for repo in precommit.get("repos", {}):
3434
if "repo" in repo and repo["repo"].lower() == cls.repo:
3535
return True

src/sp_repo_review/families.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import importlib.metadata
43
import typing
54

65
__all__ = ["Family", "get_familes"]

0 commit comments

Comments
 (0)