Skip to content

Publish Python package #1

Publish Python package

Publish Python package #1

Workflow file for this run

name: Publish Python package
on:
workflow_dispatch:
inputs:
target:
description: "Publish target"
required: true
type: choice
options:
- testpypi
- pypi
default: testpypi
release:
types: [published]
jobs:
build:
name: Build distributions
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- uses: actions/setup-node@v4
with:
node-version: "22"
- name: Install build tooling
run: |
python -m pip install --upgrade pip
python -m pip install ".[dev]" twine
- name: Ruff
run: python -m ruff check .
- name: Type check
run: python -m mypy
- name: Test
run: python -m pytest
- name: Coverage
run: python -m pytest --cov=codex_usage_tracker --cov-report=term-missing
- name: Compile
run: python -m compileall src
- name: Dashboard JavaScript syntax
run: |
node --check src/codex_usage_tracker/plugin_data/dashboard/dashboard_format.js
node --check src/codex_usage_tracker/plugin_data/dashboard/dashboard_data.js
node --check src/codex_usage_tracker/plugin_data/dashboard/dashboard.js
node --check src/codex_usage_tracker/plugin_data/dashboard/dashboard_state.js
- name: Release readiness
run: python scripts/check_release.py
- name: Whitespace
run: git diff --check
- name: Build wheel and sdist
run: |
rm -rf dist build *.egg-info src/*.egg-info
python -m build
python -m twine check dist/*
python scripts/check_release.py --dist
- name: Show distribution files
run: |
ls -la dist
python - <<'PY'
from pathlib import Path
import hashlib
for path in sorted(Path("dist").iterdir()):
digest = hashlib.sha256(path.read_bytes()).hexdigest()
print(f"{digest} {path}")
PY
- name: Upload dist artifacts
uses: actions/upload-artifact@v4
with:
name: python-dist
path: dist/*
if-no-files-found: error
publish-testpypi:
name: Publish to TestPyPI
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi'
environment:
name: testpypi
url: https://test.pypi.org/project/codex-usage-tracking/
permissions:
id-token: write
steps:
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: python-dist
path: dist
- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
print-hash: true
publish-pypi:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.target == 'pypi')
environment:
name: pypi
url: https://pypi.org/project/codex-usage-tracking/
permissions:
id-token: write
steps:
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: python-dist
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true