refac
Some checks failed
Build Docker Image / build (linux/amd64, map[file:Dockerfile name:default short_tag:latest suffix:]) (push) Has been cancelled
Build Docker Image / build (linux/amd64, map[file:Dockerfile.alpine name:alpine short_tag:alpine suffix:-alpine]) (push) Has been cancelled
Build Docker Image / build (linux/amd64, map[file:Dockerfile.slim name:slim short_tag:slim suffix:-slim]) (push) Has been cancelled
Build Docker Image / build (linux/arm64, map[file:Dockerfile name:default short_tag:latest suffix:]) (push) Has been cancelled
Build Docker Image / build (linux/arm64, map[file:Dockerfile.alpine name:alpine short_tag:alpine suffix:-alpine]) (push) Has been cancelled
Build Docker Image / build (linux/arm64, map[file:Dockerfile.slim name:slim short_tag:slim suffix:-slim]) (push) Has been cancelled
Publish to PyPI / build (push) Has been cancelled
Release / release (push) Has been cancelled
Build Docker Image / merge (map[name:alpine short_tag:alpine suffix:-alpine]) (push) Has been cancelled
Build Docker Image / merge (map[name:default short_tag:latest suffix:]) (push) Has been cancelled
Build Docker Image / merge (map[name:slim short_tag:slim suffix:-slim]) (push) Has been cancelled
Publish to PyPI / publish (push) Has been cancelled

This commit is contained in:
Timothy Jaeryang Baek 2026-09-06 17:36:00 -04:00
parent 38d6a2b8b6
commit 6696428e36

84
.github/workflows/pypi.yml vendored Normal file
View file

@ -0,0 +1,84 @@
name: Publish to PyPI
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: pypi-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
build:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
publish_needed: ${{ steps.check.outputs.publish_needed }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Check if version already on PyPI
id: check
run: |
python - <<'PY'
import os
import tomllib
import urllib.error
import urllib.request
with open("pyproject.toml", "rb") as source:
project = tomllib.load(source)["project"]
name, version = project["name"], project["version"]
exists = False
try:
with urllib.request.urlopen(f"https://pypi.org/pypi/{name}/{version}/json", timeout=15):
exists = True
except urllib.error.HTTPError as exc:
if exc.code != 404:
raise
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
output.write(f"publish_needed={'false' if exists else 'true'}\n")
print(f"{name} {version} {'already exists on PyPI, skipping publish' if exists else 'is not on PyPI'}")
PY
- name: Build distributions
if: steps.check.outputs.publish_needed == 'true'
run: |
python -m pip install build
python -m build
- uses: actions/upload-artifact@v4
if: steps.check.outputs.publish_needed == 'true'
with:
name: dist
path: dist/
if-no-files-found: error
publish:
needs: build
if: needs.build.outputs.publish_needed == 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
# Configure a trusted publisher at:
# https://pypi.org/manage/project/open-terminal/settings/publishing/
# Owner: open-webui; repository: open-terminal;
# workflow: pypi.yml; environment: pypi.
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1