Skip to content

Publish to PyPI

Publish to PyPI #84

name: Publish to PyPI
on:
workflow_dispatch:
inputs:
dryRun:
description: 'Do a dry run to preview instead of a real release'
required: true
default: 'true'
jobs:
authorize:
name: Authorize
runs-on: ubuntu-latest
steps:
- name: ${{ github.actor }} permission check to do a release
uses: lannonbr/repo-permission-check-action@2bb8c89ba8bf115c4bfab344d6a6f442b24c9a1f # 2.0.2
with:
permission: "write"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-n-publish:
environment: Unit Test
name: Build and publish to PyPI
runs-on: ubuntu-latest
needs: [authorize]
permissions:
contents: write
id-token: write
steps:
- name: Checkout for release to PyPI
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
fetch-depth: 0
- name: Set up Python 3.8
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: 3.8
- name: Install dependencies
run: python -m pip install build setuptools wheel twine amplitude_analytics parameterized python-dotenv~=0.21.1
- name: Install requirements
run: pip install -r requirements.txt && pip install -r requirements-dev.txt
- name: Run Test
env:
API_KEY: ${{ secrets.API_KEY }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
EU_API_KEY: ${{ secrets.EU_API_KEY }}
EU_SECRET_KEY: ${{ secrets.EU_SECRET_KEY }}
run: python -m unittest discover -s ./tests -p '*_test.py'
- name: Python Semantic Release --dry-run
if: ${{ github.event.inputs.dryRun == 'true'}}
uses: python-semantic-release/python-semantic-release@350c48fcb3ffcdfd2e0a235206bc2ecea6b69df0 # v10.5.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
push: false
vcs_release: false
- name: Publish to Test PyPI
if: ${{ github.event.inputs.dryRun == 'true'}}
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
with:
repository-url: https://test.pypi.org/legacy/
- name: Python Semantic Release
if: ${{ github.event.inputs.dryRun == 'false'}}
uses: python-semantic-release/python-semantic-release@350c48fcb3ffcdfd2e0a235206bc2ecea6b69df0 # v10.5.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to PyPI
if: ${{ github.event.inputs.dryRun == 'false'}}
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0