Skip to content

Commit

Permalink
chore: improve CI
Browse files Browse the repository at this point in the history
Release-As: 0.1.1
  • Loading branch information
lnqs committed Sep 25, 2024
1 parent 944a3d1 commit e751714
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 31 deletions.
50 changes: 50 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build distribution
description: Builds the distribution

inputs:
use-scm-version:
description: Overwrite package version from SCM information
default: 'false'
required: false

runs:
using: composite
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install poetry
shell: bash
run: python3 -m pip install poetry

- name: Install tools
shell: bash
if: ${{ inputs.use-scm-version == true || inputs.use-scm-version == 'true' }}
run: python3 -m pip install setuptools_scm toml --user

- name: Set package version
shell: python
if: ${{ inputs.use-scm-version == true || inputs.use-scm-version == 'true' }}
run: |
import setuptools_scm
import toml
with open("pyproject.toml", "r") as f:
pyproject = toml.load(f)
pyproject["project"]["version"] = setuptools_scm.get_version()
with open("pyproject.toml", "w") as f:
toml.dump(pyproject, f)
- name: Build distribution packages
shell: bash
run: poetry build

- name: Store distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
44 changes: 27 additions & 17 deletions .github/workflows/ci.yml → .github/actions/check/action.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
name: CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
name: Run linter and tests
description: Runs the format check, linter, type check and tests

runs:
using: composite
steps:
- name: Install system dependencies
shell: bash
run: sudo apt-get install -y pulseaudio libhidapi-libusb0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install poetry
run: pip install poetry
shell: bash
run: python3 -m pip install poetry

- name: Setup project
shell: bash
run: poetry install

- name: isort
shell: bash
run: poetry run isort --check .

- name: black
shell: bash
run: poetry run black --check .

- name: flake8
shell: bash
run: poetry run flake8 .

- name: mypy
shell: bash
run: poetry run mypy .

- name: pytest
shell: bash
run: poetry run pytest
33 changes: 33 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Check PR

on:
pull_request:

jobs:
check:
name: Check
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check
uses: ./.github/actions/check

build:
name: Build
runs-on: ubuntu-latest
needs: [check]

steps:
- name: Checkout
uses: actions/checkout@v4
with: # required to get the correct scm version
fetch-depth: 0
fetch-tags: true

- name: Build
uses: ./.github/actions/build
with:
use-scm-version: true
76 changes: 62 additions & 14 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,69 @@
name: Release
name: Build and publish

on:
release:
types: [created]
push:
branches: [main]

jobs:
deploy:
check:
name: Check
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check
uses: ./.github/actions/check

build:
name: Build
runs-on: ubuntu-latest
needs: [check]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build
uses: ./.github/actions/build

release-please:
runs-on: ubuntu-latest
needs: [build]
permissions:
contents: write
pull-requests: write

outputs:
release_created: ${{ steps.release-please.outputs.release_created }}

steps:
- uses: googleapis/release-please-action@v4
id: release-please
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: python

publish:
name: Publish
needs: [release-please]
if: ${{ needs.release-please.outputs.release_created }}
runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/p/knoepfe

permissions:
id-token: write

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- name: Download distribution packages
uses: actions/download-artifact@v4
with:
python-version: '3.10'
- name: Install poetry
run: pip install poetry
- name: Build and publish
run: |
poetry build
poetry publish -u "__token__" -p "${{ secrets.PYPI_API_TOKEN }}"
name: python-package-distributions
path: dist/

- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1

0 comments on commit e751714

Please sign in to comment.