Reputation: 3929
I need to run poetry version
to get the pyproject.toml
version on every push to master touching pyproject.toml
. However, since Poetry is not installed on GitHub Actions runner virtual environments, I also need to install it before I can run any Poetry commands. I want to cache this tool installation so I don't have to install it on every run and use up Actions minutes. The only Poetry command I need to run is poetry version
, so I'm not worried about the tool being outdated - it only needs to parse the pyproject.toml
and get the project version number. I'm also not sure what to use as my key
for the caching action - I assume it can be static
The desired order of operations would be something like:
poetry version
.Upvotes: 5
Views: 2238
Reputation: 3929
The key
input of actions/cache@v2
can be a string - provide it something arbitrary. The path
input is the location of the tool.
path
argument does NOT resolve environment variables like $HOME
, but the tilde (~
) can be used to signify the home directory.on:
push:
branches:
- master
paths:
- 'pyproject.toml'
jobs:
pyproject-version:
runs-on: 'ubuntu-latest'
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.7'
# Perma-cache Poetry since we only need it for checking pyproject version
- name: Cache Poetry
id: cache-poetry
uses: actions/cache@v2
with:
path: ~/.poetry
key: poetry
# Only runs when key from caching step changes
- name: Install latest version of Poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
curl -sSL https://install.python-poetry.org | python -
# Poetry still needs to be re-prepended to the PATH on each run, since
# PATH does not persist between runs.
- name: Add Poetry to $PATH
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Get pyproject version
run: poetry version
Upvotes: 3