Skip to content

Commit c37707e

Browse files
committed
Refactor GitHub Actions workflow to streamline setup and improve Python environment configuration
1 parent 81b96a2 commit c37707e

File tree

2 files changed

+50
-46
lines changed

2 files changed

+50
-46
lines changed

.github/actions/setup/action.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: 'setup'
2+
description: 'Setup python environment and install dependencies'
3+
inputs:
4+
python-version:
5+
description: 'Python version.'
6+
required: true
7+
default: '3.9'
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Set up Python
12+
uses: actions/setup-python@v3
13+
with:
14+
python-version: '${{ inputs.python-version }}'
15+
- name: Install poetry
16+
uses: abatilo/actions-poetry@v2
17+
- name: Setup poetry virtual environment
18+
run: |
19+
poetry config virtualenvs.create true --local
20+
poetry config virtualenvs.in-project true --local
21+
shell: bash
22+
- uses: actions/cache/restore@v3
23+
id: cache-restore
24+
name: Restore caches for the virtual environment based on poetry.lock
25+
with:
26+
path: ./.venv
27+
key: venv-${{ hashFiles('poetry.lock') }}
28+
- name: Install the project dependencies
29+
run: poetry install --with dev,docs -E all
30+
shell: bash
31+
- uses: actions/cache/save@v3
32+
name: Save caches based on poetry.lock
33+
if: ${{ !steps.cache-restore.outputs.cache-hit }}
34+
with:
35+
path: ./.venv
36+
key: venv-${{ hashFiles('poetry.lock') }}

.github/workflows/pr.yml

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,24 @@ on:
1717
- ".github/workflows/**"
1818

1919
jobs:
20-
setup:
21-
runs-on: ubuntu-latest
22-
steps:
23-
- name: Check Out Repo
24-
uses: actions/checkout@v4
25-
- name: Set up Python
26-
uses: actions/setup-python@v5
27-
with:
28-
python-version: '3.9'
29-
cache: 'pip'
30-
- name: Install Poetry
31-
run: pip install poetry ruff
32-
- name: Install Dependencies
33-
run: poetry install --with dev
34-
- name: Cache Poetry dependencies
35-
uses: actions/cache@v3
36-
with:
37-
path: .venv
38-
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
39-
4020
ruff:
41-
needs: setup
4221
runs-on: ubuntu-latest
4322
steps:
44-
- uses: actions/checkout@v4
45-
- uses: actions/setup-python@v5
46-
with:
47-
python-version: '3.9'
48-
- name: Install Poetry
49-
run: pip install poetry
50-
- uses: actions/cache@v3
51-
with:
52-
path: .venv
53-
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
54-
- name: Run ruff
55-
run: poetry run ruff check
23+
- uses: actions/checkout@v4
24+
- name: Set up Python environment and install dependencies
25+
uses: ./.github/actions/setup
26+
with:
27+
python-version: "3.10"
28+
- name: Ruff Check
29+
run: poetry run ruff check
5630

5731
test:
58-
needs: ruff
5932
runs-on: ubuntu-latest
6033
steps:
61-
- uses: actions/checkout@v4
62-
- uses: actions/setup-python@v5
63-
with:
64-
python-version: '3.9'
65-
- name: Install Poetry
66-
run: pip install poetry
67-
- uses: actions/cache@v3
68-
with:
69-
path: .venv
70-
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
71-
- name: Run Tests
72-
run: poetry run pytest tests
34+
- uses: actions/checkout@v4
35+
- name: Set up Python environment and install dependencies
36+
uses: ./.github/actions/setup
37+
with:
38+
python-version: "3.9"
39+
- name: Ruff Check
40+
run: poetry run pytest tests

0 commit comments

Comments
 (0)