Skip to content

Commit

Permalink
Refactor poetry installation as a Custom Github Action
Browse files Browse the repository at this point in the history
  • Loading branch information
arnav13081994 authored Feb 4, 2023
1 parent ccf81cb commit 46c7641
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 40 deletions.
36 changes: 36 additions & 0 deletions .github/install_poetry_action/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Setup and install poetry
description: Install and Setup Poetry

inputs:
POETRY_VERSION:
required: true
type: string
python_version:
required: true
type: string


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

- name: Install poetry (${{ inputs.POETRY_VERSION }}) binary on runner
run: |
curl -sL https://install.python-poetry.org | python - --version ${{ inputs.POETRY_VERSION }}
shell: bash

- name: Set up cache
uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ inputs.python_version }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: timeout 10s poetry run pip --version || rm -rf .venv
shell: bash
21 changes: 3 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,10 @@ jobs:
steps:
- uses: actions/checkout@v3

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

- name: Install poetry
run: |
curl -sL https://install.python-poetry.org | python - --version ${{ env.POETRY_VERSION }}
- name: Set up cache
uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ matrix.python-version }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: timeout 10s poetry run pip --version || rm -rf .venv
POETRY_VERSION: ${{ env.POETRY_VERSION }}
python_version: ${{ matrix.python-version }}

- name: Install dependencies
run: poetry install --with ci
Expand Down
21 changes: 3 additions & 18 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
- uses: ./.github/install_poetry_action
with:
python-version: "3.11"

- name: Install poetry (${{ env.POETRY_VERSION }}) binary on runner
run: |
curl -sL https://install.python-poetry.org | python - --version ${{ env.POETRY_VERSION }}
- name: Set up cache
uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: timeout 10s poetry run pip --version || rm -rf .venv
POETRY_VERSION: ${{ env.POETRY_VERSION }}
python_version: "3.11"

- name: Install dependencies
run: poetry install --with docs
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ on:
# The branches below must be a subset of the branches above
branches: [master]

env:
POETRY_VERSION: "1.2.2"
POETRY_VIRTUALENVS_IN_PROJECT: "1"


jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4

- uses: ./.github/install_poetry_action
with:
python-version: "3.11"
POETRY_VERSION: ${{ env.POETRY_VERSION }}
python_version: "3.11"

- name: Install pre-commit
run: pip install pre-commit
run: poetry install --with dev

- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure
run: poetry run pre-commit run --all-files --show-diff-on-failure

0 comments on commit 46c7641

Please sign in to comment.