Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move common steps into composite step #559

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/actions/install-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: "Common steps to install and cache dependencies"

inputs:
python-version:
description: "Python version to set up"
required: false
default: "3.9"

runs:
using: "composite"
steps:
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Setup environment
id: environment
shell: bash
run: |
PYTHON_USER_BASE="$(python -m site --user-base)"
echo "$PYTHON_USER_BASE/bin" >> $GITHUB_PATH
echo "pip-user-base=$PYTHON_USER_BASE" >> $GITHUB_OUTPUT

- name: Get poetry latest version
id: latest-versions
shell: bash
run: |
poetry_version=$(curl -s https://pypi.org/pypi/poetry/json | jq -r .info.version)
echo "poetry=$poetry_version" >> $GITHUB_OUTPUT
echo "Python user base: $(python -m site --user-base)"

- uses: actions/cache@v4
name: Cache Poetry
with:
path: ${{ steps.environment.outputs.pip-user-base }}
key: >
${{ format('pip-user-{0}-{1}-{2}',
runner.os,
inputs.python-version,
steps.latest-versions.outputs.poetry
) }}

- name: Install or update Poetry
shell: bash
run: |
pip install --user poetry==${{ steps.latest-versions.outputs.poetry }}

- name: Use local virtual environment
shell: bash
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local

- uses: actions/cache@v4
name: Cache Poetry dependencies
with:
path: ./.venv
key: deps-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
deps-${{ runner.os }}-${{ inputs.python-version }}-

- name: Install dependencies with Poetry
shell: bash
run: |
poetry env use python3
poetry install
16 changes: 0 additions & 16 deletions .github/actions/setup-environment/action.yml

This file was deleted.

52 changes: 2 additions & 50 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,15 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ["3.9"]
fail-fast: false

runs-on: ${{ matrix.os }}
steps:
- name: Check out the repository
uses: actions/checkout@v4

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

- name: Setup Python Environment
uses: ./.github/actions/setup-environment
id: environment

- name: Get poetry latest version
id: latest-versions
shell: bash
run: |
poetry_version=$(curl -s https://pypi.org/pypi/poetry/json | jq -r .info.version)
echo "poetry=$poetry_version" >> $GITHUB_OUTPUT
echo "Python user base: $(python -m site --user-base)"

- uses: actions/cache@v4
name: Cache Poetry
with:
path: ${{ steps.environment.outputs.pip-user-base }}
key: >
${{ format('pip-user-{0}-{1}-{2}',
matrix.os,
matrix.python-version,
steps.latest-versions.outputs.poetry
) }}

- name: Install or update Poetry
run: |
pip install --user poetry==${{ steps.latest-versions.outputs.poetry }}

- name: Use local virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local

- uses: actions/cache@v4
name: Cache Poetry dependencies
with:
path: ./.venv
key: deps-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
deps-${{ matrix.os }}-${{ matrix.python-version }}-

- name: Install dependencies with Poetry
run: |
poetry env use python3
poetry install
- name: Prepare and install deps
uses: ./.github/actions/install-deps

- name: Check if package builds
run: |
Expand Down
24 changes: 3 additions & 21 deletions .github/workflows/linting-and-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,17 @@ jobs:
strategy:
matrix:
python-version: ["3.9", "3.10"]
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4

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

- name: Install Poetry
uses: abatilo/actions-poetry@v3

- name: Use local virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local

- uses: actions/cache@v4
name: Cache Poetry dependencies
with:
path: ./.venv
key: deps-${{ env.RUNS_ON }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
deps-${{ env.RUNS_ON }}-${{ matrix.python-version }}-

- uses: actions/cache@v4
name: Cache pre-commit hooks
with:
Expand All @@ -55,9 +40,6 @@ jobs:
pre-commit-${{ env.RUNS_ON }}-${{ matrix.python-version }}-
pre-commit-${{ env.RUNS_ON }}-

- name: Install dependencies with Poetry
run: poetry install

- name: Run pre-commit on all files
run: |
poetry run pre-commit run --all-files --show-diff-on-failure --color=always
Expand Down
28 changes: 2 additions & 26 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,13 @@ env:
jobs:
publish:
name: Publish
strategy:
matrix:
python-version: ["3.9"]
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4

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

- name: Install Poetry
uses: abatilo/actions-poetry@v3

- name: Use local virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local

- uses: actions/cache@v4
name: Cache Poetry dependencies
with:
path: ./.venv
key: deps-${{ env.RUNS_ON }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
deps-${{ env.RUNS_ON }}-${{ matrix.python-version }}-

- name: Install dependencies with Poetry
run: poetry install
- name: Prepare and install deps
uses: ./.github/actions/install-deps

- name: Set version
run: poetry version $(git describe --tags --abbrev=0 | sed -e "s/^v//")
Expand Down