Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add ability to install plugins #69

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,46 @@ jobs:
- run: |
source .github/scripts/assert.sh
assert_in "1.1.9" "$(poetry --version)"

test-plugin-installation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
version: 1.2.0a2
plugins: poetry-version-plugin
- run: |
source .github/scripts/assert.sh
poetry plugin show
assert_in "poetry-version-plugin" "$(poetry plugin show)"

test-plugins-comma-delimited:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
version: 1.2.0a2
plugins: poetry-version-plugin, poetry-export-plugin
- run: |
source .github/scripts/assert.sh
poetry plugin show
Copy link
Contributor Author

@connortann connortann Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command poetry plugin show seems to be failing on CI, with what looks to be possibly an issue with Poetry itself? Any help debugging would be appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly related issue: python-poetry/poetry#4290

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree this seems related. Do you think we'll need to wait for the next release candidate version to proceed with this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially, although that would be a shame. As an alternative, do you think it would be possible to "pip install" the plugins?

I think if Poetry is "pip-installed", then the plugins can also be pip-installed. Not sure though how this works when Poetry is installed with install-poetry.py ; perhaps by activating the venv and then using pip?

This seems a little non-standard; but, all the more reason for it to be implemented in this action so others don't have to deal with the same complexities.

Copy link
Contributor Author

@connortann connortann Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could comment out that part of the test for now, and implement the plugins feature, with a note in the README that the plugins system is still pre-release and subject to errors. I think our code is ready to go, for example I would use it in my project to install the dynamic-versioning plugin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never really done a proper deep dive in the installation script, but on first glance it seems to just create a venv in an os-specific path (here-ish), so we certainly would have a pip-executable we could use to install things into that venv with.

Are Poetry plugins just added to the poetry venv anyway? In that case this seems like it would work 🤔

assert_in "poetry-version-plugin" "$(poetry plugin show)"
assert_in "poetry-export-plugin" "$(poetry plugin show)"

test-plugins-whitespace-delimited:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
version: 1.2.0a2
plugins: |
poetry-version-plugin
poetry-export-plugin
- run: |
source .github/scripts/assert.sh
poetry plugin show
assert_in "poetry-version-plugin" "$(poetry plugin show)"
assert_in "poetry-export-plugin" "$(poetry plugin show)"
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ inputs:
installation-arguments:
description: "Arguments passed directly to the Poetry installation script. For example --force."
required: false
plugins:
description: "Comma- or whitespace-delimited list of poetry plugins to install. Requires Poetry>=1.2"
required: false
runs:
using: "composite"
steps:
Expand All @@ -41,3 +44,4 @@ runs:
VIRTUALENVS_PATH: ${{ inputs.virtualenvs-path }}
INSTALLER_PARALLEL: ${{ inputs.installer-parallel }}
INSTALLATION_ARGUMENTS: ${{ inputs.installation-arguments }}
POETRY_PLUGINS: ${{ inputs.plugins }}
18 changes: 18 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ $poetry_ config virtualenvs.create ${VIRTUALENVS_CREATE}
$poetry_ config virtualenvs.in-project ${VIRTUALENVS_IN_PROJECT}
$poetry_ config virtualenvs.path ${VIRTUALENVS_PATH}

# Parse plugin array from string, handle comma, whitespace or newline delimiters
read -r -d "" -a plugins <<< "$(echo "$POETRY_PLUGINS" | tr "," " ")"
if [ ${#plugins[@]} -gt 0 ]; then

# Ensure poetry version >= 1.2
# Simplistic version comparison, will need to be updated if Poetry 2.X is released
major=${VERSION:0:1}
minor=${VERSION:2:1}
if [ "$major" -lt 1 ] || [ "$minor" -lt 2 ]; then
echo "Use of plugins requires Poetry version >= 1.2"
exit 1
fi

# Install plugins
echo "Installing plugins: " "${plugins[@]}"
$poetry_ plugin add "${plugins[@]}" || exit 1
fi

config="$($poetry_ config --list)"

if echo "$config" | grep -q -c "installer.parallel"; then
Expand Down