Skip to content

Commit

Permalink
Add lint/build-test/release workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Klavionik committed Jan 29, 2024
1 parent f398944 commit 165390f
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 122 deletions.
89 changes: 71 additions & 18 deletions .github/workflows/ci.yml → .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
name: CI
name: Build & test

on:
workflow_dispatch:
pull_request:
paths:
- "**.pyi?"
- "**.rs"
- "Cargo.*"
- "pyproject.toml"
- "README.md"
push:
paths:
- "**.pyi?"
- "**.rs"
- "Cargo.*"
- "pyproject.toml"
- "README.md"
workflow_call:
inputs:
release:
type: boolean
description: Build for release
default: false
outputs:
run_id:
description: Workflow run ID
value: ${{ jobs.output_run_id.outputs.run_id }}

jobs:
lint:
name: Run linters
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: Klavionik/pre-commit-action@main
with:
extra_args: "--hook-stage manual"
env:
# If this workflow is called to build for release, build using
# only one Python version, which is the lowest ABI version set
# in PyO3 features.
pymatrix: ${{ inputs.release && fromJSON(['3.8']) || fromJSON(['3.8', '3.12']) }}
# If this workflow is called to build for release, build using
# release profile.
build_profile: ${{ inputs.release && 'release' || 'dev' }}

test-linux:
jobs:
linux:
name: Build & test on Linux
runs-on: ubuntu-latest
needs: [lint]
strategy:
matrix:
target: [x86_64, aarch64]
py: ["3.8", "3.12"]
py: ${{ env.pymatrix }}
env:
DISPLAY: :0
steps:
Expand All @@ -40,18 +62,24 @@ jobs:
with:
command: develop
target: ${{ matrix.target }}
args: --profile ${{ env.build_profile }}
- name: Run tests
run: |
source .venv/bin/activate
python -m unittest -v
- name: Update build artifact
if: ${{ inputs.release }}
uses: actions/upload-artifact@v4
with:
name: wheels
path: target/wheels

windows:
name: Build & test on Windows
runs-on: windows-latest
needs: [lint]
strategy:
matrix:
py: ["3.8", "3.12"]
py: ${{ env.pymatrix }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -64,20 +92,26 @@ jobs:
with:
command: develop
target: x64
args: --profile ${{ env.build_profile }}
- name: Run tests
shell: powershell
run: |
.venv/Scripts/activate.ps1
python -m unittest -v
- name: Update build artifact
if: ${{ inputs.release }}
uses: actions/upload-artifact@v4
with:
name: wheels
path: target/wheels

macos:
name: Build & test on MacOS
runs-on: macos-latest
needs: [lint]
strategy:
matrix:
target: [x86_64, aarch64]
py: ["3.8", "3.12"]
py: ${{ env.pymatrix }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -90,7 +124,26 @@ jobs:
with:
command: develop
target: ${{ matrix.target }}
args: --profile ${{ env.build_profile }}
- name: Run tests
run: |
source .venv/bin/activate
python -m unittest -v
- name: Update build artifact
if: ${{ inputs.release }}
uses: actions/upload-artifact@v4
with:
name: wheels
path: target/wheels

output_run_id:
if: ${{ inputs.release }}
runs-on: ubuntu-latest
env:
RUN_ID: ${{ github.run_id }}
outputs:
run_id: ${{ steps.export.outputs.run_id }}
steps:
- name: Export workflow run ID to the caller
id: export
run: echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint

on:
workflow_dispatch:
push:
pull_request:

jobs:
lint:
name: Run linters
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: Klavionik/pre-commit-action@main
with:
extra_args: "--hook-stage manual"
39 changes: 39 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish release

on:
workflow_dispatch:
release:
types:
- published

jobs:
build:
uses: ./.github/workflows/build-test.yml
with:
release: true

publish:
name: Release
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/download-artifact@v4
with:
name: wheels
path: dist
github-token: ${{ github.token }}
run-id: ${{ needs.job1.outputs.run_id }}
- uses: actions/checkout@v3
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_REPOSITORY: ${{ secrets.PYPI_INDEX }}
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing dist/*
104 changes: 0 additions & 104 deletions .github/workflows/release.yml

This file was deleted.

0 comments on commit 165390f

Please sign in to comment.