Skip to content

Commit

Permalink
Add pypi trusted publishing (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Aug 18, 2023
1 parent 37358df commit 24851eb
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }}
cancel-in-progress: true

permissions:
contents: read
id-token: write

jobs:
build-wheels:
name: Wheel - ${{ matrix.os.name }} ${{ matrix.python.major-dot-minor }} ${{ matrix.arch.name }}
Expand Down Expand Up @@ -277,32 +281,17 @@ jobs:
name: packages
path: ./dist

- name: Test for secrets access
id: check_secrets
shell: bash
run: |
unset HAS_SECRET
if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi
echo "HAS_SECRET=${HAS_SECRET}" >>$GITHUB_OUTPUT
env:
SECRET: "${{ secrets.test_pypi_password }}"

- name: Install twine
run: pip install twine

- name: Publish distribution to PyPI
if: env.RELEASE == 'true' && steps.check_secrets.outputs.HAS_SECRET
env:
TWINE_USERNAME: __token__
TWINE_NON_INTERACTIVE: 1
TWINE_PASSWORD: ${{ secrets.pypi_password }}
run: twine upload --non-interactive --skip-existing --verbose 'dist/*'
if: env.RELEASE == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
skip-existing: true

- name: Publish distribution to Test PyPI
if: env.PRE_RELEASE == 'true' && steps.check_secrets.outputs.HAS_SECRET
env:
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
TWINE_USERNAME: __token__
TWINE_NON_INTERACTIVE: 1
TWINE_PASSWORD: ${{ secrets.test_pypi_password }}
run: twine upload --non-interactive --skip-existing --verbose 'dist/*'
if: env.PRE_RELEASE == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: dist/
skip-existing: true

0 comments on commit 24851eb

Please sign in to comment.