|
1 | | -name: Publish and Release |
| 1 | +name: Publish python package |
| 2 | + |
| 3 | +# description: |- A github reusable workflow to publish a python package to |
| 4 | +# pypi.org or test.pypi.org. |
| 5 | +# |
| 6 | +# Input options: |
| 7 | +# - `pypi: test.pypi`: Publish to test.pypi.org (default). |
| 8 | +# - `pypi: pypi`: Publish to pypi.org. |
| 9 | +# |
| 10 | +# The workflow invokes the github composite action |
| 11 | +# `glenn20/python-ci/publish@v1` to publish the package. |
| 12 | +# |
| 13 | +# Requirements: |
| 14 | +# 1. For trusted publishing, the publishing workflow must be in the project |
| 15 | +# repository, so copy this workflow file to |
| 16 | +# `.github/workflows/publish.yaml` in your repository. |
| 17 | +# 2. Create the `publish-test.pypi` and `publish-pypi` Environments in your |
| 18 | +# github repository (Settings->Environments->New Environment). |
| 19 | +# 3. Add this workflow as a "trusted publisher" on your pypi and test.pypi |
| 20 | +# project pages (add the name of the relevant Environment for additional |
| 21 | +# access control). |
| 22 | +# 4. Call this workflow from a parent workflow with the `pypi` input set to |
| 23 | +# "pypi" or "test.pypi" (default). |
| 24 | +# |
| 25 | +# Invoke with `uses: ./.github/workflows/publish@v1` |
2 | 26 |
|
3 | 27 | on: |
4 | | - release: |
5 | | - types: [published] |
| 28 | + workflow_call: |
| 29 | + inputs: |
| 30 | + pypi: |
| 31 | + description: 'Set to "pypi" or "test.pypi" (default).' |
| 32 | + default: 'test.pypi' |
| 33 | + required: false |
| 34 | + type: string |
6 | 35 |
|
7 | 36 | jobs: |
8 | 37 | build: |
9 | | - name: Build distribution |
10 | | - runs-on: ubuntu-latest |
11 | | - steps: |
12 | | - - name: Checkout repository |
13 | | - uses: actions/checkout@v4 |
14 | | - with: |
15 | | - fetch-depth: 0 # Fetch all history for tags for versioning |
16 | | - |
17 | | - |
18 | | - - name: Install uv |
19 | | - uses: astral-sh/setup-uv@v3 |
20 | | - with: |
21 | | - enable-cache: true |
22 | | - cache-dependency-glob: "uv.lock" |
23 | | - |
24 | | - - name: Set up Python |
25 | | - uses: actions/setup-python@v5 |
26 | | - with: |
27 | | - python-version-file: "pyproject.toml" |
28 | | - |
29 | | - - name: Install dependencies |
30 | | - run: uv sync --no-sources --all-extras --dev |
31 | | - |
32 | | - - name: Build |
33 | | - run: uv build --no-sources |
34 | | - |
35 | | - - name: Store the distribution packages |
36 | | - uses: actions/upload-artifact@v4 |
37 | | - with: |
38 | | - name: python-package-distributions |
39 | | - path: dist/ |
| 38 | + name: Build |
| 39 | + uses: glenn20/python-ci/.github/workflows/build.yaml@main |
| 40 | + permissions: |
| 41 | + id-token: none |
40 | 42 |
|
41 | 43 | publish: |
42 | | - name: Publish distribution |
| 44 | + name: Publish to ${{ inputs.pypi }} |
43 | 45 | needs: build |
44 | 46 | runs-on: ubuntu-latest |
45 | | - |
46 | 47 | environment: |
47 | | - name: release |
48 | | - url: https://pypi.org/p/mp-image-tool-esp32 |
| 48 | + name: publish-${{ inputs.pypi }} |
| 49 | + url: https://${{ inputs.pypi }}.org/p/${{ needs.build.outputs.package-name }} |
49 | 50 | permissions: |
50 | 51 | id-token: write # IMPORTANT: mandatory for trusted publishing |
51 | | - |
52 | | - steps: |
53 | | - - name: Download all the dists |
54 | | - uses: actions/download-artifact@v4 |
55 | | - with: |
56 | | - name: python-package-distributions |
57 | | - path: dist/ |
58 | | - |
59 | | - - name: Publish distribution to PyPI |
60 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
61 | | - |
62 | | - |
63 | | - github-release: |
64 | | - name: Sign the distribution and upload to GitHub Release |
65 | | - needs: publish |
66 | | - runs-on: ubuntu-latest |
67 | | - |
68 | | - permissions: |
69 | | - contents: write # IMPORTANT: mandatory for making GitHub Releases |
70 | | - id-token: write # IMPORTANT: mandatory for sigstore |
71 | | - |
72 | 52 | steps: |
73 | | - - name: Download all the dists |
74 | | - uses: actions/download-artifact@v4 |
| 53 | + - uses: glenn20/python-ci/publish@main |
75 | 54 | with: |
76 | | - name: python-package-distributions |
77 | | - path: dist/ |
78 | | - |
79 | | - - name: Sign the dists with Sigstore |
80 | | - |
81 | | - with: |
82 | | - inputs: >- |
83 | | - ./dist/*.tar.gz |
84 | | - ./dist/*.whl |
85 | | -
|
86 | | - - name: Create GitHub Release |
87 | | - env: |
88 | | - GITHUB_TOKEN: ${{ github.token }} |
89 | | - run: >- |
90 | | - gh release create |
91 | | - '${{ github.ref_name }}' |
92 | | - --repo '${{ github.repository }}' |
93 | | - --notes "" |
94 | | -
|
95 | | - - name: Upload artifact signatures to GitHub Release |
96 | | - env: |
97 | | - GITHUB_TOKEN: ${{ github.token }} |
98 | | - # Upload to GitHub Release using the `gh` CLI. |
99 | | - # `dist/` contains the built packages, and the |
100 | | - # sigstore-produced signatures and certificates. |
101 | | - run: >- |
102 | | - gh release upload |
103 | | - '${{ github.ref_name }}' dist/** |
104 | | - --repo '${{ github.repository }}' |
| 55 | + pypi: ${{ inputs.pypi }} |
0 commit comments