Skip to content

Commit

Permalink
Move common steps into composite step
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI committed Sep 12, 2024
1 parent cac4282 commit 3237da9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 105 deletions.
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.

49 changes: 2 additions & 47 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,11 @@ jobs:
- 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: 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: Check if package builds
run: |
poetry build
23 changes: 2 additions & 21 deletions .github/workflows/linting-and-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,11 @@ jobs:
- 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 +39,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
23 changes: 2 additions & 21 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,11 @@ jobs:
- 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 }}-
- name: Install dependencies with Poetry
run: poetry install

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

Expand Down

0 comments on commit 3237da9

Please sign in to comment.