Reputation: 116
I'm learning the basics of Github Actions for CICD. I use Poetry for Dependencies Managements. But I keep throwing poetry: command not found
. If I run source $HOME/.poetry/env
in every step (which opens new shell with my limited knowledge), It works. I tried to modify the .bashrc
with cat $HOME/.poetry/env >> ~/.bashrc
, but It doesn't work.
Here is my Yaml file, thanks ^^
name: Django CI
on:
push:
branches:
- master
- develop
pull_request:
branches:
# - develop
- master
jobs:
Unit tests:
runs-on: ubuntu-latest
strategy: # Strategy
max-parallel: 4
matrix:
python-version: [3.8]
services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
ports:
- 5432:5432
steps:
- name: Checkout Github repo
uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
source $HOME/.poetry/env
cat $HOME/.poetry/env >> ~/.bashrc
poetry install
echo "OK"
- name: Run unit tests
run: |
# If I run "source $HOME/.poetry/env", It works
poetry run python manage.py test
Upvotes: 3
Views: 10282
Reputation: 703
You better use this action to install Poetry and setup the venv.
Here is what I use in my projects. It includes caching of the complete venv. The cache is invalidated by a different Python version and/or a modification in poetry.lock
.
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.1.13
virtualenvs-create: true
virtualenvs-in-project: true
- name: Set up cache
uses: actions/cache@v2
id: cached-poetry-dependencies
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
Upvotes: 3
Reputation: 1323145
Note that, from this thread:
Github Actions invoke bash scripts in non-interactive mode, it will not load
.bashrc
by default.
Only /etc/bashrc
or /etc/bash.bashrc
would be sourced (you have some other alternatives).
Or you need to source it explicitly:
source $HOME/.poetry/env
Upvotes: 1