Skip to content

Publish Python Package #38

Publish Python Package

Publish Python Package #38

Workflow file for this run

name: Publish Python Package
on:
workflow_dispatch:
inputs:
publish:
description: 'Create Production Release'
required: true
type: boolean
jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Next Version
if: ${{ github.event.inputs.publish }}
id: semver
uses: ietf-tools/semver-action@v1
with:
patchList: fix, bugfix, perf, refactor, test, tests, chore, revert
token: ${{ github.token }}
branch: main
- name: Set Next Version Env Var
if: ${{ github.event.inputs.publish }}
env:
NEXT_VERSION: ${{ steps.semver.outputs.next }}
run: |
echo "NEXT_VERSION=$next" >> $GITHUB_ENV
- name: Set Build Variables
run: |
if [[ $NEXT_VERSION ]]; then
echo "Using AUTO SEMVER mode: $NEXT_VERSION"
echo "SHOULD_DEPLOY=true" >> $GITHUB_ENV
echo "PKG_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
echo "PKG_VERSION_STRICT=${NEXT_VERSION#?}" >> $GITHUB_ENV
elif [[ "$GITHUB_REF" =~ ^refs/tags/v* ]]; then
echo "Using TAG mode: $GITHUB_REF_NAME"
echo "SHOULD_DEPLOY=true" >> $GITHUB_ENV
echo "PKG_VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV
echo "PKG_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
else
echo "Using TEST mode: v0.0.1-dev.$GITHUB_RUN_NUMBER"
echo "SHOULD_DEPLOY=false" >> $GITHUB_ENV
echo "PKG_VERSION=v0.0.1-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
echo "PKG_VERSION_STRICT=3.0.0-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
fi
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Python dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip build twine
pip install build
sudo apt update
sudo apt install -y twine
- name: Build Python package
run: |
echo "Using version $PKG_VERSION_STRICT"
sed -i -r -e "s/^__version__ += '.*'$/__version__ = '$PKG_VERSION_STRICT'/" svgcheck/__init__.py
sed -i -r -e "s/^version += .*$/version = $PKG_VERSION_STRICT/" svgcheck/__init__.py
source venv/bin/activate
python -m build --sdist