-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(.github): revamp workflows and add hatch
Improve the GitHub action workflows and start to use hatch and hatchling as build backend.
- Loading branch information
1 parent
5b9cb59
commit 9154d5b
Showing
14 changed files
with
335 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
- 'ci/improve-ci' | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
env: | ||
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | ||
|
||
jobs: | ||
test: | ||
if: false | ||
name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Hatch | ||
run: pip install --upgrade hatch | ||
|
||
- name: Run tests and track code coverage | ||
run: hatch run test:cov | ||
|
||
# TODO: Enforce quality, security and style checks. | ||
|
||
bump_and_build: | ||
# needs: test | ||
name: Bump and Build version [${{ github.head_ref || github.ref_name }}] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade hatch | ||
- name: Generate SLUG | ||
id: generate_slug | ||
run: | | ||
SLUG=$(echo "$BRANCH_NAME" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z) | ||
echo "SLUG=$SLUG" >> $GITHUB_OUTPUT | ||
# Bump for dev versions | ||
- name: Bump version | ||
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/ci/improve-ci' | ||
run: hatch run dev-bump $GITHUB_RUN_NUMBER | ||
continue-on-error: true | ||
|
||
- name: Local bump | ||
if: github.ref != 'refs/heads/main' | ||
run: hatch run local-bump $(hatch version)+${{ steps.generate_slug.outputs.SLUG }} | ||
|
||
- name: Build package | ||
run: hatch build | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: "dist-${{ steps.generate_slug.outputs.SLUG }}" | ||
path: dist/* | ||
if-no-files-found: error | ||
retention-days: 7 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: PyPi Release | ||
|
||
on: | ||
workflow_run: | ||
workflows: [CI] | ||
branches: [production] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
pypi-publish: | ||
name: upload release to PyPI | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
environment: release | ||
permissions: | ||
id-token: write | ||
steps: | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: dist-main | ||
path: dist | ||
- name: Publish package distributions to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
print-hash: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
repos: | ||
- hooks: | ||
- id: commitizen | ||
- id: commitizen-branch | ||
stages: | ||
- push | ||
repo: https://github.com/commitizen-tools/commitizen | ||
rev: v3.12.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
import sys | ||
import pytest | ||
|
||
|
||
def pytest_collection_modifyitems(items, config): | ||
for item in items: | ||
if not any(item.iter_markers()): | ||
item.add_marker("basic") | ||
|
||
markexpr = config.getoption("markexpr", 'False') | ||
|
||
expr = "basic" | ||
|
||
if markexpr: | ||
expr += f" or ({markexpr})" | ||
|
||
config.option.markexpr = expr | ||
|
||
|
||
def pytest_deselected(items): | ||
if not items: | ||
return | ||
config = items[0].session.config | ||
config.deselected = items | ||
|
||
|
||
def pytest_terminal_summary(terminalreporter, exitstatus, config): | ||
reports = terminalreporter.getreports('') | ||
content = os.linesep.join(text for report in reports for secname, text in report.sections) | ||
deselected = getattr(config, "deselected", []) | ||
if deselected: | ||
terminalreporter.ensure_newline() | ||
terminalreporter.section('Deselected tests', sep='-', yellow=True, bold=True) | ||
content = os.linesep.join(item.nodeid for item in deselected) | ||
terminalreporter.line(content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.