Skip to content

Commit

Permalink
Merge pull request #1 from henningWoehr/feature/create-action
Browse files Browse the repository at this point in the history
feat: add action code
  • Loading branch information
henningWoehr authored Oct 12, 2022
2 parents 8b4a055 + 4ab7c74 commit e07f121
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# action-poetry-check-version
# action-poetry-check-version
GitHub Action for Python projects using poetry

## Description
This action compares the current project version with the latest tag of the repository. Fails if the project version isn't newer than the newest tag.

## Action Inputs
| Input name | Description | Required | Default Value |
| --- | --- | --- | --- |
| token | Github token to make authed request to GH API | true | None |

## Action Outputs
| Output name | Description |
| --- | --- |
| - | - |

## Example

#### Notes
- No code checkout is needed

```yml
name: Check Version

on:
pull_request:
branches:
- master

workflow_dispatch:

jobs:
check_version:
runs-on: ubuntu-latest
steps:
- name: Check Version
uses: henningwoehr/actions/poetry/check-version@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
```
43 changes: 43 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "check-version"
description: "Checks, if the current project-version in the pyproject.toml is already existing as a tag. Fails, if that tag already exists"

inputs:
token:
description: "Github token to make authed request to GH API"
required: true

runs:
using: composite
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get Latest Release
id: current
uses: ctrlaltdev/[email protected]
with:
repo: ${{ github.repository }}
token: ${{ inputs.token }}
limit: 1

- name: Setup poetry
id: setup-poetry
uses: henningwoehr/action-poetry-setup@v1

- name: Set env
run: |
echo "RELEASE_OLD=$(echo $json_var | jq '.[].tag_name' | tr -d '"')" >> $GITHUB_ENV
echo "POETRY_NEW=$(poetry version --short)" >> $GITHUB_ENV
env:
json_var: ${{ steps.current.outputs.releases }}
shell: bash

- name: validate version
run: |
python -c """
import sys
from packaging import version
if version.parse(sys.argv[1]) >= version.parse(sys.argv[2]):
raise ValueError('Poetry Version is not larger than the last release')
""" $RELEASE_OLD $POETRY_NEW
shell: bash

0 comments on commit e07f121

Please sign in to comment.