Skip to content

Commit 0fd2a7a

Browse files
committed
Use official action to publish package in CI
This enables trusted publishing (with attestations).
1 parent 81b4c07 commit 0fd2a7a

File tree

5 files changed

+297
-111
lines changed

5 files changed

+297
-111
lines changed

.github/workflows/build_wheels_macos.yml

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ jobs:
153153
needs: [Build, Test]
154154
runs-on: ubuntu-22.04
155155
environment: opencv-python-rolling-release
156+
permissions:
157+
contents: read
158+
id-token: write
156159
defaults:
157160
run:
158161
shell: bash
@@ -161,28 +164,46 @@ jobs:
161164
with:
162165
name: wheels
163166
path: wheelhouse/
164-
- name: Upload wheels for opencv_python_rolling
167+
- name: Select only OpenCV wheels
165168
run: |
166-
python -m pip install twine
167-
python -m twine upload -u ${{ secrets.OPENCV_PYTHON_ROLLING_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_ROLLING_PASSWORD }} --skip-existing wheelhouse/opencv_python_rolling-*
169+
mkdir dist dist-contrib dist-headless dist-contrib-headless
170+
cp wheelhouse/opencv_python_rolling-* dist/
171+
cp wheelhouse/opencv_contrib_python_rolling-* dist-contrib/
172+
cp wheelhouse/opencv_python_headless_rolling-* dist-headless/
173+
cp wheelhouse/opencv_contrib_python_headless_rolling-* dist-contrib-headless/
174+
- name: Upload wheels for opencv_python_rolling
175+
uses: pypa/gh-action-pypi-publish@release/v1
176+
with:
177+
packages-dir: dist/
178+
print-hash: true
179+
skip-existing: true
168180
- name: Upload wheels for opencv_contrib_python_rolling
169-
run: |
170-
python -m pip install twine
171-
python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_ROLLING_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_ROLLING_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_rolling-*
181+
uses: pypa/gh-action-pypi-publish@release/v1
182+
with:
183+
packages-dir: dist-contrib/
184+
print-hash: true
185+
skip-existing: true
172186
- name: Upload wheels for opencv_python_headless_rolling
173-
run: |
174-
python -m pip install twine
175-
python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_ROLLING_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_ROLLING_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless_rolling-*
187+
uses: pypa/gh-action-pypi-publish@release/v1
188+
with:
189+
packages-dir: dist-headless/
190+
print-hash: true
191+
skip-existing: true
176192
- name: Upload wheels for opencv_contrib_python_headless_rolling
177-
run: |
178-
python -m pip install twine
179-
python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_ROLLING_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_ROLLING_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless_rolling-*
193+
uses: pypa/gh-action-pypi-publish@release/v1
194+
with:
195+
packages-dir: dist-contrib-headless/
196+
print-hash: true
197+
skip-existing: true
180198

181199
Pre-release:
182200
if: github.event_name == 'release' && github.event.release.prerelease
183201
needs: [Build, Test]
184202
runs-on: ubuntu-22.04
185203
environment: test-opencv-python-release
204+
permissions:
205+
contents: read
206+
id-token: write
186207
defaults:
187208
run:
188209
shell: bash
@@ -191,16 +212,27 @@ jobs:
191212
with:
192213
name: wheels
193214
path: wheelhouse/
194-
- name: Upload all wheels
215+
- name: Select only OpenCV wheels
195216
run: |
196-
python -m pip install twine
197-
python -m twine upload --repository testpypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --skip-existing wheelhouse/opencv_*
217+
mkdir dist
218+
cp wheelhouse/opencv_* dist/
219+
- name: Upload all wheels
220+
uses: pypa/gh-action-pypi-publish@release/v1
221+
with:
222+
packages-dir: dist/
223+
print-hash: true
224+
repository-url: https://test.pypi.org/legacy/
225+
skip-existing: true
226+
verbose: true
198227

