Skip to content

Commit

Permalink
Update publish.yml to use Trusted Publishers
Browse files Browse the repository at this point in the history
  • Loading branch information
jaime-cespedes-sisniega authored and alvarolopez committed Sep 29, 2024
1 parent 2484916 commit c640980
Showing 1 changed file with 64 additions and 31 deletions.
95 changes: 64 additions & 31 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,70 @@ on:
release:
types: [published]

permissions:
contents: read

jobs:
publish:
runs-on: ubuntu-22.04
build:
name: Build distribution
runs-on: ubuntu-24.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build

- name: Store distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish to TestPyPI
runs-on: ubuntu-24.04
needs: build
environment:
name: testpypi
url: https://test.pypi.org/p/frouros
permissions:
id-token: write

steps:
- name: Download distribution packages
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 to PyPI
runs-on: ubuntu-24.04
needs: [build, publish-to-testpypi]
environment:
name: pypi
url: https://pypi.org/p/frouros
permissions:
id-token: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build

- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Download distribution packages
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 c640980

Please sign in to comment.