From 7327f65da30e7a15c10246fb62aa44b14648735b Mon Sep 17 00:00:00 2001 From: polischuks Date: Fri, 14 Feb 2025 10:58:06 +0200 Subject: [PATCH] Add CI workflow for linting, type checking, and testing with multiple Python versions --- .github/workflows/actions/prepare/action.yml | 47 +++++++++++ .github/workflows/build-wheels.yml | 87 +++++++++++++++++++ .github/workflows/ci.yml | 88 ++++++++++++++++++++ .github/workflows/main.yml | 18 ++-- 4 files changed, 232 insertions(+), 8 deletions(-) create mode 100755 .github/workflows/actions/prepare/action.yml create mode 100755 .github/workflows/build-wheels.yml create mode 100755 .github/workflows/ci.yml mode change 100644 => 100755 .github/workflows/main.yml diff --git a/.github/workflows/actions/prepare/action.yml b/.github/workflows/actions/prepare/action.yml new file mode 100755 index 0000000..12d2ba8 --- /dev/null +++ b/.github/workflows/actions/prepare/action.yml @@ -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 diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml new file mode 100755 index 0000000..9fd9b9d --- /dev/null +++ b/.github/workflows/build-wheels.yml @@ -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/* diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100755 index 0000000..e792b4c --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml old mode 100644 new mode 100755 index fd01c66..869ce9e --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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 @@ -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') }}