|
| 1 | +# This workflow will upload a Python Package using Twine when a release is created |
| 2 | +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries |
| 3 | + |
| 4 | +# This workflow uses actions that are not certified by GitHub. |
| 5 | +# They are provided by a third-party and are governed by |
| 6 | +# separate terms of service, privacy policy, and support |
| 7 | +# documentation. |
| 8 | + |
| 9 | +name: Upload Python Package |
| 10 | + |
1 | 11 | on: |
2 | 12 | release: |
3 | | - types: |
4 | | - - published |
| 13 | + types: [published] |
| 14 | + push: |
| 15 | + branches: |
| 16 | + - main |
5 | 17 |
|
6 | | -name: release |
| 18 | +permissions: |
| 19 | + contents: write |
7 | 20 |
|
8 | 21 | jobs: |
9 | | - pypi: |
10 | | - name: upload release to PyPI |
| 22 | + deploy: |
| 23 | + defaults: |
| 24 | + run: |
| 25 | + working-directory: ./src/python/ |
| 26 | + |
11 | 27 | runs-on: ubuntu-latest |
12 | | - permissions: |
13 | | - id-token: write |
| 28 | + |
14 | 29 | steps: |
15 | | - - uses: actions/checkout@v3 |
16 | | - |
17 | | - - uses: actions/setup-python@v4 |
18 | | - with: |
19 | | - python-version: "3.x" |
20 | | - |
21 | | - - name: deps |
22 | | - run: python -m pip install -U build |
23 | | - |
24 | | - - name: build |
25 | | - run: python -m build |
26 | | - |
27 | | - - name: mint API token |
28 | | - id: mint-token |
29 | | - run: | |
30 | | - # retrieve the ambient OIDC token |
31 | | - resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ |
32 | | - "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi") |
33 | | - oidc_token=$(jq -r '.value' <<< "${resp}") |
34 | | -
|
35 | | - # exchange the OIDC token for an API token |
36 | | - resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}") |
37 | | - api_token=$(jq -r '.token' <<< "${resp}") |
38 | | -
|
39 | | - # mask the newly minted API token, so that we don't accidentally leak it |
40 | | - echo "::add-mask::${api_token}" |
41 | | -
|
42 | | - # see the next step in the workflow for an example of using this step output |
43 | | - echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}" |
44 | | -
|
45 | | - - name: publish |
46 | | - # gh-action-pypi-publish uses TWINE_PASSWORD automatically |
47 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
48 | | - with: |
49 | | - password: ${{ steps.mint-token.outputs.api-token }} |
50 | | - |
51 | | - - name: Commit version |
52 | | - run: | |
53 | | - # commit incremented version |
54 | | - git config --global user.email "vishrant.gupta@gmail.com" |
55 | | - git config --global user.name "Vishrant Gupta" |
56 | | - |
57 | | - git add version.txt |
58 | | - |
59 | | - git commit -m "[skip ci] Incrementing version" |
60 | | - git push |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + ref: main |
| 34 | + |
| 35 | + - name: Set up Python |
| 36 | + uses: actions/setup-python@v3 |
| 37 | + with: |
| 38 | + python-version: '3.x' |
| 39 | + |
| 40 | + - name: Install dependencies |
| 41 | + run: | |
| 42 | + python -m pip install --upgrade pip |
| 43 | + python -m pip install --upgrade Pillow numpy filetype setuptools wheel twine build semver |
| 44 | +
|
| 45 | + # install project dependencies |
| 46 | + pip install -r requirements.txt |
| 47 | +
|
| 48 | + - name: Build package |
| 49 | + run: | |
| 50 | +
|
| 51 | + python setup.py sdist bdist_wheel |
| 52 | +
|
| 53 | + pwd |
| 54 | + ls -lart ./ dist/ build/ |
| 55 | +
|
| 56 | + - name: Publish package |
| 57 | + run: | |
| 58 | + |
| 59 | + token="$api_token" |
| 60 | + twine upload --username __token__ --password $token dist/* |
| 61 | +
|
| 62 | + - name: Commit version |
| 63 | + run: | |
| 64 | + # commit incremented version |
| 65 | + git config --global user.email "vishrant.gupta@gmail.com" |
| 66 | + git config --global user.name "Vishrant Gupta" |
| 67 | +
|
| 68 | + git add version.txt |
| 69 | +
|
| 70 | + git commit -m "[skip ci] Incrementing version" |
| 71 | + git push |
0 commit comments