Skip to content

Commit 69692b3

Browse files
Update Publishing Workflow (#1389)
* Update packaging workflow to use trusted publishing and python build. * Add github attestations * Rename deploy file * Clean up tarball file name scripting * Move permissions block to top level --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent a32bb4e commit 69692b3

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

.github/workflows/deploy-python.yml renamed to .github/workflows/deploy.yml

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ on:
1919
types:
2020
- published
2121

22+
permissions:
23+
contents: read
24+
2225
jobs:
2326
build-linux-py3-legacy:
2427
runs-on: ubuntu-24.04
@@ -110,18 +113,22 @@ jobs:
110113
persist-credentials: false
111114
fetch-depth: 0
112115

116+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # 5.6.0
117+
with:
118+
python-version: "3.12"
119+
113120
- name: Install Dependencies
114121
run: |
115122
pip install -U pip
116-
pip install -U setuptools packaging
123+
pip install -U build
117124
118125
- name: Build Source Package
119126
run: |
120-
python setup.py sdist
127+
python -m build --sdist
121128
122129
- name: Prepare MD5 Hash File
123130
run: |
124-
tarball="$(python setup.py --fullname).tar.gz"
131+
tarball="$(basename ./dist/*.tar.gz)"
125132
md5_file="${tarball}.md5"
126133
openssl md5 -binary "dist/${tarball}" | xxd -p | tr -d '\n' > "dist/${md5_file}"
127134
@@ -135,58 +142,46 @@ jobs:
135142
if-no-files-found: error
136143
retention-days: 1
137144

138-
deploy:
145+
publish:
139146
runs-on: ubuntu-24.04
147+
environment: pypi
148+
permissions:
149+
contents: read
150+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
151+
attestations: write
140152

141153
needs:
142154
- build-linux-py3-legacy
143155
- build-linux-py3
144156
- build-sdist
145157

146158
steps:
147-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
148-
with:
149-
persist-credentials: false
150-
fetch-depth: 0
151-
152-
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # 5.6.0
153-
with:
154-
python-version: "3.x"
155-
architecture: x64
156-
157-
- name: Install Dependencies
158-
run: |
159-
pip install -U pip
160-
pip install -U wheel setuptools packaging twine
161-
162-
- name: Download Artifacts
163-
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # 4.3.0@95815c38cf2ff2164869cbab79da8d1f422bc89e # 4.3.0
159+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # 4.3.0
164160
with:
165-
path: ./artifacts/
166-
167-
- name: Unpack Artifacts
168-
run: |
169-
mkdir -p dist/
170-
mv artifacts/**/*{.whl,.tar.gz,.tar.gz.md5} dist/
161+
path: ./dist/
162+
merge-multiple: true
171163

172164
- name: Upload Package to S3
173165
run: |
174-
tarball="$(python setup.py --fullname).tar.gz"
166+
tarball="$(basename ./dist/*.tar.gz)"
175167
md5_file="${tarball}.md5"
176168
aws s3 cp "dist/${md5_file}" "${S3_DST}/${md5_file}"
177169
aws s3 cp "dist/${tarball}" "${S3_DST}/${tarball}"
170+
rm "dist/${md5_file}"
178171
env:
179172
S3_DST: s3://nr-downloads-main/python_agent/release
180173
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
181174
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
182175
AWS_DEFAULT_REGION: us-west-2
183176

184-
- name: Upload Package to PyPI
185-
run: |
186-
twine upload --non-interactive dist/*.tar.gz dist/*.whl
187-
env:
188-
TWINE_USERNAME: __token__
189-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
177+
- name: Upload Package
178+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # 1.12.4
179+
180+
- name: Attest
181+
uses: actions/attest-build-provenance@db473fddc028af60658334401dc6fa3ffd8669fd # 2.3.0
182+
id: attest
183+
with:
184+
subject-path: ./dist/*
190185

191186
- name: Wait for release to be available
192187
id: wait

0 commit comments

Comments
 (0)