Skip to content

Commit

Permalink
add new workflow to publish on PyPI and generate releases on github
Browse files Browse the repository at this point in the history
  • Loading branch information
luclaurent committed Jan 4, 2025
1 parent bc972e9 commit 4741ac7
Showing 1 changed file with 163 additions and 0 deletions.
163 changes: 163 additions & 0 deletions .github/workflows/ci-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on:
workflow_run:
workflows: [CI-mac-os,CI-Ubuntu]
types: [completed]
# push:
# branches:
# - 'main'
# tags:
# - 'v*'

jobs:
allowrun:
name: Check if the workflow can be ran
runs-on: ubuntu-latest
outputs:
status: ${{ steps.info.outputs.status }}
steps:
- name: Check if head branch has version tag
uses: actions-ecosystem/action-regex-match@v2
id: regex-match
with:
text: ${{ github.event.workflow_run.head_branch }}
regex: '^v[0-9]+'
- name: Show info
id: info
run: |
echo ${{ steps.regex-match.outputs.match }}
echo "status=${{(github.event.workflow_run.conclusion == 'success') && (steps.regex-match.outputs.match != '') }}" >> "$GITHUB_OUTPUT"
build:
name: Build distribution 📦
needs: allowrun
runs-on: ubuntu-latest
if: ${{ needs.allowrun.outputs.status == 'true' }}
steps:
- name: Show event info
run: |
echo "value: ${{ needs.allowrun.outputs.status }}"
echo "Event info: ${{ toJson(github.event) }}"
echo "Workflow run info: ${{ toJson(github.event.workflow_run) }}"
echo "Workflow job info: ${{ github.event.workflow_run.head_branch }}"
- uses: actions/checkout@main
- name: Set up Python
uses: actions/setup-python@main
with:
python-version: "3.12"
- name: Install hatch
run: >-
python3 -m
pip install
hatch
--user
- name: Build a binary wheel and a source tarball
run: hatch build
- name: Store the distribution packages
uses: actions/upload-artifact@main
with:
name: python-package-distributions
path: dist/


github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- build
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@main
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
# - name: Release
# uses: softprops/action-gh-release@master
# if: startsWith(github.ref, 'refs/tags/')
# with:
# name: amc2moodle release ${{ github.event.release.tag_name }}
# prerelease: false
# files: dist/*
# env:
# GITHUB_TOKEN: ${{ github.token }}
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.event.workflow_run.head_branch }}'
--repo '${{ github.repository }}'
--generate-notes
--title 'amc2moodle ${{ github.event.workflow_run.head_branch }}'
## '${{ github.ref_name }}'
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.event.workflow_run.head_branch }}' dist/**
--repo '${{ github.repository }}'
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/amc2moodle

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
needs:
- publish-to-testpypi
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/amc2moodle # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

0 comments on commit 4741ac7

Please sign in to comment.