Skip to content

Improve publishing

Improve publishing #15

Workflow file for this run

name: Latest commit
env:
CACHE_VERSION: 1
DEFAULT_PYTHON: "3.13"
PRE_COMMIT_HOME: ~/.cache/pre-commit
VENV: venv
on:
schedule:
- cron: "2 4 * * 0" # weekly
workflow_dispatch:
push:
# pull_request:
jobs:
# Check shellscripts
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- name: Check out committed code
uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
test-publishing:
name: Build and publish Python 🐍 distributions 📦 to TestPyPI
runs-on: ubuntu-latest
environment: testpypi
permissions:
id-token: write
steps:
- name: Check out committed code
uses: actions/checkout@v4
- name: Prepare uv
run: |
pip install uv
uv venv --seed venv
. venv/bin/activate
uv pip install toml
- name: Check for existing package on TestPyPI
id: check_package
run: |
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION"
if curl -sI "https://test.pypi.org/project/$PACKAGE_NAME/$PACKAGE_VERSION/" | head -n 1 | grep "HTTP/1.1 200 OK"; then
echo "Package version already exists. Skipping upload."
echo "::set-output name=should_publish::false"
else
echo "Package version does not exist. Proceeding with upload."
echo "::set-output name=should_publish::true"
fi
- name: Build
if: steps.check_package.outputs.should_publish == 'true'
run: |
. venv/bin/activate
uv build
- name: Publish distribution 📦 to TestPyPI
if: steps.check_package.outputs.should_publish == 'true'
run: |
. venv/bin/activate
uv publish --publish-url https://test.pypi.org/legacy/