Skip to content

Commit

Permalink
ci: ensure proper venv creation and activation in GitHub Actions
Browse files Browse the repository at this point in the history
Fix Python virtual environment setup in GitHub Actions workflow by:
- Always creating venv before cache restoration
- Separating Poetry installation from dependency installation
- Making Poetry installation unconditional
- Making dependency installation conditional on cache hit

This fixes the black failure caused by missing Python interpreter when
cache was restored without proper venv creation.
  • Loading branch information
engineervix committed Jan 21, 2025
1 parent 0c925db commit dac0f04
Showing 1 changed file with 46 additions and 16 deletions.
62 changes: 46 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@ jobs:
with:
python-version: "3.10"

- name: Create virtual environment
run: python -m venv .venv

- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}

- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
- name: Install Poetry
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Dependencies
shell: bash
run: |
source .venv/bin/activate
poetry install --with dev
Expand All @@ -64,19 +70,25 @@ jobs:
with:
python-version: "3.10"

- name: Create virtual environment
run: python -m venv .venv

- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}

- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
- name: Install Poetry
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Dependencies
shell: bash
run: |
source .venv/bin/activate
poetry install --with dev
Expand Down Expand Up @@ -193,12 +205,21 @@ jobs:
with:
python-version: "3.10"

- name: Create virtual environment
run: python -m venv .venv

- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}

- name: Install Poetry
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
- name: System Dependencies
shell: bash
run: |
Expand All @@ -215,12 +236,9 @@ jobs:
export LC_ALL=en_US.UTF-8
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
name: Install Dependencies
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
source .venv/bin/activate
poetry install --with dev
Expand Down Expand Up @@ -257,19 +275,25 @@ jobs:
with:
python-version: "3.10"

- name: Create virtual environment
run: python -m venv .venv

- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}

- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
- name: Install Poetry
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Dependencies
shell: bash
run: |
source .venv/bin/activate
poetry install --with dev
Expand Down Expand Up @@ -320,19 +344,25 @@ jobs:
with:
python-version: "3.12"

- name: Create virtual environment
run: python -m venv .venv

- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}

- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
- name: Install Poetry
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Dependencies
shell: bash
run: |
source .venv/bin/activate
poetry install --with dev
Expand Down

0 comments on commit dac0f04

Please sign in to comment.