Skip to content

Commit 789b784

Browse files
authored
Migrate PyPi publishing to Trusted Publishers and environments (#20376)
* Migrate PyPi publishing to Trusted Publishers and environments * Add comments to clarify the OIDC workflow
1 parent 955e53d commit 789b784

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

.github/workflows/build-ddev.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ jobs:
579579

580580
permissions:
581581
contents: write
582+
id-token: write
583+
584+
environment: pypi-ddev
582585

583586
steps:
584587
- name: Download Python artifacts
@@ -601,12 +604,15 @@ jobs:
601604
path: installers
602605
merge-multiple: true
603606

607+
# Publish wheels to PyPI using Trusted Publishers.
608+
# https://docs.pypi.org/trusted-publishers/using-a-publisher/
609+
# This job needs to run from within the pypi-ddev environment. PyPi validates the
610+
# workflow file name, environment and repository the request is comming from to
611+
# provide the valid JWT token.
604612
- name: Push Python artifacts to PyPI
605613
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
606614
with:
607615
skip-existing: true
608-
user: __token__
609-
password: ${{ secrets.PYPI_TOKEN_DDEV_2 }}
610616

611617
- name: Add assets to current release
612618
uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631 # v2.2.2

.github/workflows/claim-pypi-name.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
name: Build wheel
2222
runs-on: ubuntu-latest
2323

24+
environment: typo-squatting-release
25+
2426
steps:
2527
- name: Checkout code
2628
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -46,4 +48,4 @@ jobs:
4648
# Only uploading the missing wheels makes this job idempotent and reduces its complexity.
4749
skip-existing: true
4850
user: __token__
49-
password: ${{ secrets.INTEGRATIONS_PYPI_NAME_CLAIM }}
51+
password: ${{ secrets.PYPI_TOKEN }}

.github/workflows/release-base.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ jobs:
99
release:
1010
runs-on: ubuntu-latest
1111

12+
permissions:
13+
id-token: write
14+
15+
environment: pypi-datadog-checks-base
16+
1217
steps:
1318
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1419

@@ -30,8 +35,16 @@ jobs:
3035
ddev config set repos.core .
3136
ddev config set repo core
3237
33-
- name: Release base package
34-
run: ddev release upload -s datadog_checks_base
35-
env:
36-
TWINE_USERNAME: __token__
37-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN_BASE_2 }}
38+
- name: Build base package
39+
run: ddev release build datadog_checks_base
40+
41+
# Publish wheels to PyPI using Trusted Publishers.
42+
# https://docs.pypi.org/trusted-publishers/using-a-publisher/
43+
# This job needs to run from within the pypi-datadog-checks-base environment. PyPi
44+
# validates the workflow file name, environment and repository the request is
45+
# comming from to provide the valid JWT token.
46+
- name: Release base package to PyPI
47+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
48+
with:
49+
skip-existing: true
50+
packages-dir: datadog_checks_base/dist

.github/workflows/release-dev.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ jobs:
99
release:
1010
runs-on: ubuntu-latest
1111

12+
permissions:
13+
id-token: write
14+
15+
environment: pypi-datadog-checks-dev
16+
1217
steps:
1318
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1419

@@ -30,8 +35,16 @@ jobs:
3035
ddev config set repos.core .
3136
ddev config set repo core
3237
33-
- name: Release dev package
34-
run: ddev release upload -s datadog_checks_dev
35-
env:
36-
TWINE_USERNAME: __token__
37-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN_DEV_2 }}
38+
- name: Build dev package
39+
run: ddev release build datadog_checks_dev
40+
41+
# Publish wheels to PyPI using Trusted Publishers.
42+
# https://docs.pypi.org/trusted-publishers/using-a-publisher/
43+
# This job needs to run from within the pypi-datadog-checks-dev environment. PyPi
44+
# validates the workflow file name, environment and repository the request is
45+
# comming from to provide the valid JWT token.
46+
- name: Release dev package to PyPI
47+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
48+
with:
49+
skip-existing: true
50+
packages-dir: datadog_checks_dev/dist

0 commit comments

Comments
 (0)