Skip to content

Commit cb832bc

Browse files
committed
CI: use trusted publisher for PyPi publishing
1 parent f1c4ce1 commit cb832bc

File tree

1 file changed

+43
-70
lines changed

1 file changed

+43
-70
lines changed

.github/workflows/build.yml

Lines changed: 43 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -151,96 +151,69 @@ jobs:
151151
run: |
152152
bash packing/test_wheels.sh $(pwd)
153153
154-
publish_wheels:
155-
needs: [test_wheels_mac, test_wheels_win]
156-
name: Upload wheels
157-
runs-on: ubuntu-latest
158-
if: github.event_name== 'release'
159-
steps:
160-
- name: Setup Python
161-
uses: actions/setup-python@v4
162-
with:
163-
python-version: "3.9"
164-
165-
- uses: actions/download-artifact@v3
166-
with:
167-
path: downloads/
168-
169-
- name: Publish release
170-
if: github.event_name == 'release'
171-
shell: bash
172-
env:
173-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
174-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
175-
run: |
176-
mkdir -p wheelhouse/
177-
find downloads/ -name \*.whl -exec cp {} wheelhouse \;
178-
pip install twine
179-
twine upload wheelhouse/*.whl
180-
181154
build_sdist:
182155
name: Source distribution
183156
runs-on: ubuntu-latest
184-
if: github.event_name== 'release'
185157
steps:
186158
- name: Checkout
187159
uses: actions/checkout@v4
188160

189161
- name: Setup Python
190-
uses: actions/setup-python@v4
162+
uses: actions/setup-python@v5
191163
with:
192-
python-version: "3.8"
164+
python-version: "3.11"
193165

194-
- name: Build Source Distribution
195-
if: ${{ github.event_name== 'release' && runner.os == 'Linux' }}
196-
env:
197-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
198-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
166+
- name: Install dependencies
199167
run: |
200168
sudo apt install libcairo2-dev pkg-config python3-dev
201169
sudo apt-get install libpango1.0-dev
202-
pip install twine
203-
python setup.py sdist
204-
twine upload dist/*
170+
python -m pip install --upgrade build
171+
172+
- name: Build sdist
173+
run: python -m build --sdist
174+
175+
- name: Test sdist
176+
run: |
177+
python -m pip install dist/*.tar.gz
205178
206179
- name: Store artifacts
207180
uses: actions/upload-artifact@v3
208181
with:
209182
path: dist/*.tar.gz
210-
name: manimpango.tar.gz
211-
- name: Install Dependency
212-
run: pip install requests
213-
- name: Get Upload URL
214-
id: create_release
215-
shell: python
216-
env:
217-
access_token: ${{ secrets.GITHUB_TOKEN }}
218-
tag_act: ${{ github.ref }}
183+
name: manimpango-src
184+
185+
publish:
186+
needs: [test_wheels_mac, test_wheels_win, build_sdist]
187+
name: Upload wheels to PyPI
188+
runs-on: ubuntu-latest
189+
environment:
190+
name: release
191+
url: https://pypi.org/p/ManimPango
192+
permissions:
193+
id-token: write
194+
contents: write
195+
if: github.event_name== 'release'
196+
steps:
197+
- uses: actions/download-artifact@v3
198+
with:
199+
path: downloads/
200+
201+
- name: Move files to dist
219202
run: |
220-
import requests
221-
import os
222-
ref_tag = os.getenv('tag_act').split('/')[-1]
223-
access_token = os.getenv('access_token')
224-
headers = {
225-
"Accept":"application/vnd.github.v3+json",
226-
"Authorization": f"token {access_token}"
227-
}
228-
url = f"https://api.github.com/repos/ManimCommunity/manimpango/releases/tags/{ref_tag}"
229-
c = requests.get(url,headers=headers)
230-
upload_url=c.json()['upload_url']
231-
with open(os.environ.get("GITHUB_OUTPUT"), "w") as f:
232-
print(f"upload_url={upload_url}", file=f)
233-
print(f"tag_name={ref_tag[1:]}", file=f)
234-
- name: Upload Release Asset
235-
id: upload-release
236-
uses: actions/upload-release-asset@v1
237-
env:
238-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
203+
mkdir -p dist/
204+
find downloads/ -name \*.whl -exec cp {} dist \;
205+
find downloads/ -name \*.tar.gz -exec cp {} dist \;
206+
207+
- name: Publish package distributions to PyPI
208+
uses: pypa/gh-action-pypi-publish@release/v1
209+
210+
- name: Release
211+
uses: softprops/action-gh-release@v2
239212
with:
240-
upload_url: ${{ steps.create_release.outputs.upload_url }}
241-
asset_path: dist/ManimPango-${{ steps.create_release.outputs.tag_name }}.tar.gz
242-
asset_name: ManimPango-${{ steps.create_release.outputs.tag_name }}.tar.gz
243-
asset_content_type: application/gzip
213+
fail_on_unmatched_files: false
214+
files: |
215+
dist/*.whl
216+
dist/*.tar.gz
244217
245218
success:
246219
needs: [test_wheels_win, test_wheels_mac]

0 commit comments

Comments
 (0)