Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SonarCloud config and GitHub actions #14

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
- { python-version: "3.11", os: macos-latest }
- { python-version: "3.10", os: ubuntu-latest }
- { python-version: "3.9", os: ubuntu-latest }
- { python-version: "3.8", os: ubuntu-latest }
name: Python ${{ matrix.python-version }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
steps:
Expand Down
16 changes: 11 additions & 5 deletions {{cookiecutter.project_name}}/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Tests

on:
- push
- pull_request
on: [push, pull_request]

jobs:
tests:
Expand All @@ -17,11 +15,9 @@ jobs:
- { python: "3.11", os: "ubuntu-latest", session: "mypy" }
- { python: "3.10", os: "ubuntu-latest", session: "mypy" }
- { python: "3.9", os: "ubuntu-latest", session: "mypy" }
- { python: "3.8", os: "ubuntu-latest", session: "mypy" }
- { python: "3.11", os: "ubuntu-latest", session: "tests" }
- { python: "3.10", os: "ubuntu-latest", session: "tests" }
- { python: "3.9", os: "ubuntu-latest", session: "tests" }
- { python: "3.8", os: "ubuntu-latest", session: "tests" }
- { python: "3.11", os: "windows-latest", session: "tests" }
- { python: "3.11", os: "macos-latest", session: "tests" }
- { python: "3.11", os: "ubuntu-latest", session: "typeguard" }
Expand Down Expand Up @@ -116,6 +112,8 @@ jobs:
steps:
- name: Check out the repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up Python
uses: actions/[email protected]
Expand Down Expand Up @@ -153,3 +151,11 @@ jobs:

- name: Upload coverage report
uses: codecov/[email protected]

- name: SonarCloud Scan
env:
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }} # Needed to get PR information, if any
SONAR_TOKEN: {{ "${{ secrets.SONAR_TOKEN }}" }}
# No need to run SonarCloud analysis if dependabot update or token not defined
if: env.SONAR_TOKEN != '' && (github.actor != 'dependabot[bot]')
uses: SonarSource/[email protected]
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Request features on the [Issue Tracker].

## How to set up your development environment

You need Python 3.8+ and the following tools:
You need Python 3.9+ and the following tools:

- [Poetry]
- [Nox]
Expand Down
29 changes: 19 additions & 10 deletions {{cookiecutter.project_name}}/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
raise SystemExit(dedent(message)) from None

package = "{{cookiecutter.package_name}}"
python_versions = ["3.11", "3.10", "3.9", "3.8"]
python_versions = ["3.11", "3.10", "3.9"]
nox.needs_version = ">= 2021.6.6"
nox.options.sessions = (
"pre-commit",
Expand Down Expand Up @@ -94,19 +94,28 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None:

text = hook.read_text()

if not any(
Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text
for bindir in bindirs
):
if not is_bindir_in_text(bindirs, text):
continue

lines = text.splitlines()
hook.write_text(insert_header_in_hook(headers, lines))

for executable, header in headers.items():
if executable in lines[0].lower():
lines.insert(1, dedent(header))
hook.write_text("\n".join(lines))
break

def is_bindir_in_text(bindirs: list[str], text: str) -> bool:
"""Helper function to check if bindir is in text."""
return any(
Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text
for bindir in bindirs
)


def insert_header_in_hook(header: dict[str, str], lines: list[str]) -> str:
"""Helper function to insert headers in hook's text."""
for executable, header_text in header.items():
if executable in lines[0].lower():
lines.insert(1, dedent(header_text))
return "\n".join(lines)
return "\n".join(lines)


@session(name="pre-commit", python=python_versions[0])
Expand Down
Loading