Skip to content

Commit 643afa2

Browse files
authored
ci: use trusted publisher instead of token flow (#1874)
* ci: use trusted publisher instead of token auth Signed-off-by: Adrien Mannocci <[email protected]> * ci: backport changes to release workflow Signed-off-by: Adrien Mannocci <[email protected]> * ci: build also source distribution Signed-off-by: Adrien Mannocci <[email protected]> --------- Signed-off-by: Adrien Mannocci <[email protected]>
1 parent 0eaa44a commit 643afa2

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

.github/workflows/packages.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
run: pip install --user wheel
2626
- name: Building universal wheel
2727
run: python setup.py bdist_wheel
28+
- name: Building source distribution
29+
run: python setup.py sdist
2830
- name: Upload Packages
2931
uses: actions/upload-artifact@v3
3032
with:

.github/workflows/release.yml

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,19 @@ jobs:
2020
- test
2121
- packages
2222
runs-on: ubuntu-latest
23-
env:
24-
PYPI_SECRET_PATH: secret/apm-team/ci/apm-agent-python-pypi-prod
23+
environment: release
24+
permissions:
25+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
2526
steps:
2627
- uses: actions/checkout@v3
27-
- uses: hashicorp/[email protected]
28-
with:
29-
url: ${{ secrets.VAULT_ADDR }}
30-
method: approle
31-
roleId: ${{ secrets.VAULT_ROLE_ID }}
32-
secretId: ${{ secrets.VAULT_SECRET_ID }}
33-
secrets: |
34-
${{ env.PYPI_SECRET_PATH }} user | TWINE_USER ;
35-
${{ env.PYPI_SECRET_PATH }} password | TWINE_PASSWORD
3628
- uses: actions/download-artifact@v3
3729
with:
3830
name: packages
3931
path: dist
4032
- name: Upload
41-
run: |
42-
python -m pip install --user twine
43-
python setup.py sdist
44-
echo "Uploading to ${REPO_URL} with user ${TWINE_USER}"
45-
python -m twine upload --username "${TWINE_USER}" --password "${TWINE_PASSWORD}" --skip-existing --repository-url ${REPO_URL} dist/*.tar.gz
46-
python -m twine upload --username "${TWINE_USER}" --password "${TWINE_PASSWORD}" --skip-existing --repository-url ${REPO_URL} dist/*.whl
47-
env:
48-
REPO_URL: "https://upload.pypi.org/legacy/"
33+
uses: pypa/gh-action-pypi-publish@f5622bde02b04381239da3573277701ceca8f6a0
34+
with:
35+
repository-url: https://upload.pypi.org/legacy/
4936

5037
build-distribution:
5138
uses: ./.github/workflows/build-distribution.yml
@@ -56,7 +43,7 @@ jobs:
5643
runs-on: ubuntu-latest
5744
steps:
5845
- uses: actions/checkout@v3
59-
- uses: hashicorp/vault-action@v2.5.0
46+
- uses: hashicorp/vault-action@v2.7.2
6047
with:
6148
url: ${{ secrets.VAULT_ADDR }}
6249
method: approle
@@ -74,7 +61,7 @@ jobs:
7461
# Convert v1.2.3 to ver-1-2-3
7562
VERSION=${GITHUB_REF_NAME/v/ver-}
7663
VERSION=${VERSION//./-}
77-
64+
7865
ELASTIC_LAYER_NAME="elastic-apm-python-${VERSION}" .ci/publish-aws.sh
7966
- uses: actions/upload-artifact@v3
8067
with:
@@ -113,7 +100,7 @@ jobs:
113100
.
114101
- name: Docker retag
115102
run: >-
116-
docker tag
103+
docker tag
117104
${{ steps.setup-docker.outputs.name }}:${{ steps.setup-docker.outputs.tag }}
118105
${{ steps.setup-docker.outputs.name }}:latest
119106
- name: Docker push
@@ -133,7 +120,7 @@ jobs:
133120
with:
134121
name: arn-file
135122
- name: Create GitHub Draft Release
136-
run: >-
123+
run: >-
137124
gh release create "${GITHUB_REF_NAME}"
138125
--title="${GITHUB_REF_NAME}"
139126
--generate-notes

0 commit comments

Comments
 (0)