|
1 |
| -# Triggers a pypi publication when a release is created |
2 |
| - |
3 | 1 | name: Publish Python Package
|
4 | 2 |
|
5 | 3 | on:
|
6 |
| - release: |
7 |
| - types: [created] |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: 'Release Tag' |
| 8 | + required: true |
8 | 9 |
|
9 | 10 | jobs:
|
10 | 11 | build:
|
11 | 12 | runs-on: ubuntu-latest
|
| 13 | + outputs: |
| 14 | + hashes: ${{ steps.hash.outputs.hashes }} |
12 | 15 | steps:
|
13 |
| - - uses: actions/checkout@v4 |
14 |
| - |
15 |
| - - uses: actions/setup-python@v5 |
16 |
| - with: |
17 |
| - python-version: '3.x' |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + ref: ${{ inputs.tag }} |
| 19 | + - name: Set up Python |
| 20 | + uses: actions/setup-python@v5 |
| 21 | + with: |
| 22 | + python-version: '3.x' |
| 23 | + - name: Install dependencies |
| 24 | + run: | |
| 25 | + python -m pip install --upgrade pip |
| 26 | + pip install setuptools wheel twine |
| 27 | + - name: Build |
| 28 | + run: | |
| 29 | + python setup.py sdist bdist_wheel |
| 30 | + - name: "Generate hashes" |
| 31 | + id: hash |
| 32 | + run: | |
| 33 | + cd dist && echo "hashes=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT |
| 34 | + - uses: actions/upload-artifact@v4 |
| 35 | + with: |
| 36 | + name: build |
| 37 | + path: ./dist |
18 | 38 |
|
19 |
| - - name: Install dependencies |
20 |
| - run: | |
21 |
| - python -m pip install --upgrade pip |
22 |
| - pip install setuptools wheel |
23 |
| -
|
24 |
| - - name: Build |
25 |
| - run: | |
26 |
| - python setup.py sdist bdist_wheel |
27 |
| - |
28 |
| - - uses: actions/upload-artifact@v4 |
29 |
| - with: |
30 |
| - path: ./dist |
| 39 | + provenance_python: |
| 40 | + needs: [build] |
| 41 | + permissions: |
| 42 | + actions: read |
| 43 | + contents: write |
| 44 | + id-token: write # Needed to access the workflow's OIDC identity. |
| 45 | + uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.0.0 |
| 46 | + with: |
| 47 | + base64-subjects: "${{ needs.build.outputs.hashes }}" |
| 48 | + upload-assets: true |
| 49 | + upload-tag-name: ${{ inputs.tag }} # Tag from the initiation of the workflow |
31 | 50 |
|
32 |
| - pypi-publish: |
33 |
| - needs: ['build'] |
34 |
| - environment: |
35 |
| - name: publish |
36 |
| - url: 'https://pypi.org/project/labelboxbigquery/' |
| 51 | + publish-python-package-to-release: |
37 | 52 | runs-on: ubuntu-latest
|
| 53 | + needs: ['build'] |
38 | 54 | permissions:
|
39 |
| - # IMPORTANT: this permission is mandatory for trusted publishing |
40 |
| - id-token: write |
| 55 | + contents: write |
41 | 56 | steps:
|
| 57 | + - uses: actions/checkout@v4 |
| 58 | + with: |
| 59 | + ref: ${{ inputs.tag }} |
42 | 60 | - uses: actions/download-artifact@v4
|
43 |
| - |
44 |
| - - name: Publish package distributions to PyPI |
45 |
| - uses: pypa/gh-action-pypi-publish@release/v1.8 |
46 | 61 | with:
|
47 |
| - packages-dir: artifact/ |
48 |
| - |
49 |
| -# Note that the build and pypi-publish jobs are split so that the additional permissions are only granted to the pypi-publish job. |
| 62 | + name: build |
| 63 | + path: ./artifact |
| 64 | + - name: Upload dist to release |
| 65 | + run: | |
| 66 | + gh release upload ${{ inputs.tag }} ./artifact/* |
| 67 | + env: |
| 68 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments