Skip to content

Merge branch 'main' of https://github.com/adradr/lmax-python-sdk #7

Merge branch 'main' of https://github.com/adradr/lmax-python-sdk

Merge branch 'main' of https://github.com/adradr/lmax-python-sdk #7

name: Bump Version and Release
on:
push:
branches: [main]
jobs:
bump-version:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install dependencies for version bump
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Bump version with Poetry
id: bump-version
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MESSAGE" =~ Merge\ pull\ request.* ]]; then
echo "Detected merge commit, bumping major version..."
poetry version major
else
echo "Detected direct push, bumping patch version..."
poetry version patch
fi
echo "PACKAGE_VERSION=$(poetry version -s)" >> $GITHUB_ENV
echo "::set-output name=PACKAGE_VERSION::$(poetry version -s)"
git add pyproject.toml
shell: bash
- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: "Bump version to v${{ steps.bump-version.outputs.PACKAGE_VERSION }}"
force: true
release:
runs-on: ubuntu-latest
needs: bump-version
environment:
name: pypi
url: https://pypi.org/p/lmax-python-sdk
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing OpenID Connect (OIDC) tokens
deployments: write
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch the latest commits
run: |
git fetch origin main
git checkout origin/main
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install dependencies for release
run: pip install toml build
- name: Build package
run: python -m build
- name: Get package info
id: package-info
run: |
echo "PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")" >> $GITHUB_ENV
echo "PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['name'])")" >> $GITHUB_ENV
echo "::set-output name=PACKAGE_VERSION::$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")"
echo "::set-output name=PACKAGE_NAME::$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['name'])")"
- name: Create release
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "v${{ steps.package-info.outputs.PACKAGE_VERSION }}"
prerelease: false
title: "Release ${{ steps.package-info.outputs.PACKAGE_NAME }} v${{ steps.package-info.outputs.PACKAGE_VERSION }}"
files: |
dist/*.whl
dist/*.tar.gz
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
verbose: true