From 404ab70044104d1af35fc6ed061d5b67c3e3adcf Mon Sep 17 00:00:00 2001 From: James BH Date: Thu, 31 Oct 2024 18:02:12 +0000 Subject: [PATCH] test on all platforms --- .github/actions/poetry-install/action.yml | 41 +++++++++++++ .github/workflows/_tests-matrix.yml | 34 +++++++++++ .github/workflows/ci.yml | 71 ++++++++++++++--------- 3 files changed, 118 insertions(+), 28 deletions(-) create mode 100644 .github/actions/poetry-install/action.yml create mode 100644 .github/workflows/_tests-matrix.yml diff --git a/.github/actions/poetry-install/action.yml b/.github/actions/poetry-install/action.yml new file mode 100644 index 0000000..e8312a3 --- /dev/null +++ b/.github/actions/poetry-install/action.yml @@ -0,0 +1,41 @@ +name: Poetry Install +description: Installs Python dependencies using Poetry + +inputs: + poetry-version: + description: The version of Poetry to install + type: string + required: true + python-version: + description: The version of Python to use + type: string + required: true + +defaults: + run: + shell: bash + +runs: + using: composite + steps: + - name: Install Poetry + shell: bash + run: | + pipx install poetry==${{ inputs.poetry-version}} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + cache: 'poetry' + cache-dependency-path: poetry.lock + + - name: Set Poetry environment + shell: bash + run: | + poetry env use ${{ inputs.python-version }} + + - name: Install project dependencies + shell: bash + run: | + poetry install --no-interaction --no-root diff --git a/.github/workflows/_tests-matrix.yml b/.github/workflows/_tests-matrix.yml new file mode 100644 index 0000000..08d4780 --- /dev/null +++ b/.github/workflows/_tests-matrix.yml @@ -0,0 +1,34 @@ +# Reusable workflow consumed by ci.yml; used to share a single matrix across jobs. +on: + workflow_call: + inputs: + runner: + required: true + type: string + python-version: + required: true + type: string + poetry-version: + required: true + type: string + +defaults: + run: + shell: bash + +jobs: + tests: + name: Run tests (Python ${{ matrix.python-version }}), Poetry ${{ matrix.poetry-version }}, Platform ${{ matrix.runner }}) + runs-on: ${{ inputs.runner }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - uses: ./.github/actions/poetry-install + with: + python-version: ${{ inputs.python-version }} + poetry-version: ${{ inputs.poetry-version }} + + - name: Run unit tests + run: | + poetry run pytest spotify_sync/tests \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a46d5f..69daddc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,42 +1,57 @@ name: CI on: push: - branches: [main] + branches: + - main pull_request: + branches: + - main + +defaults: + run: + shell: bash jobs: - build-and-test: - name: Build and test + lint: + name: Lint runs-on: ubuntu-latest - strategy: - matrix: - python-version: ['3.8', '3.9', '3.10', '3.11', '3.11'] - steps: - name: Checkout code uses: actions/checkout@v4 - - name: Install Poetry - run: | - pipx install poetry==1.8.4 - - - name: Set up Python - uses: actions/setup-python@v5 + - uses: ./.github/actions/poetry-install with: - python-version: ${{ matrix.python-version }} - cache: 'poetry' - cache-dependency-path: poetry.lock - - - name: Set Poetry environment - run: | - poetry env use ${{ matrix.python-version }} - - - name: Install project dependencies - run: | - poetry install --no-interaction --no-root + python-version: '3.12' + poetry-version: '1.8.4' - name: Code Quality - run: poetry run black . --check - - - name: Unit Tests - run: poetry run pytest spotify_sync/tests + run: | + poetry run black . --check + + unit-tests: + name: "Unit tests (Python ${{ matrix.python-version }}, Poetry ${{ matrix.poetry-version }}, Platform ${{ matrix.os.name }})" + uses: ./.github/workflows/_tests-matrix.yml + needs: lint + with: + runner: ${{ matrix.os.image }} + python-version: ${{ matrix.python-version }} + poetry-version: '1.8.4' + strategy: + matrix: + os: + - name: Ubuntu + image: ubuntu-22.04 + - name: macOS x86_64 + image: macos-13 + - name: Windows + image: windows-2022 + - name: macOS aarch64 + image: macos-14 + python-version: + - '3.8' + - '3.9' + - '3.10' + - '3.11' + - '3.11' + - '3.12' + fail-fast: false