199228
Release:
200229
if: github.event_name == 'release' && !github.event.release.prerelease
201230
needs: [Build, Test]
202231
runs-on: ubuntu-22.04
203232
environment: opencv-python-release
233+
permissions:
234+
contents: read
235+
id-token: write
204236
defaults:
205237
run:
206238
shell: bash
@@ -209,19 +241,34 @@ jobs:
209241
with:
210242
name: wheels
211243
path: wheelhouse/
212-
- name: Upload wheels for opencv_python
244+
- name: Select only OpenCV wheels
213245
run: |
214-
python -m pip install twine
215-
python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
246+
mkdir dist dist-contrib dist-headless dist-contrib-headless
247+
cp wheelhouse/opencv_python-* dist/
248+
cp wheelhouse/opencv_contrib_python-* dist-contrib/
249+
cp wheelhouse/opencv_python_headless-* dist-headless/
250+
cp wheelhouse/opencv_contrib_python_headless-* dist-contrib-headless/
251+
- name: Upload wheels for opencv_python
252+
uses: pypa/gh-action-pypi-publish@release/v1
253+
with:
254+
packages-dir: dist/
255+
print-hash: true
256+
skip-existing: true
216257
- name: Upload wheels for opencv_contrib_python
217-
run: |
218-
python -m pip install twine
219-
python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
258+
uses: pypa/gh-action-pypi-publish@release/v1
259+
with:
260+
packages-dir: dist-contrib/
261+
print-hash: true
262+
skip-existing: true
220263
- name: Upload wheels for opencv_python_headless
221-
run: |
222-
python -m pip install twine
223-
python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
264+
uses: pypa/gh-action-pypi-publish@release/v1
265+
with:
266+
packages-dir: dist-headless/
267+
print-hash: true
268+
skip-existing: true
224269
- name: Upload wheels for opencv_contrib_python_headless
225-
run: |
226-
python -m pip install twine
227-
python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-*
270+
uses: pypa/gh-action-pypi-publish@release/v1
271+
with:
272+
packages-dir: dist-contrib-headless/
273+
print-hash: true
274+
skip-existing: true

.github/workflows/build_wheels_macos_m1.yml

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ jobs:
119119
needs: [Build, Test]
120120
runs-on: ubuntu-22.04
121121
environment: opencv-python-rolling-release
122+
permissions:
123+
contents: read
124+
id-token: write
122125
defaults:
123126
run:
124127
shell: bash
@@ -127,28 +130,46 @@ jobs:
127130
with:
128131
name: wheels
129132
path: wheelhouse/
130-
- name: Upload wheels for opencv_python_rolling
133+
- name: Select only OpenCV wheels
131134
run: |
132-
python -m pip install twine
133-
python -m twine upload -u ${{ secrets.OPENCV_PYTHON_ROLLING_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_ROLLING_PASSWORD }} --skip-existing wheelhouse/opencv_python_rolling-*
135+
mkdir dist dist-contrib dist-headless dist-contrib-headless
136+
cp wheelhouse/opencv_python_rolling-* dist/
137+
cp wheelhouse/opencv_contrib_python_rolling-* dist-contrib/
138+
cp wheelhouse/opencv_python_headless_rolling-* dist-headless/
139+
cp wheelhouse/opencv_contrib_python_headless_rolling-* dist-contrib-headless/
140+
- name: Upload wheels for opencv_python_rolling
141+
uses: pypa/gh-action-pypi-publish@release/v1
142+
with:
143+
packages-dir: dist/
144+
print-hash: true
145+
skip-existing: true
134146
- name: Upload wheels for opencv_contrib_python_rolling
135-
run: |
136-
python -m pip install twine
137-
python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_ROLLING_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_ROLLING_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_rolling-*
147+
uses: pypa/gh-action-pypi-publish@release/v1
148+
with:
149+
packages-dir: dist-contrib/
150+
print-hash: true
151+
skip-existing: true
138152
- name: Upload wheels for opencv_python_headless_rolling
139-
run: |
140-
python -m pip install twine
141-
python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_ROLLING_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_ROLLING_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless_rolling-*
153+
uses: pypa/gh-action-pypi-publish@release/v1
154+
with:
155+
packages-dir: dist-headless/
156+
print-hash: true
157+
skip-existing: true
142158
- name: Upload wheels for opencv_contrib_python_headless_rolling
143-
run: |
144-
python -m pip install twine
145-
python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_ROLLING_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_ROLLING_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless_rolling-*
159+
uses: pypa/gh-action-pypi-publish@release/v1
160+
with:
161+
packages-dir: dist-contrib-headless/
162+
print-hash: true
163+
skip-existing: true
146164

