Skip to content

Commit

Permalink
[FUZB-130] Poetry update for multi projects (#7)
Browse files Browse the repository at this point in the history
* [FUZB-92] Bug fix changing version check to not check for micro release

* [FUZB-92] Allow directory to be given as argument

* [FUZB-92] Add echo statement

* [FUZB-92] Add update poetry

* [FUZB-92] Try adding installation directory arguments

* [FUZB-92] Fix arg syntax

* [FUZB-92] Install from lock file

* [FUZB-92] Set virtualenvs-create to true

* [FUZB-92] add echo statements

* [FUZB-92] Change to allow update message

* [FUZB-92] Change to allow multiple PRs

* [FUZB-130] Update to add env variables to GITHUB_ENV

* [FUZB-130] Fix bash script

* [FUZB-130] Add missing $

* [FUZB-130] Move string manipulation into sed

* [FUZB-130] Fix space in variable assignment

* [FUZB-130] Remove trailing dashes

* [FUZB-130] Add quotes to assignment

* [FUZB-130] Debugging statements

* [FUZB-130] Change variable assignment syntax

* [FUZB-130] Change variable assignment syntax

* [FUZB-130] Debug commit

* [FUZB-130] Add quotes around assignment

* [FUZB-130] Add quotes around assignment

* [FUZB-130] Change to double quotes

* [FUZB-130] Debug commit

* [FUZB-130] use alternative assignment syntax

* [FUZB-130] Remove spaces

* [FUZB-130] Syntax change

* [FUZB-130] bug fixes

* [FUZB-130] Set PR details from env variables

* [FUZB-130] Set Commit Message

* [FUZB-130] Add slash to directory

* [FUZB-130] echo current directory

* [FUZB-130] echo current directory

* [FUZB-130] Add run update condition to generating commit message and PR details

* [FUZB-130] More debug statements

* [FUZB-130] More debug statements

* [FUZB-130] isolate update step

* [FUZB-130] isolate text writing step

* [FUZB-130] More debugging

* [FUZB-130] Fix comparison to check if multi-project repo

* [FUZB-130] Add back in updating grep

* [FUZB-130] Remove quotes around poetry

* [FUZB-130] Remove quotes around poetry

* [FUZB-130] Add grep back in

* [FUZB-130] Check if the problem is writing an empty string to file

* [FUZB-130] Add echo as workaround

* [FUZB-130] Change echo to be combined with cat

* [FUZB-130] Change echo to be combined with cat

* [FUZB-130] Experiment with removing all text processing from poetry update message

* [FUZB-130] Fix test new test condition.

* [FUZB-130] Remove trailing dashes and second attempt at fixing conditional

* [FUZB-130] Remove commented out text processing

* [FUZB-130] Add example to README

* [FUZB-130] Grammar and unnecessary `pwd` command
  • Loading branch information
EchoStatements authored Apr 15, 2024
1 parent c8285e4 commit 78e5e9c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 9 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ All inputs are **optional**. If not set, sensible defaults will be used.
| Name | Description | Default |
| --- | --- | --- |
| `python-version` | The python version to use with poetry, the minimum version required is >=3.10.5 | 3.10.12 |
| `python-version` | The python version to use with poetry, the minimum version required is >=3.10 | 3.10.12 |
| `poetry-version` | The poetry version to use | 1.8.2 |

### Example
Expand All @@ -90,4 +90,33 @@ jobs:
with:
python-version: '3.10.12'
poetry-version: '1.8.2'
```
```

This action can also be used on repositories which contain multiple projects in different directories. The following example shows a workflow in which the action updates dependencies in projects in directories `project1/` `project2` and `project3`.

If dependencies are updated in one or more of these projects, a separate pull request
will be generated for each of the updated projects.

```yaml
name: Poetry Update
on:
# Run weekly on Monday at 0700AM
schedule:
- cron: "0 7 * * MON"
# Allow a manual trigger
workflow_dispatch:
jobs:
auto-update:
runs-on: ubuntu-latest
strategy:
matrix: { directory: ['project1/', 'project2/', 'project3/'] }
steps:
- uses: fuzzylabs/gha-poetry-update@v1
with:
python-version: "3.10"
directory: ${{ matrix.directory }}
```
_Note: We do not explicitly support this action with Python <=3.10.4. Though Python 3.10 is checked for as a minimum requirement, this is to capture workflows which set version generically to 3.10.X specifying only major and minor release numbers._
57 changes: 50 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
poetry-version:
description: "The poetry version to use"
default: '1.8.2'
directory:
description: "The directory of the project files"
default: './'

runs:
using: "composite"
Expand All @@ -22,7 +25,7 @@ runs:
# Poetry 1.2 is the first release that support python >=3.8
- name: Check compatible version
run: |
min_python_version="3.10.5"
min_python_version="3.10"
min_poetry_version="1.2"
if [ "$(printf '%s\n' "$min_python_version" "${{ inputs.python-version }}" | sort -V | head -n1)" != "$min_python_version" ]; then
echo "Less than the minimum required python version: ${min_python_version}, exiting workflow"
Expand Down Expand Up @@ -67,6 +70,7 @@ runs:
# Check if poetry.lock exists
#----------------------------------------------
- name: Check if poetry.lock exists
working-directory: ${{ inputs.directory }}
if: env.RUN_UPDATE != 'false'
run: |
if [ -f "poetry.lock" ]; then
Expand All @@ -81,11 +85,12 @@ runs:
# Run poetry update
#----------------------------------------------
- name: Run poetry update
working-directory: ${{ inputs.directory }}
if: env.RUN_UPDATE != 'false'
run: |
echo "running install"
poetry install --no-interaction --no-root
poetry update | grep -i 'updating' | grep -v 'Updating dependencies' | sed 's/Updating//g' > /var/tmp/updated_deps.txt
cat /var/tmp/updated_deps.txt
poetry update > /var/tmp/updated_deps.txt
{
echo "UPDATE_MESSAGE<<EOF"
cat /var/tmp/updated_deps.txt
Expand All @@ -96,16 +101,54 @@ runs:
#----------------------------------------------
# Create a pull request
#----------------------------------------------
- name: Create branch name
working-directory: ${{ inputs.directory }}
if: env.RUN_UPDATE != 'false'
shell: bash
run: |
if [ ${{ inputs.directory }} == "./" ]
then
BRANCH_NAME="update/poetry-update"
BRANCH_TITLE="Update poetry dependencies"
COMMIT_MESSAGE="Chore(deps): Upgrading poetry dependencies"
else
# replace " " and "_" with dashes
BRANCH_NAME=$(echo ${{ inputs.directory }} | sed -r "s/[_ ]/-/g" | sed -r "s/\//--/g")
# remove trailing dashes
BRANCH_NAME=$(echo $BRANCH_NAME | sed -r "s/-+$//g")
# NOTE: undesirable behaviour may occur if a project directory name is excessively long (~100 chars)
# or if two projects share the same name up to substitutions of "-" with " ".
BRANCH_NAME="update/poetry-update-$BRANCH_NAME"
BRANCH_TITLE="Update poetry dependencies for ${{ inputs.directory }}"
COMMIT_MESSAGE="Chore(deps): Upgrading poetry dependencies for ${{ inputs.directory }}"
fi
{
echo "BRANCH_NAME<<EOF"
echo $BRANCH_NAME
echo "EOF"
} >> $GITHUB_ENV
{
echo "BRANCH_TITLE<<EOF"
echo $BRANCH_TITLE
echo "EOF"
} >> $GITHUB_ENV
{
echo "COMMIT_MESSAGE<<EOF"
echo $COMMIT_MESSAGE
echo "EOF"
} >> $GITHUB_ENV
- name: Create Pull Request
if: env.RUN_UPDATE != 'false'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ github.token }}
branch: update/poetry-update
title: Update poetry dependencies
commit-message: "Chore(deps): Upgrading `poetry` dependencies"
branch: ${{ env.BRANCH_NAME }}
title: ${{ env.BRANCH_TITLE }}
commit-message: ${{ env.COMMIT_MESSAGE }}
body: |
Update `poetry` dependencies to use latest compatible versions.
**Outdated packages**:
**Poetry update message**:
${{ env.UPDATE_MESSAGE }}

0 comments on commit 78e5e9c

Please sign in to comment.