|
1 | | -# Adapted from https://blog.deepjyoti30.dev/pypi-release-github-action |
2 | | - |
3 | 1 | name: PyPI release |
4 | 2 |
|
5 | 3 | on: |
6 | 4 | workflow_dispatch: |
7 | 5 | push: |
8 | 6 | tags: |
9 | | - - "*" |
| 7 | + - v* |
| 8 | + branches: |
| 9 | + - 'v*-release' |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
10 | 13 |
|
11 | 14 | jobs: |
12 | | - find-and-checkout-latest-branch: |
| 15 | + build-and-test: |
13 | 16 | runs-on: ubuntu-22.04 |
14 | | - outputs: |
15 | | - latest_branch: ${{ steps.set_latest_branch.outputs.latest_branch }} |
16 | 17 | steps: |
17 | | - - name: Checkout Repo |
18 | | - uses: actions/checkout@v6 |
| 18 | + - name: Checkout repo |
| 19 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
19 | 20 |
|
20 | 21 | - 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 |
49 | 23 | with: |
50 | 24 | python-version: "3.10" |
51 | 25 |
|
52 | | - - name: Install dependencies |
| 26 | + - name: Install build dependencies |
53 | 27 | run: | |
54 | 28 | python -m pip install --upgrade pip |
55 | | - pip install -U setuptools wheel twine |
| 29 | + pip install -U build |
56 | 30 | pip install -U torch --index-url https://download.pytorch.org/whl/cpu |
57 | 31 |
|
58 | 32 | - 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/* |
60 | 39 |
|
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 |
66 | 42 |
|
67 | 43 | - name: Test installing diffusers and importing |
68 | 44 | run: | |
69 | | - pip install diffusers && pip uninstall diffusers -y |
70 | | - pip install -i https://test.pypi.org/simple/ diffusers |
71 | 45 | pip install -U transformers |
72 | 46 | python utils/print_env.py |
73 | 47 | python -c "from diffusers import __version__; print(__version__)" |
74 | 48 | python -c "from diffusers import DiffusionPipeline; pipe = DiffusionPipeline.from_pretrained('fusing/unet-ldm-dummy-update'); pipe()" |
75 | 49 | python -c "from diffusers import DiffusionPipeline; pipe = DiffusionPipeline.from_pretrained('hf-internal-testing/tiny-stable-diffusion-pipe', safety_checker=None); pipe('ah suh du')" |
76 | 50 | python -c "from diffusers import *" |
77 | 51 |
|
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 |
0 commit comments