From f0fc7c929db4870e68cf7ec003b259e3e7d6b94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Wed, 6 Sep 2023 21:01:06 -0600 Subject: [PATCH] chore: Setup CI (#1) --- .github/dependabot.yaml | 36 ++++++++ .github/semantic.yml | 2 + .github/workflows/constraints.txt | 1 + .github/workflows/release.yaml | 51 +++++++++++ .github/workflows/test.yaml | 135 ++++++++++++++++++++++++++++++ pyproject.toml | 15 +++- src/pep610/__init__.py | 2 +- 7 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 .github/dependabot.yaml create mode 100644 .github/semantic.yml create mode 100644 .github/workflows/constraints.txt create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..ba91cd6 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,36 @@ +version: 2 +updates: + - directory: / + package-ecosystem: pip + schedule: + interval: weekly + timezone: America/Mexico_City + assignees: + - "edgarrmondragon" + reviewers: + - "edgarrmondragon" + commit-message: + prefix: "chore(deps): " + prefix-development: "chore(deps-dev): " + - package-ecosystem: pip + directory: /.github/workflows + schedule: + interval: monthly + timezone: America/Mexico_City + assignees: + - "edgarrmondragon" + reviewers: + - "edgarrmondragon" + commit-message: + prefix: "ci: " + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: monthly + timezone: America/Mexico_City + assignees: + - "edgarrmondragon" + reviewers: + - "edgarrmondragon" + commit-message: + prefix: "ci: " diff --git a/.github/semantic.yml b/.github/semantic.yml new file mode 100644 index 0000000..b5161df --- /dev/null +++ b/.github/semantic.yml @@ -0,0 +1,2 @@ +enabled: true +titleOnly: true diff --git a/.github/workflows/constraints.txt b/.github/workflows/constraints.txt new file mode 100644 index 0000000..1e4cbe9 --- /dev/null +++ b/.github/workflows/constraints.txt @@ -0,0 +1 @@ +hatch==1.7.0 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..83b9c93 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,51 @@ +name: Publish to PyPI + +on: + release: + types: [published] + +permissions: + contents: write + id-token: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.8 + - name: Install dependencies + env: + PIP_CONSTRAINT: .github/workflows/constraints.txt + run: | + pipx install hatch + - name: Build + run: | + hatch build + - uses: actions/upload-artifact@v3 + with: + name: dist + path: dist + + upload: + runs-on: ubuntu-latest + needs: build + environment: publish + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: dist + path: dist + - name: Upload wheel to release + uses: svenstaro/upload-release-action@v2 + with: + file: dist/*.whl + tag: ${{ github.ref }} + overwrite: true + file_glob: true + + - name: Publish + uses: pypa/gh-action-pypi-publish@v1.8.10 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..3619d33 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,135 @@ +name: Test + +on: + push: + branches: [ main ] + paths: + - src/** + - tests/** + - pyproject.toml + - .github/workflows/test.yml + - .github/workflows/constraints.txt + pull_request: + branches: [ main ] + paths: + - src/** + - tests/** + - pyproject.toml + - .github/workflows/test.yml + - .github/workflows/constraints.txt + workflow_dispatch: {} + schedule: + # Run every 27 hours to avoid running at the same time every day + - cron: "40 12 * * 1-5" + +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + cache: pip + python-version: "3.11" + - name: Install dependencies + env: + PIP_CONSTRAINT: .github/workflows/constraints.txt + run: | + pipx install hatch + - name: Run lint + env: + HATCH_ENV: lint + run: | + hatch run style + + typing: + name: Typing + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + cache: pip + python-version: "3.11" + - name: Install dependencies + env: + PIP_CONSTRAINT: .github/workflows/constraints.txt + run: | + pipx install hatch + - name: Run typing + env: + HATCH_ENV: lint + run: | + hatch run typing + + test: + name: Pytest (Python ${{ matrix.python-version }}, ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ["ubuntu-latest"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + include: + - python-version: "3.11" + os: "windows-latest" + + - python-version: "3.11" + os: "macos-latest" + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + cache: pip + python-version: ${{ matrix.python-version }} + allow-prereleases: true + - name: Install dependencies + env: + PIP_CONSTRAINT: .github/workflows/constraints.txt + run: | + pipx install hatch + - name: Run tests + env: + HATCH_ENV: "test.py${{ matrix.python-version }}" + run: | + hatch run cov + - uses: actions/upload-artifact@v3 + with: + name: coverage-data + path: ".coverage.*" + + coverage: + name: Coverage + runs-on: ubuntu-latest + needs: test + env: + PYTHON: "3.11" + HATCH_ENV: coverage + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON }} + - name: Install dependencies + env: + PIP_CONSTRAINT: .github/workflows/constraints.txt + run: | + pipx install hatch + - uses: actions/download-artifact@v3 + with: + name: coverage-data + - name: Combine coverage data + run: | + hatch run report + - name: Create coverage XML report + run: | + hatch run xml + - uses: codecov/codecov-action@v3 + with: + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml index 637113f..7f00b2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,16 +45,27 @@ source = "vcs" [tool.hatch.envs.test] dependencies = [ + "coverage[toml]>=6.5", "hypothesis", "hypothesis-jsonschema", "pytest", ] [tool.hatch.envs.test.scripts] -run = "pytest {args:tests}" +test = "pytest {args:tests}" +cov = "coverage run -m pytest {args:tests}" [[tool.hatch.envs.test.matrix]] python = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] +[tool.hatch.envs.coverage] +dependencies = [ + "coverage[toml]>=6.5", +] +[tool.hatch.envs.coverage.scripts] +json = "coverage json" +xml = "coverage xml" +report = ["coverage combine", "coverage report --show-missing"] + [tool.hatch.envs.lint] detached = true dependencies = [ @@ -63,7 +74,7 @@ dependencies = [ "hypothesis", "hypothesis-jsonschema", "pytest", - "ruff>=0.0.243", + "ruff>=0.0.287", ] [tool.hatch.envs.lint.scripts] typing = "mypy --install-types --non-interactive {args:src/pep610 tests}" diff --git a/src/pep610/__init__.py b/src/pep610/__init__.py index e30be72..da2e6dd 100644 --- a/src/pep610/__init__.py +++ b/src/pep610/__init__.py @@ -3,13 +3,13 @@ from __future__ import annotations import json -import sys import typing as t from dataclasses import dataclass from importlib.metadata import version from pathlib import Path if t.TYPE_CHECKING: + import sys from importlib.metadata import Distribution from os import PathLike