TensorHue v0.1.0-alpha #20
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will upload a Python Package using Twine when a release is created | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
name: Release python package on PyPi | |
on: | |
release: | |
types: [published] | |
permissions: | |
contents: read | |
jobs: | |
pypi-publish: | |
runs-on: ubuntu-latest | |
environment: release | |
permissions: | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.x | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build | |
- name: Check version consistency | |
run: | | |
import re | |
import sys | |
import os | |
# Read the version from tensorhue/__init__.py | |
with open('tensorhue/__init__.py') as f: | |
content = f.read() | |
match = re.search(r'__version__\s*=\s*["\']([^"\']+)["\']', content) | |
if match: | |
version = match.group(1) | |
else: | |
print("Could not find __version__ in tensorhue/__init__.py") | |
sys.exit(1) | |
# Extract the version from the GitHub release tag | |
github_ref = os.environ.get('GITHUB_REF') | |
if github_ref.startswith('refs/tags/'): | |
release_version = github_ref.split('/')[-1] | |
if release_version.startswith('v'): | |
release_version = release_version[1:] # Remove 'v' prefix | |
if release_version != version: | |
print(f"Version mismatch: GitHub release {release_version} != Package version {version}") | |
sys.exit(1) | |
print(f"Version {version} matches GitHub release tag (without 'v' prefix).") | |
else: | |
print("Not a release tag, skipping version check.") | |
shell: python | |
- name: Build package | |
run: python -m build | |
- name: Publish package on PyPi | |
uses: pypa/gh-action-pypi-publish@release/v1 |