See Ash Code logo See Ash Code

Publishing my Python package needed its own workflow

Ashlynn Antrobus
• • 3 min read

Building ebook2text on my computer and publishing it to PyPI are different jobs. My computer has the tools and files I’ve accumulated while working on the project. A GitHub Actions runner starts with a checkout and whatever I tell the workflow to install.

A dragon wraps a parcel at a worktable near a separate post office counter.

Illustration: preparing a package and sending it are separate steps.

On December 5, I added a release workflow. Several follow-up commits that evening dealt with the parts around the build command.

The trigger comes first

The new workflow runs when I push a tag whose name starts with v:

on:
  push:
    tags:
      - 'v*'

That gives the release a deliberate starting point. An ordinary code push doesn’t match this trigger. A matching tag does.

I still have to make the tag and the package version agree. The pattern doesn’t inspect the version in my package metadata; it selects which Git events start the job.

The first version of the job checked out the code, selected Python using .python-version, installed uv, synchronized dependencies, built the project, and published it. Before the evening was over, I removed the separate Python setup and dependency synchronization steps. The revised workflow uses uv for the build and publish operations.

I don’t need to copy my entire development setup into a release job just because that is the setup I use while writing code. I do need the job to have everything its remaining commands require.

The files have to reach the runner

The uv setup step enabled caching and named uv.lock as the dependency file to watch. Another change that evening removed the lockfile from .gitignore so it could be tracked.

That is an easy distinction to miss while working locally. A file on my disk can help a command succeed without ever being part of the checkout that the workflow receives. Naming the file in YAML doesn’t put it in Git.

The release steps themselves are short:

- name: Build project
  run: uv build

- name: Publish to PyPI
  run: uv publish

The first command produces distributions. The second sends distributions to the package index. Building successfully gets me as far as having something to upload. The upload still has its own requirements.

The runner needs an identity

The last workflow change in this sequence added:

environment: pypi
permissions:
  id-token: write

The permission allows the job to request an identity token. It doesn’t give every command permission to write arbitrary repository files, and it isn’t itself a PyPI password.

With trusted publishing, PyPI checks an identity associated with a configured publisher. Its 2023 introduction describes matching the GitHub repository and workflow, with an optional environment restriction. The workflow side and the package-index side have to agree.

That explains why publishing has more setup than building. Creating an archive is local work. Accepting that archive as a release of my package requires the destination to recognize the job.

A release job still needs checks

This workflow describes how to build and upload. There isn’t a test command between those steps in the December revision.

In my Python compatibility post, I looked at the gap between a package declaration and testing the behavior it promises. A release workflow has the same limit. Giving it a tag trigger and publishing permissions doesn’t test conversion output or compatibility across interpreters.

A successful upload can distribute a broken package just as efficiently as a working one.

AA

Written by Ashlynn Antrobus

Software developer, author, and builder. Sharing technical lessons learned from building tools like Ebook2Text, IndexedDict, and rag-mcp, and navigating life as a programmer with dyslexia.