From 4003151430d162dde2ccaaa64efc944c697a2183 Mon Sep 17 00:00:00 2001 From: Max Rakitin Date: Tue, 13 Jan 2026 15:17:45 -0500 Subject: [PATCH] CI: PyPI release workflow based on OIDC --- .github/workflows/python-publish.yml | 77 ++++++++++++++++++---------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 934d467..d653256 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -1,35 +1,58 @@ -# This workflows will upload a Python Package using flit when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -name: Upload Python Package +name: CD on: - release: - types: [created] + workflow_dispatch: + pull_request: + push: branches: - - master + - main + release: + types: + - published + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + # Many color libraries just need this to be set to any value, but at least + # one distinguishes color depth, where "3" -> "256-bit color". + FORCE_COLOR: 3 jobs: - deploy: - if: github.repository_owner == 'NSLS-II-HXN' + dist: + name: Distribution build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - uses: hynek/build-and-inspect-python-package@v2 + + publish: + needs: [dist] + name: Publish to PyPI + environment: pypi + permissions: + id-token: write + attestations: write + contents: read runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install wheel twine setuptools - - name: Build and publish - env: - TWINE_USERNAME: __token__ - # The PYPI_PASSWORD must be a pypi token with the "pypi-" prefix with sufficient permissions to upload this package - # https://pypi.org/help/#apitoken - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + - uses: actions/download-artifact@v7 + with: + name: Packages + path: dist + + - name: Generate artifact attestation for sdist and wheel + uses: actions/attest-build-provenance@v3 + with: + subject-path: "dist/*" + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: ./dist/