From e62fbda2004c4cb7a8a95eae17b879e2de9f1f38 Mon Sep 17 00:00:00 2001 From: AlexisGauthierAtKronos Date: Fri, 6 Jan 2023 10:30:18 -0500 Subject: [PATCH 1/2] Added option to setup dependencies with Poetry --- README.md | 5 ++++- action.yml | 47 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6f3ec36..153a580 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/action.yml b/action.yml index 3887b1f..3226ed1 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,8 @@ -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. runs: using: composite @@ -10,16 +12,51 @@ 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: 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 From acca3ee2ac72ff8c673b8e950bd756c14f2bf643 Mon Sep 17 00:00:00 2001 From: AlexisGauthierAtKronos Date: Wed, 11 Jan 2023 09:59:06 -0500 Subject: [PATCH 2/2] Outputs dependencies manager selection --- action.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/action.yml b/action.yml index 3226ed1..706ea73 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,11 @@ description: | 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 steps: @@ -22,6 +27,11 @@ runs: 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