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

Reworks workflows to integrate release creation and trusted publishing in addition to testing and linting #35

Merged
merged 8 commits into from
Sep 24, 2024
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
32 changes: 32 additions & 0 deletions .editorconfig
Archmonger marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# EditorConfig: http://EditorConfig.org

root = true

[*]
indent_style = tab
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
max_line_length = 120

[{*.html,*.css,*.js}]
max_line_length = off

[*.py]
indent_size = 4
indent_style = space
Archmonger marked this conversation as resolved.
Show resolved Hide resolved

[*.{yml,yaml}]
indent_style = space
indent_size = 4

[*.{rst, md}]
indent_style = space

# Tests don't get a line width restriction. It's still a good idea to follow
# the 99 character rule, but in the interests of clarity, tests often need to
# violate it.
[**/test_*.py]
max_line_length = off
254 changes: 254 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
name: CI

on:
push:
pull_request:
branches:
- main

concurrency:
group: ci-${{ github.ref_name }}
cancel-in-progress: true

jobs:
code-lint:
name: Code Linting
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- name: Install Hatch
run: |
pip3 --quiet install --upgrade hatch uv
hatch --version
uv --version
- name: Lint project
run: |
hatch fmt --check
- name: Check files with pre-commit
uses: pre-commit/[email protected]

docs-lint:
name: Documentation Linting
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: 3.x
cache: pip
- name: Install dependecies
run: |
pip install --upgrade hatch uv
- name: Check documentation links
if: false
run: |
hatch run docs:linkcheck
- name: Check docs build
run: |
hatch run docs:build

tests:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs:
- code-lint

strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: pip

- name: Install dependencies
run: |
python -m pip install --upgrade pip hatch uv

- name: Show environment
run: |
hatch test --show --python ${{ matrix.python-version }}

- name: Run tests
run: |
hatch test --cover --python ${{ matrix.python-version }}
mv .coverage ".coverage.py${{ matrix.python-version }}"

- name: Upload coverage data
if: matrix.os != 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: "coverage-data-py${{ matrix.python-version }}"
path: ".coverage.py${{ matrix.python-version }}"
if-no-files-found: error
include-hidden-files: true
retention-days: 7

build:
name: Build Distributions
runs-on: ubuntu-latest
permissions:
contents: read
needs:
- code-lint
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- name: Install Hatch
run: |
pip3 --quiet install --upgrade hatch uv
hatch --version
uv --version
- name: Build release files
run: |
hatch build --clean
- uses: actions/upload-artifact@v4
with:
name: artifacts
path: dist/*
if-no-files-found: error
retention-days: 7

coverage:
name: Coverage
runs-on: ubuntu-latest
needs:
- tests
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: pip

- name: Install dependencies
run: python -m pip install --upgrade coverage[toml]

- name: Download data
uses: actions/download-artifact@v4
with:
merge-multiple: true

- name: Combine coverage and fail if it's <95%
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Around here would be a great place to integrate codecov if ever desired

run: |
python -m coverage combine
python -m coverage html --skip-covered --skip-empty
python -m coverage report --fail-under=95

- name: Upload HTML report
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov

docs-deploy:
name: Deploy Documentation
runs-on: ubuntu-latest
needs:
- docs-lint
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: 3.x
cache: pip
- name: Install dependecies
run: |
pip install --upgrade hatch uv
- name: Configure Git
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Publish Develop Docs
if: github.ref_name == 'main'
run: |
hatch run docs:deploy_develop
- name: Publish Develop Docs
if: startsWith(github.ref, 'refs/tags/')
run: |
hatch run docs:deploy_latest ${{ github.ref_name }}

create-release:
name: Create Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
needs:
- build
- tests
- docs-deploy
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: artifacts
path: dist
- name: Get latest release info
id: query-release-info
uses: release-flow/keep-a-changelog-action@v3
with:
command: query
version: ${{ github.ref_name }}
- name: Display release info
run: |
echo "Version: ${{ steps.query-release-info.outputs.version }}"
echo "Date: ${{ steps.query-release-info.outputs.release-date }}"
echo "${{ steps.query-release-info.outputs.release-notes }}"
- uses: ncipollo/release-action@v1
with:
artifacts: "dist/*.tar.gz,dist/*.whl"
body: ${{ steps.query-release-info.outputs.release-notes }}

pypi-publish:
name: Publish to PyPi
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
Archmonger marked this conversation as resolved.
Show resolved Hide resolved
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
needs:
- build
- tests
- docs-deploy
steps:
- uses: actions/download-artifact@v4
with:
name: artifacts
path: dist
- name: Publish build to PyPI
Archmonger marked this conversation as resolved.
Show resolved Hide resolved
uses: pypa/[email protected]
27 changes: 0 additions & 27 deletions .github/workflows/publish-develop-docs.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/publish-py.yml

This file was deleted.

27 changes: 0 additions & 27 deletions .github/workflows/publish-release-docs.yml

This file was deleted.

Loading