Skip to content

PyPI publishing

PyPI publishing #18

Workflow file for this run

# Builds a Python package and publish it to PyPI when a new tag is
# created.
name: PyPI publishing
on:
# Runs on creating a new tag starting with 'v', e.g. 'v1.0.3'
push:
tags: ['v*']
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
pypi-publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Check-out repository
uses: actions/checkout@v6
with:
fetch-depth: 0 # full history with tags to get the version number by versioningit
- name: Git state after checkout
run: |
git status --short
git describe --tags --dirty --always
- name: Set up pixi
uses: ./.github/actions/setup-pixi
- name: Git state after Pixi setup
run: |
git status --short
git diff --stat
git describe --tags --dirty --always
# Build the Python package (to dist/ folder)
- name: Create Python package
run: pixi run --frozen default-build
- name: Git state after build
run: |
git status --short
git diff --stat
git describe --tags --dirty --always
# Publish the package to PyPI (from dist/ folder)
# Instead of publishing with personal access token, we use
# GitHub Actions OIDC to get a short-lived token from PyPI.
# New publisher must be previously configured in PyPI at
# https://pypi.org/manage/project/easydiffraction/settings/publishing/
# Use the following data:
# Owner: easyscience
# Repository name: diffraction-lib
# Workflow name: pypi-publish.yml
- name: Publish to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: 'dist'