-
Notifications
You must be signed in to change notification settings - Fork 1
144 lines (127 loc) · 5.2 KB
/
python-publish.yml
File metadata and controls
144 lines (127 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Version Update and Upload Python Package
# Disabled attestations to correct errors on upload.
# https://github.com/pypa/gh-action-pypi-publish/issues/283
on:
release:
types: [published]
workflow_dispatch:
inputs:
target_ref:
description: 'Branch, tag, or SHA to build/test (default: event ref)'
required: false
default: ''
release_version:
description: 'Version to use when manually testing (omit to use current package version)'
required: false
default: ''
publish_to_pypi:
description: 'Publish to PyPI (only for manual runs)'
required: false
type: boolean
default: false
permissions:
contents: write
jobs:
update-version:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
# Use provided ref for manual run, else use the event ref
ref: ${{ inputs.target_ref || github.ref }}
- name: Determine release/base versions
id: set_version
run: |
CURRENT_TAG_VERSION="${GITHUB_REF##refs/tags/v}"
INPUT_VERSION="${{ inputs.release_version }}"
if [ "${{ github.event_name }}" = "release" ]; then
USE_VERSION="$CURRENT_TAG_VERSION"
elif [ -n "$INPUT_VERSION" ]; then
USE_VERSION="$INPUT_VERSION"
else
USE_VERSION=$(python -c 'from utils.release import get_version; print(get_version())')
fi
echo "release_version=$USE_VERSION" >> $GITHUB_ENV
echo "base_version=$(python -c 'from utils.release import get_version; print(get_version())')" >> $GITHUB_ENV
echo "release_version=$USE_VERSION" >> $GITHUB_OUTPUT
echo "base_version=$(python -c 'from utils.release import get_version; print(get_version())')" >> $GITHUB_OUTPUT
- name: Update version (idempotent)
if: github.event_name == 'release' || inputs.publish_to_pypi == 'true'
run: |
# Guard: ensure release_version is set; if not, skip to avoid calling release.py with empty arg
if [ -z "${{ env.release_version }}" ]; then
echo "release_version is empty; skipping version update.";
exit 0
fi
if [ "${{ env.release_version }}" = "${{ env.base_version }}" ]; then
echo "Version already ${env.release_version}; skipping bump.";
else
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
python utils/release.py --update_version "${{ env.release_version }}"
if git diff --quiet; then
echo "No changes after version update.";
else
git add .
git commit -m "Update version from ${{ env.base_version }} to ${{ env.release_version }}"
# Only push to master/default branch on release event
if [ "${{ github.event_name }}" = "release" ]; then
git pull --rebase origin $(git rev-parse --abbrev-ref HEAD)
git push origin HEAD:master
fi
fi
fi
release-build:
name: Build / Test / Publish
runs-on: ubuntu-22.04
needs: update-version
environment:
name: pypi_release
url: https://pypi.org/p/auto_diffusers
permissions:
id-token: write
contents: read
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
ref: ${{ inputs.target_ref || github.ref }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools twine build
pip install -U torch --index-url https://download.pytorch.org/whl/cpu
pip install -U diffusers transformers
- name: Build distributions
run: |
python -m build
ls -l dist
- name: Publish to Test PyPI
if: github.event_name == 'release' || inputs.publish_to_pypi == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
attestations: false
repository-url: https://test.pypi.org/legacy/
skip-existing: true
- name: Test install from built artifacts (wheel)
run: |
python -c "import glob,sys; print('dist:',glob.glob('dist/*'))" || true
pip install --no-cache-dir dist/*.whl
python -c "from auto_diffusers import *"
# Due to a bug on the Civitai API side that prevents a fundamental fix, we will skip the operation check in order to apply the mitigation measures.
# python -c "from auto_diffusers import EasyPipelineForText2Image; pipe = EasyPipelineForText2Image.from_huggingface('Stable Diffusion')"
# rm -rf ~/.cache/huggingface/hub/*
# python -c "from auto_diffusers import EasyPipelineForText2Image; pipe = EasyPipelineForText2Image.from_civitai('Anything', base_model='SD 1.5')"
- name: Publish to PyPI
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
attestations: false
skip-existing: true