Skip to content

Commit

Permalink
Add CI workflow for linting, type checking, and testing with multiple…
Browse files Browse the repository at this point in the history
… Python versions
  • Loading branch information
polischuks committed Feb 14, 2025
1 parent d4e0614 commit 7327f65
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 8 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/actions/prepare/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: 'Prepare environment'
description: 'Prepare environment'

inputs:
python-version:
description: 'Python version to use'
required: true

runs:
using: "composite"
steps:
- name: Setup PATH
run: echo "/home/runner/.local/bin" >> $GITHUB_PATH
shell: bash

- name: Install Poetry
run: pipx install poetry==$(head -n 1 .poetry-version)
shell: bash

- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: 'poetry'

- name: Clear Poetry cache
run: poetry cache clear --all pypi
shell: bash

- name: Install dependencies and package
run: poetry install --no-interaction --no-ansi
shell: bash

# Setup Node.js for JavaScript tests
- uses: actions/setup-node@v4
with:
node-version: '20'

# Install Node.js dependencies
- name: Install Node.js dependencies
run: npm install
shell: bash

# Setup Go for Go language tests
- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: false
87 changes: 87 additions & 0 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Build Wheels

on:
push:
tags:
- 'v*'
workflow_dispatch:

jobs:
build_wheels:
name: Build psutil wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
matrix:
include:
# Linux builds
- os: ubuntu-latest
python-version: '3.10'
- os: ubuntu-latest
python-version: '3.11'
- os: ubuntu-latest
python-version: '3.12'

# Windows builds
- os: windows-latest
python-version: '3.10'
- os: windows-latest
python-version: '3.11'
- os: windows-latest
python-version: '3.12'

# macOS builds
- os: macos-latest
python-version: '3.10'
- os: macos-latest
python-version: '3.11'
- os: macos-latest
python-version: '3.12'

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install build dependencies
run: |
python -m pip install pip wheel
shell: bash

- name: Build psutil wheel
run: |
# Create dist directory
mkdir -p dist
# Build psutil wheel
pip wheel psutil==5.8.0 --wheel-dir dist/
shell: bash

- name: Upload to GitHub Actions
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.os }}-py${{ matrix.python-version }}
path: dist/*

release:
needs: build_wheels
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: dist-*
path: dist
merge-multiple: true

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
88 changes: 88 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: CI

on:
push:
branches:
- master
- release
pull_request:

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

jobs:
lint:
name: Lint with ruff
runs-on: arc-runners-small
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- uses: ./.github/workflows/actions/prepare
with:
python-version: "3.11"
- name: Check files using the ruff formatter
run: |
poetry run ruff check --fix --unsafe-fixes --preview --exit-zero .
poetry run ruff format .
shell: bash
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
fetch: false
default_author: github_actions
message: 'Backend: Auto format'
add: '.'

mypy:
name: Static Type Checking
runs-on: arc-runners-small
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/actions/prepare
with:
python-version: "3.12"
- name: Mypy
run: poetry run mypy .
shell: bash

test:
name: Run unit test on ${{ matrix.os }} with Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Self-hosted runner
- os: [ self-hosted, small ]
python-version: "3.10"
- os: [ self-hosted, small ]
python-version: "3.11"
- os: [ self-hosted, small ]
python-version: "3.12"

# Windows
- os: windows-latest
python-version: "3.10.11"
- os: windows-latest
python-version: "3.11"
- os: windows-latest
python-version: "3.12"

# macOS (arm64)
- os: macos-14
python-version: "3.11"
- os: macos-14
python-version: "3.12"
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/actions/prepare
with:
python-version: ${{ matrix.python-version }}
- name: Run Tests
run: poetry run python tests/testing.py
shell: bash
18 changes: 10 additions & 8 deletions .github/workflows/main.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ on: [ push ]

jobs:
Lint:
if: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: "3.12"
python-version: "3.7"
- name: Python version
run: python --version
- name: Install dependencies
Expand All @@ -24,16 +25,17 @@ jobs:
- name: Lint
run: flake8
test-ubuntu:
if: false
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-20.04", "windows-latest", "macos-latest"]
python-version: [ "3.10", "3.11", "3.12" ]
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10", "3.11.0-rc.2" ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Python version
Expand All @@ -43,7 +45,7 @@ jobs:
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/cache@v4
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
Expand Down

0 comments on commit 7327f65

Please sign in to comment.