Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Setup Python GitHub Action

Setup Python environment with Pipenv and cache the virtual environment.
Setup Python environment and cache the virtual environment.

Dependencies manager Pipenv or Poetry can be used.
Projects using Poetry must specify version in `.tool-versions`.
57 changes: 52 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Install Python dependencies with Pipenv and caching.
name: Install Python dependencies with Pipenv or Poetry and caching.
description: |
Install Python dependencies with Pipenv.
Install Python dependencies and caching. |
Dependencies manager Pipenv or Poetry is detetected using file `.tool-versions`. |
Caching name is defined.

outputs:
dependencies-manager:
description: "Dependencies manager selection between 'pipenv' and 'poetry'."
value: ${{ steps.dependencies-manager.outputs.dm }}

runs:
using: composite
Expand All @@ -10,16 +17,56 @@ runs:
shell: bash
run: echo "python-version=$(cat .tool-versions | grep python | awk '{print $2}')" >> $GITHUB_OUTPUT

- name: Install pipenv
- name: Search Poetry
id: search-poetry
shell: bash
run: echo "poetry-str=$(cat .tool-versions | grep poetry | awk '{print $1}')" >> $GITHUB_OUTPUT

- name: Check if poetry
id: check-if-poetry
shell: bash
run: echo "use-poetry=$(expr '${{ steps.search-poetry.outputs.poetry-str }}' == 'poetry')" >> $GITHUB_OUTPUT

- name: Dependecies Manager
id: dependencies-manager
shell: bash
run: if [[ ${{ steps.check-if-poetry.outputs.use-poetry }} == 1 ]]; then echo 'dm=poetry'; else echo 'dm=pipenv'; fi >> $GITHUB_OUTPUT

- name: Get poetry version
id: get-poetry-version
shell: bash
if: ${{ steps.check-if-poetry.outputs.use-poetry == 1 }}
run: echo "poetry-version=$(cat .tool-versions | grep poetry | awk '{print $2}')" >> $GITHUB_OUTPUT

- name: Install poetry if selected
id: install-poetry-if-selected
shell: bash
if: ${{ steps.check-if-poetry.outputs.use-poetry == 1 }}
run: pipx install poetry==${{ steps.get-poetry-version.outputs.poetry-version }}

- name: Install pipenv if not poetry
id: install-pipenv-if-not-poetry
shell: bash
if: ${{ steps.check-if-poetry.outputs.use-poetry != 1 }}
run: pipx install pipenv

- name: Get cache name
id: get-cache-name
shell: bash
run: if [[ ${{ steps.check-if-poetry.outputs.use-poetry }} == 1 ]]; then echo 'cache=poetry'; else echo 'cache=pipenv'; fi >> $GITHUB_OUTPUT

- name: Setup Python environment and cache
uses: actions/setup-python@v4
with:
python-version: ${{ steps.get-python-version.outputs.python-version }}
cache: 'pipenv'
cache: ${{ steps.get-cache-name.outputs.cache }}

- name: Install dependencies using poetry
shell: bash
if: ${{ steps.check-if-poetry.outputs.use-poetry == 1 }}
run: poetry install --sync

- name: Install dependencies
- name: Install dependencies using pipenv
shell: bash
if: ${{ steps.check-if-poetry.outputs.use-poetry != 1 }}
run: pipenv sync --dev