Skip to content

Commit

Permalink
Merge pull request #47 from OSIPI/sematic-version
Browse files Browse the repository at this point in the history
Add manually triggered release workflow to bump version, gather change-log, and publish release.
  • Loading branch information
ltorres6 authored Sep 9, 2024
2 parents a392972 + 52e1c75 commit e78d9e2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
62 changes: 54 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Publish to PyPI

on:
workflow_dispatch:
branches:
- main
inputs:
version:
description: 'Version to release'
Expand All @@ -16,6 +14,22 @@ on:
- 'minor'
- 'patch'

repository:
description: 'Repository to publish to'
required: true
default: 'testpypi'
type: choice
options:
- 'pypi'
- 'testpypi'

permissions:
contents: write
id-token: write
pull-requests: read
issues: read


jobs:
release:
runs-on: ubuntu-latest
Expand All @@ -37,19 +51,51 @@ jobs:
run: poetry install

- name: Bump version
id: bump_version
run: |
python handle_versioning.py ${{ github.event.inputs.version }}
poetry run python handle_versioning.py ${{ github.event.inputs.version }}
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add pyproject.toml
git commit -m "Bump version to ${{ github.event.inputs.version }}"
new_version=$(poetry run python handle_versioning.py read)
git commit -m "Bump version to $new_version"
git push
echo "latest_version=$new_version" >> $GITHUB_ENV
- name: Generate release notes
id: release-notes
uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create tag
id: create_tags
run: |
current_version=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")
current_version=${{env.latest_version}}
git tag $current_version
git push origin $current_version
- name: Publish to PyPI
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{env.latest_version}}
release_name: Release ${{env.latest_version}}
body: ${{ steps.release-notes.outputs.release_notes }}
draft: false
prerelease: false

- name: Build package
run: |
poetry build
- name: Publish to TestPyPI or PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ github.event.inputs.repository == 'pypi' && 'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/' }}
username: __token__
password: ${{ github.event.inputs.repository == 'pypi' && secrets.PYPI_API_TOKEN || secrets.TEST_PYPI_API_TOKEN }}
env:
POETRY_PYPI_TOKEN: ${{ secrets.POETRY_PYPI_TOKEN }}
run: poetry publish --build
POETRY_PYPI_TOKEN: ${{ github.event.inputs.repository == 'pypi' && secrets.PYPI_POETRY_TOKEN || secrets.TEST_PYPI_POETRY_TOKEN }}
2 changes: 1 addition & 1 deletion handle_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def bump_version(part):
command = sys.argv[1]
if command == "read":
current_version = read_version()
print(f"Current version is {current_version}")
print(f"{current_version}")

else:
bump_version(command)
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ line-length = 100

[tool.poetry]
name = "osipi"
version = "0.1.2"
version = "0.1.0"
description = "The authorative python package for perfusion MRI"
authors = [ "Luis Torres <[email protected]>", "Steven Sourbron <[email protected]>",]
readme = "README.md"
Expand All @@ -47,9 +47,7 @@ quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

docstring-code-format = true

docstring-code-line-length = 100

[tool.poetry.dependencies]
Expand Down

0 comments on commit e78d9e2

Please sign in to comment.