Skip to content

🔧 (workflows): replace docs.yml with release.yml for automated versio… #1

🔧 (workflows): replace docs.yml with release.yml for automated versio…

🔧 (workflows): replace docs.yml with release.yml for automated versio… #1

Workflow file for this run

name: Bump Version and Release
on:
push:
branches: [main]
jobs:
pytest:
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 testing
run: pip install .
- name: Run tests
run: pytest
bump-version:
runs-on: ubuntu-latest
needs: pytest
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
# Build the documentation and upload the static HTML files as an artifact.
build-docs:
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
# ADJUST THIS: install all dependencies (including pdoc)
- run: pip install -e .
# We use a custom build script for pdoc itself, ideally you just run `pdoc -o docs/ ...` here.
- run: pdoc --mermaid -o docs/ lmax_python_sdk/
- uses: actions/upload-pages-artifact@v3
with:
path: docs/
# Deploy the artifact to GitHub pages.
# This is a separate job so that only actions/deploy-pages has the necessary permissions.
deploy-docs:
needs: build-docs
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4