Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: github workflow release #2127

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Build and Publish Python Package

on:
workflow_dispatch:
inputs:
version:
description: 'Version to release'
required: true
type: string
push:
branches:
- 'release/[0-9]+.[0-9]+.[0-9]+'
- 'hotfix/[0-9]+.[0-9]+.[0-9]+'

jobs:
build:
name: Build Python distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build wheel twine

- name: Build package
run: python setup.py sdist bdist_wheel

- name: Check if package version already exists
run: |
PACKAGE_NAME=$(python setup.py --name)
PACKAGE_VERSION=${{ github.event.inputs.version }}
if twine check dist/*; then
if pip install $PACKAGE_NAME==$PACKAGE_VERSION; then
echo "Error: Version $PACKAGE_VERSION of $PACKAGE_NAME already exists on PyPI"
exit 1
else
echo "Version $PACKAGE_VERSION of $PACKAGE_NAME does not exist on PyPI. Proceeding with upload."
fi
else
echo "Error: Twine check failed."
exit 1
fi

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/

approve-and-publish:
needs: build
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
id-token: write

steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: dist
path: dist/

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
print-hash: true