Skip to content

Commit

Permalink
Add Poetry Version Option (#1)
Browse files Browse the repository at this point in the history
Add Poetry Version Option

Adds an option to allow allow specifying the poetry
version in the setup-python action.

Signed-off-by: Hassan Abouelela <[email protected]>
  • Loading branch information
HassanAbouelela committed Sep 8, 2022
1 parent 4c445c4 commit b671a6b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test_setup_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,28 @@ jobs:

- name: Test Optional Dependency
run: python -c "import six"

versions:
name: Test Different Poetry Versions
runs-on: ubuntu-latest
strategy:
matrix:
version:
- "poetry==1.1.*"
- "poetry==1.2.*"
- "git+https://github.com/python-poetry/poetry.git@master"

steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: ./setup-python
with:
dev: false
python_version: 3.9
poetry_version: ${{ matrix.version }}
working_dir: setup-python/tests/
use_cache: false

- name: Check Installation
run: poetry --version
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ linked in the index below.
> {name}_v{version}
Example:
> setup-python_v1.2.1
> setup-python_v1.3.0

### Support Policy
Expand All @@ -33,7 +33,7 @@ An index of all the currently maintained scripts, their description, and the lat

| Name | Version | Status | Description |
|--------------------------------|---------|-------------------------------|------------------------------------------------------|
| [Setup Python](./setup-python) | 1.2.1 | [![tests][sp_badge]][sp_link] | Setup a [poetry][Poetry]-managed python environment. |
| [Setup Python](./setup-python) | 1.3.0 | [![tests][sp_badge]][sp_link] | Setup a [poetry][Poetry]-managed python environment. |


[License]: https://shields.io/github/license/HassanAbouelela/actions
Expand Down
7 changes: 4 additions & 3 deletions setup-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ It also handles caching of pre-commit if you happen to be using that.
You can use this action as follows:
```yaml
- name: Install Python Dependencies
uses: HassanAbouelela/actions/setup-python@setup-python_v1.2.1
uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.0
with:
dev: false
python_version: 3.9
python_version: '3.10'
```
### Inputs
Expand All @@ -21,9 +21,10 @@ The following inputs are required to use this action.
|----------------|--------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| dev | bool | false | Indicate whether dev dependencies should be installed. If false, the `--no-dev` flag is passed to poetry. Despite having a default, it's good practice to explicitly set one. |
| python_version | string | | Specify the python version passed to the `actions/setup-python` action. |
| poetry_version | string | poetry | The version of poetry to install and use. This is passed directly to pip, so you can specify any pattern, such as `poetry~=1.2` or `poetry==1.1.15`. |
| working_dir | path | `.` | The directory to run the `poetry install` command in. By default, this will just be the root directory. |
| use_cache | bool | true | Enable or disable the usage of cache, even if it is available. |
| install_args | string | | A string placed after the `poetry install` command, which can contain extra options |
| install_args | string | | A string placed after the `poetry install` command, which can contain extra options. |

### Outputs
The following outputs are produced by the action:
Expand Down
16 changes: 11 additions & 5 deletions setup-python/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ inputs:
required: false
default: ""

poetry_version:
description: "The poetry version to install (passed to pip install)"
required: false
default: "poetry"

outputs:
cache-hit:
description: "Was there a cache hit for the python cache."
Expand Down Expand Up @@ -57,8 +62,8 @@ runs:
~/.cache/pypoetry
~/.cache/py-user-base
key: "python-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\
v1.2.1-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}\
v1.3.0-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}-${{ inputs.poetry_version }}\
${{ hashFiles('./pyproject.toml', './poetry.lock') }}"

# Cache pre-commit independently of other cache
Expand All @@ -67,15 +72,15 @@ runs:
with:
path: ~/.cache/pre-commit
key: "precommit-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
v1.2.1-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}\
v1.3.0-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}-${{ inputs.poetry_version }}\
${{ hashFiles('./.pre-commit-config.yaml') }}"

- name: Install Poetry
shell: bash
run: |
echo "::group::Install Poetry"
pip install poetry
pip install ${{ inputs.poetry_version }}
echo "::endgroup::"
- name: Install dependencies
Expand Down Expand Up @@ -107,3 +112,4 @@ runs:
run: |
cd ${{ inputs.working_dir }}
echo "$(python -m poetry env info --path)/bin" >> $GITHUB_PATH
python -m poetry -V
2 changes: 1 addition & 1 deletion setup-python/tests/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "project"
version = "1.2.1"
version = "1.3.0"
description = "Simple project to test the setup-python action."
authors = ["Hassan Abouelela <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit b671a6b

Please sign in to comment.