147165
Pre-release:
148166
if: github.event_name == 'release' && github.event.release.prerelease
149167
needs: [Build, Test]
150168
runs-on: ubuntu-22.04
151169
environment: test-opencv-python-release
170+
permissions:
171+
contents: read
172+
id-token: write
152173
defaults:
153174
run:
154175
shell: bash
@@ -157,16 +178,27 @@ jobs:
157178
with:
158179
name: wheels
159180
path: wheelhouse/
160-
- name: Upload all wheels
181+
- name: Select only OpenCV wheels
161182
run: |
162-
python -m pip install twine
163-
python -m twine upload --repository testpypi -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --skip-existing wheelhouse/opencv_*
183+
mkdir dist
184+
cp wheelhouse/opencv_* dist/
185+
- name: Upload all wheels
186+
uses: pypa/gh-action-pypi-publish@release/v1
187+
with:
188+
packages-dir: dist/
189+
print-hash: true
190+
repository-url: https://test.pypi.org/legacy/
191+
skip-existing: true
192+
verbose: true
164193

165194
Release:
166195
if: github.event_name == 'release' && !github.event.release.prerelease
167196
needs: [Build, Test]
168197
runs-on: ubuntu-22.04
169198
environment: opencv-python-release
199+
permissions:
200+
contents: read
201+
id-token: write
170202
defaults:
171203
run:
172204
shell: bash
@@ -175,19 +207,34 @@ jobs:
175207
with:
176208
name: wheels
177209
path: wheelhouse/
178-
- name: Upload wheels for opencv_python
210+
- name: Select only OpenCV wheels
179211
run: |
180-
python -m pip install twine
181-
python -m twine upload -u ${{ secrets.OPENCV_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_python-*
212+
mkdir dist dist-contrib dist-headless dist-contrib-headless
213+
cp wheelhouse/opencv_python-* dist/
214+
cp wheelhouse/opencv_contrib_python-* dist-contrib/
215+
cp wheelhouse/opencv_python_headless-* dist-headless/
216+
cp wheelhouse/opencv_contrib_python_headless-* dist-contrib-headless/
217+
- name: Upload wheels for opencv_python
218+
uses: pypa/gh-action-pypi-publish@release/v1
219+
with:
220+
packages-dir: dist/
221+
print-hash: true
222+
skip-existing: true
182223
- name: Upload wheels for opencv_contrib_python
183-
run: |
184-
python -m pip install twine
185-
python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python-*
224+
uses: pypa/gh-action-pypi-publish@release/v1
225+
with:
226+
packages-dir: dist-contrib/
227+
print-hash: true
228+
skip-existing: true
186229
- name: Upload wheels for opencv_python_headless
187-
run: |
188-
python -m pip install twine
189-
python -m twine upload -u ${{ secrets.OPENCV_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_python_headless-*
230+
uses: pypa/gh-action-pypi-publish@release/v1
231+
with:
232+
packages-dir: dist-headless/
233+
print-hash: true
234+
skip-existing: true
190235
- name: Upload wheels for opencv_contrib_python_headless
191-
run: |
192-
python -m pip install twine
193-
python -m twine upload -u ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_USERNAME }} -p ${{ secrets.OPENCV_CONTRIB_PYTHON_HEADLESS_PASSWORD }} --skip-existing wheelhouse/opencv_contrib_python_headless-*
236+
uses: pypa/gh-action-pypi-publish@release/v1
237+
with:
238+
packages-dir: dist-contrib-headless/
239+
print-hash: true
240+
skip-existing: true

0 commit comments

Comments
 (0)