Skip to content

Commit

Permalink
Merge pull request #9 from HassanAbouelela/test-caching
Browse files Browse the repository at this point in the history
Include Working Dir In Cache Key Hash
  • Loading branch information
HassanAbouelela committed Sep 10, 2022
2 parents b671a6b + 622a3dc commit 7ad5c23
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 36 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test_setup_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ jobs:

- name: Test Developer Dependency
id: black
run: black --version
run: |
black --version
flake8 --version
cache_hit_pre:
name: Setup Cache
Expand Down
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.3.0
> setup-python_v1.3.1

### 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.3.0 | [![tests][sp_badge]][sp_link] | Setup a [poetry][Poetry]-managed python environment. |
| [Setup Python](./setup-python) | 1.3.1 | [![tests][sp_badge]][sp_link] | Setup a [poetry][Poetry]-managed python environment. |


[License]: https://shields.io/github/license/HassanAbouelela/actions
Expand Down
19 changes: 10 additions & 9 deletions setup-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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.3.0
uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.1
with:
dev: false
python_version: '3.10'
Expand All @@ -17,14 +17,15 @@ You can use this action as follows:
### Inputs
The following inputs are required to use this action.
| Name | Type | Default | Description |
|----------------|--------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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. |
| Name | Type | Default | Description |
|------------------|--------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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. |
| cache_pre-commit | bool | true | Enable caching and restoring pre-commit installs. Only a pre-commit config at the root workspace will be cached properly. |
| 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
21 changes: 14 additions & 7 deletions setup-python/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ inputs:
required: true
default: "true"

cache_pre-commit:
description: "Enable caching of pre-commit dependencies"
required: false
default: "true"

install_args:
description: "Extra arguments passed to the install command"
required: false
Expand Down Expand Up @@ -61,19 +66,18 @@ runs:
path: |
~/.cache/pypoetry
~/.cache/py-user-base
key: "python-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\
v1.3.0-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}-${{ inputs.poetry_version }}\
${{ hashFiles('./pyproject.toml', './poetry.lock') }}"
key: "python-${{ runner.os }}-v1.3.1-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}-${{ inputs.poetry_version }}-\
${{ hashFiles(format('{0}/pyproject.toml', inputs.working_dir), format('{0}/poetry.lock', inputs.working_dir)) }}"

# Cache pre-commit independently of other cache
- name: Pre-commit Environment Caching
if: ${{ inputs.cache_pre-commit }} == true
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: "precommit-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
v1.3.0-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}-${{ inputs.poetry_version }}\
key: "precommit-${{ runner.os }}-v1.3.1-\
${{ steps.python_setup.outputs.python-version }}-${{ inputs.dev }}-${{ inputs.working_dir }}-${{ inputs.poetry_version }}-\
${{ hashFiles('./.pre-commit-config.yaml') }}"

- name: Install Poetry
Expand Down Expand Up @@ -110,6 +114,9 @@ runs:
- name: Configure Path
shell: bash
run: |
echo "::group::Configure Path"
cd ${{ inputs.working_dir }}
echo "$(python -m poetry env info --path)/bin" >> $GITHUB_PATH
echo "Added $(python -m poetry env info --path)/bin to path"
python -m poetry -V
echo "::endgroup::"
157 changes: 141 additions & 16 deletions setup-python/tests/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 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.3.0"
version = "1.3.1"
description = "Simple project to test the setup-python action."
authors = ["Hassan Abouelela <[email protected]>"]
license = "MIT"
Expand All @@ -12,6 +12,7 @@ six = {version = "*", optional = true}

[tool.poetry.dev-dependencies]
black = "*"
flake8 = "*"

[tool.poetry.extras]
extras = ["six"]
Expand Down

0 comments on commit 7ad5c23

Please sign in to comment.