diff --git a/.github/actions/setup-project/action.yml b/.github/actions/setup-project/action.yml new file mode 100644 index 0000000..4dfb260 --- /dev/null +++ b/.github/actions/setup-project/action.yml @@ -0,0 +1,43 @@ +name: Common Python + Poetry Setup + +inputs: + dependency-groups: + description: 'A comma-separated list of dependency groups to install' + default: 'main' + python-version: + description: 'The Python version to use' + default: '3.10' + +runs: + using: 'composite' + + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + + - name: Install poetry + shell: bash + run: | + python -m pip install poetry + poetry config virtualenvs.in-project true + + - name: Get cache key + id: cache-key + shell: bash + run: | + key=$(echo "${{ inputs.dependency-groups }}" | sed 's/,/+/') + echo "key=$key" >> "$GITHUB_OUTPUT" + + - name: Load cached venv + id: cache-dependencies + uses: actions/cache@v4 + with: + path: .venv + key: venv-${{ runner.os }}-python-${{ inputs.python-version }}-groups-${{ steps.cache-key.outputs.key }}-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + if: steps.cache-dependencies.outputs.cache-hit != 'true' + shell: bash + run: poetry install --with ${{ inputs.dependency-groups }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8e32a23..2066d1e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -16,17 +16,10 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 + + - uses: './.github/actions/setup-project' with: - python-version: '3.10' - - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - poetry install --with dev + dependency-groups: 'docs' - name: Build documentation run: | diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 72eadf7..1498bc6 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -5,22 +5,15 @@ on: push: jobs: - deploy: + check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - poetry install --with dev,test + - uses: './.github/actions/setup-project' + with: + dependency-groups: 'dev,test' - uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2812c62..162d774 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,16 +15,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + + - uses: './.github/actions/setup-project' with: - python-version: '3.10' - - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - poetry install --with dev + dependency-groups: 'dev' - name: Prepare README run: ./scripts/refactor_readme.py README.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c7a0215..6869e20 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,21 +13,16 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 + + - uses: './.github/actions/setup-project' with: - python-version: '3.10' - - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - poetry install --with dev + dependency-groups: 'dev' - id: supported-versions name: Get supported versions - run: echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT" + run: | + set -e + echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT" test: runs-on: ubuntu-latest @@ -40,18 +35,22 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + - uses: './.github/actions/setup-project' with: - python-version: "${{ matrix.py-version }}" - - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - - # Only install main dependencies - poetry install --with test + python-version: ${{ matrix.py-version }} + dependency-groups: 'test' - name: Run unit tests run: poetry run pytest + + results: + runs-on: ubuntu-latest + needs: test + steps: + - run: | + result="${{ needs.test.result }}" + if [[ $result == "success" || $result == "skipped" ]]; then + exit 0 + else + exit 1 + fi