Skip to content

Commit dad80d7

Browse files
authored
[ci] simplify release workflow. (#13329)
* simplify release workflow. * up * trigger on branches too. * restrict permissions to read. * use sha * remove determination step of latest branch * resolve rest
1 parent d0c9cba commit dad80d7

2 files changed

Lines changed: 47 additions & 124 deletions

File tree

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,78 @@
1-
# Adapted from https://blog.deepjyoti30.dev/pypi-release-github-action
2-
31
name: PyPI release
42

53
on:
64
workflow_dispatch:
75
push:
86
tags:
9-
- "*"
7+
- v*
8+
branches:
9+
- 'v*-release'
10+
11+
permissions:
12+
contents: read
1013

1114
jobs:
12-
find-and-checkout-latest-branch:
15+
build-and-test:
1316
runs-on: ubuntu-22.04
14-
outputs:
15-
latest_branch: ${{ steps.set_latest_branch.outputs.latest_branch }}
1617
steps:
17-
- name: Checkout Repo
18-
uses: actions/checkout@v6
18+
- name: Checkout repo
19+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1920

2021
- name: Set up Python
21-
uses: actions/setup-python@v6
22-
with:
23-
python-version: '3.10'
24-
25-
- name: Fetch latest branch
26-
id: fetch_latest_branch
27-
run: |
28-
pip install -U requests packaging
29-
LATEST_BRANCH=$(python utils/fetch_latest_release_branch.py)
30-
echo "Latest branch: $LATEST_BRANCH"
31-
echo "latest_branch=$LATEST_BRANCH" >> $GITHUB_ENV
32-
33-
- name: Set latest branch output
34-
id: set_latest_branch
35-
run: echo "::set-output name=latest_branch::${{ env.latest_branch }}"
36-
37-
release:
38-
needs: find-and-checkout-latest-branch
39-
runs-on: ubuntu-22.04
40-
41-
steps:
42-
- name: Checkout Repo
43-
uses: actions/checkout@v6
44-
with:
45-
ref: ${{ needs.find-and-checkout-latest-branch.outputs.latest_branch }}
46-
47-
- name: Setup Python
48-
uses: actions/setup-python@v6
22+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
4923
with:
5024
python-version: "3.10"
5125

52-
- name: Install dependencies
26+
- name: Install build dependencies
5327
run: |
5428
python -m pip install --upgrade pip
55-
pip install -U setuptools wheel twine
29+
pip install -U build
5630
pip install -U torch --index-url https://download.pytorch.org/whl/cpu
5731
5832
- name: Build the dist files
59-
run: python setup.py bdist_wheel && python setup.py sdist
33+
run: python -m build
34+
35+
- name: Validate dist metadata
36+
run: |
37+
pip install twine
38+
twine check --strict dist/*
6039
61-
- name: Publish to the test PyPI
62-
env:
63-
TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }}
64-
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }}
65-
run: twine upload dist/* -r pypitest --repository-url=https://test.pypi.org/legacy/
40+
- name: Install from built wheel
41+
run: pip install dist/*.whl
6642

6743
- name: Test installing diffusers and importing
6844
run: |
69-
pip install diffusers && pip uninstall diffusers -y
70-
pip install -i https://test.pypi.org/simple/ diffusers
7145
pip install -U transformers
7246
python utils/print_env.py
7347
python -c "from diffusers import __version__; print(__version__)"
7448
python -c "from diffusers import DiffusionPipeline; pipe = DiffusionPipeline.from_pretrained('fusing/unet-ldm-dummy-update'); pipe()"
7549
python -c "from diffusers import DiffusionPipeline; pipe = DiffusionPipeline.from_pretrained('hf-internal-testing/tiny-stable-diffusion-pipe', safety_checker=None); pipe('ah suh du')"
7650
python -c "from diffusers import *"
7751
78-
- name: Publish to PyPI
79-
env:
80-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
81-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
82-
run: twine upload dist/* -r pypi
52+
- name: Upload build artifacts
53+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
54+
with:
55+
name: python-dist
56+
path: dist/
57+
58+
publish-to-pypi:
59+
needs: build-and-test
60+
if: startsWith(github.ref, 'refs/tags/')
61+
runs-on: ubuntu-latest
62+
environment: pypi-release
63+
permissions:
64+
id-token: write
65+
66+
steps:
67+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
68+
69+
- name: Download build artifacts
70+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
71+
with:
72+
name: python-dist
73+
path: dist/
74+
75+
- name: Publish package distributions to TestPyPI
76+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1
77+
with:
78+
verbose: true

utils/fetch_latest_release_branch.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)