Skip to content

Commit

Permalink
Fix problematic steps and caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwerty-133 committed Jun 14, 2023
1 parent 955f78a commit 0594547
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<a href="LICENSE">
<img alt="License" src="https://img.shields.io/github/license/Qwerty-133/python-setup">
</a>
<a href="https://github.com/Qwerty-133/python-setup/releases/latest>
<a href="https://github.com/Qwerty-133/python-setup/releases/latest">
<img alt="Release" src="https://img.shields.io/github/v/release/Qwerty-133/python-setup">
</a>
</p>
Expand Down Expand Up @@ -39,10 +39,11 @@ To source the venv, add this to your workflow:
run: source $VENV
```

> Also see [#windows](#windows) if you are using Windows runners.

## Cache

This action caches the Poetry installation, it's venv, and pre-commit hooks.
On Windows runners, the venv is not cached since it doesn't work as expected.

To disable the cache entirely, the use-cache input can be set to false.

Expand Down Expand Up @@ -72,6 +73,18 @@ To skip installing pre-commit, the skip-precommit input can be set to true.
skip-precommit: true
```

## Windows

You must set the default shell to be bash, by adding the following in your workflow.

```yaml
defaults:
run:
shell: bash
```

On Windows runners, only pre-commit hooks are cached, since caching the Poetry installation and venv is problematic.

## Credits

The [`snok/install-poetry`](https://github.com/snok/install-poetry) action is used to install Poetry.
25 changes: 15 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ inputs:
description: "Whether to cache the Poetry installation, dependencies and pre-commit"
required: false
default: true
skip-precommit:
skip-pre-commit:
description: "Whether to skip installing pre-commit"
required: false
default: false
Expand All @@ -31,41 +31,46 @@ runs:
python-version: ${{ inputs.python-version }}

- name: Try loading cached Poetry installation
id: cached-poetry
if: ${{ inputs.use-cache }}
id: cache-poetry
if: ${{ inputs.use-cache == 'true' && runner.os != 'Windows' }}
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-${{ runner.os }}

- name: Install Poetry
if: ${{ !inputs.use-cache || !steps.cached-poetry.outputs.cache-hit }}
id: install-poetry
if: ${{ steps.cache-poetry.outcome == 'skipped' || steps.cache-poetry.outputs.cache-hit != 'true' }}
uses: snok/install-poetry@v1
with:
virtualenvs-in-project: true

- name: Add Poetry to PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH && export PATH="$HOME/.local/bin:$PATH"
shell: bash

- name: Load cached venv
id: cached-poetry-dependencies
if: ${{ runner.os != 'Windows' }}
id: cache-deps
if: ${{ inputs.use-cache == 'true' && runner.os != 'Windows' }}
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: ${{ runner.os == 'Windows' || !steps.cached-poetry-dependencies.outputs.cache-hit }}
if: ${{ steps.cache-deps.outcome == 'skipped' || steps.cache-deps.outputs.cache-hit != 'true'}}
run: poetry install --no-interaction
shell: bash

- name: Try loading Pre-commit cache
id: cached-pre-commit
if: ${{ inputs.use-cache && !inputs.skip-precommit }}
id: cache-pre-commit
if: ${{ inputs.use-cache == 'true' && inputs.skip-pre-commit == 'false' }}
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Install pre-commit
if: ${{ !inputs.skip-precommit }}
if: ${{ inputs.skip-pre-commit == 'false' }}
run: poetry run pre-commit install --install-hooks
shell: bash

0 comments on commit 0594547

Please sign in to comment.