-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Allow to pass a python version to be used by the pipx action
Setting up a python version via the setup-python action before calling the pipx actions allows for more flexible setup. Otherwise all inputs of setup-python must have been passed through the pipx action too.
- Loading branch information
1 parent
a08c02a
commit 0998903
Showing
1 changed file
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,11 @@ author: "Björn Ricks <[email protected]>" | |
inputs: | ||
python-version: | ||
description: Setup a specific Python version | ||
python-path: | ||
description: | | ||
Path to the Python binary to use. Passing python-path allows for setting | ||
up a Python version before using this action and running pipx with the set | ||
up Python version. | ||
cache: | ||
description: "Enable caching for the installed application. Disabled by default. 'true' to enable." | ||
default: "false" | ||
|
@@ -57,18 +62,26 @@ runs: | |
echo $PATH | ||
shell: bash | ||
- name: Cache pipx venv for the application | ||
if: inputs.install && inputs.cache == 'true' | ||
# cache venv only if an application will be installed and the user requested caching and no python path is set | ||
if: inputs.install && inputs.cache == 'true' && !inputs.python-path | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.settings.outputs.venvs }}/${{ inputs.install }} | ||
key: python-${{ steps.python.outputs.python-version }}-pipx-venv-${{ inputs.install }}-${{ inputs.install-version || 'latest' }} | ||
- name: Install application | ||
if: inputs.install && inputs.cache == 'true' && steps.cache.outputs.cache-hit != 'true' | ||
# install an application if an application should be installed and the user did not request caching, a python path is set or the cache was not hit | ||
if: inputs.install && (inputs.python-path || inputs.cache != 'true' || steps.cache.outputs.cache-hit != 'true') | ||
run: | | ||
if [ -n "${{ inputs.python-path }}" ]; then | ||
PYTHON_BIN="${{ inputs.python-path }}" | ||
else | ||
PYTHON_BIN="${{ steps.python.outputs.python-path }}" | ||
fi | ||
ARGS="" | ||
if [ -n "${{ inputs.python-version }}" ]; then | ||
ARGS="$ARGS --python ${{ steps.python.outputs.python-path }}" | ||
if [ -n "$PYTHON_BIN" ]; then | ||
ARGS="$ARGS --python $PYTHON_BIN" | ||
fi | ||
ARGS="$ARGS ${{ inputs.install }}" | ||
|
@@ -81,8 +94,9 @@ runs: | |
pipx install $ARGS | ||
shell: bash | ||
- name: Upgrade poetry | ||
if: inputs.install && !inputs.install-version && inputs.cache == 'true' && steps.cache.outputs.cache-hit == 'true' | ||
- name: Upgrade application | ||
# install an application if the latest version of the application should be installed and the user requested caching and the cache was hit and no python path was set | ||
if: inputs.install && !inputs.install-version && inputs.cache == 'true' && steps.cache.outputs.cache-hit == 'true' && !inputs.python-path | ||
run: | | ||
pipx upgrade ${{ inputs.install }} | ||
shell: bash | ||
|