Skip to content

Upload release to PyPI #31

Upload release to PyPI

Upload release to PyPI #31

Workflow file for this run

name: Upload release to PyPI
on:
workflow_dispatch:
inputs:
version:
description: 'Version tag for the release'
required: true
push:
tags:
- 'v*.*.*'
jobs:
pypi-publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set version environment variable
id: set_version
env:
VERSION: ${{ github.event.inputs.version || github.ref_name }}
run: echo "VERSION=${VERSION#v}" >> $GITHUB_ENV
- name: Update version in toml
run: |
sed -i "s/^version = .*/version = \"${{ env.VERSION }}\"/" pyproject.toml
- name: Update links in README
run: |
REPO_URL="https://github.com/${{ github.repository }}"
sed -i "s|sql-data-guard-logo.png|${REPO_URL}/blob/main/sql-data-guard-logo.png|g" README.md
- name: Install pypa/build
run: python3 -m pip install build --user
- name: Build a binary wheel and a source tarball for test PyPi
run: python3 -m build --outdir dist-testpypi
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: dist-testpypi
verbose: true
- name: Create virtual environment for test PyPi
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
echo "Waiting for 30 seconds to make sure package is available"
sleep 30
pip install --no-cache-dir --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ sql-data-guard==${{ env.VERSION }}
pip install pytest
shell: bash
- name: Run unit tests with test PyPi package
# This step runs the unit tests with the test PyPi package, the src dir is not in the context
# This specific unit test file only uses public methods from the package
run: |
source .venv/bin/activate
python -m pytest --color=yes test/test_sql_guard_unit.py
- name: Clear test PyPi virtual environment
run: rm -rf .venv
shell: bash
- name: Build a binary wheel and a source tarball for test PyPi
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
- name: Create virtual environment for PyPi
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
echo "Waiting for 150 seconds to make sure package is available"
sleep 150
pip install --no-cache-dir sql-data-guard==${{ env.VERSION }}
pip install pytest
shell: bash
- name: Run unit tests with test PyPi package
# This step runs the unit tests with the test PyPi package, the src dir is not in the context
# This specific unit test file only uses public methods from the package
run: |
source .venv/bin/activate
python -m pytest --color=yes test/test_sql_guard_unit.py