|
| 1 | +name: Create Draft Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + release_version: |
| 7 | + description: The version to set in setup.py |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + outputs: |
| 11 | + release_id: |
| 12 | + description: The created release ID |
| 13 | + value: ${{ jobs.create_release.outputs.release_id }} |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: none |
| 17 | + |
| 18 | +jobs: |
| 19 | + |
| 20 | + package_python3: |
| 21 | + name: Create sdist and Python 3 Wheel |
| 22 | + runs-on: ubuntu-24.04 |
| 23 | + outputs: |
| 24 | + sdist: ${{ steps.package.outputs.sdist }} |
| 25 | + wheel: ${{ steps.package.outputs.wheel }} |
| 26 | + container: |
| 27 | + image: danielflook/python-minifier-build:python3.14-2025-09-26 |
| 28 | + permissions: |
| 29 | + contents: read |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + |
| 33 | + with: |
| 34 | + fetch-depth: 1 |
| 35 | + show-progress: false |
| 36 | + persist-credentials: false |
| 37 | + |
| 38 | + - name: Set version statically |
| 39 | + env: |
| 40 | + VERSION: ${{ inputs.release_version }} |
| 41 | + run: | |
| 42 | + python3 -c " |
| 43 | + import re, os |
| 44 | + version = os.environ['VERSION'] |
| 45 | + |
| 46 | + with open('setup.py', 'r') as f: |
| 47 | + content = f.read() |
| 48 | + |
| 49 | + # Remove setuptools_scm configuration and set static version |
| 50 | + content = re.sub(r'setup_requires=.*', f\"version='{version}',\", content) |
| 51 | + content = re.sub(r'use_scm_version=.*,?\s*', '', content) |
| 52 | + |
| 53 | + with open('setup.py', 'w') as f: |
| 54 | + f.write(content) |
| 55 | + " |
| 56 | + echo "Version: $VERSION" |
| 57 | +
|
| 58 | + - name: Build distribution packages |
| 59 | + id: package |
| 60 | + run: | |
| 61 | + pip3 install --upgrade build |
| 62 | + python3 -m build |
| 63 | + |
| 64 | + echo "sdist=$(find dist -name '*.tar.gz' -printf "%f\n")" >> "$GITHUB_OUTPUT" |
| 65 | + echo "wheel=$(find dist -name '*-py3-*.whl' -printf "%f\n")" >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + - name: Upload sdist artifact |
| 68 | + |
| 69 | + with: |
| 70 | + name: dist-sdist |
| 71 | + path: dist/${{ steps.package.outputs.sdist }} |
| 72 | + if-no-files-found: error |
| 73 | + |
| 74 | + - name: Upload Python 3 wheel artifact |
| 75 | + |
| 76 | + with: |
| 77 | + name: dist-py3-wheel |
| 78 | + path: dist/${{ steps.package.outputs.wheel }} |
| 79 | + if-no-files-found: error |
| 80 | + |
| 81 | + package_python2: |
| 82 | + name: Create Python 2 Wheel |
| 83 | + runs-on: ubuntu-24.04 |
| 84 | + needs: [package_python3] |
| 85 | + outputs: |
| 86 | + wheel: ${{ steps.package.outputs.wheel }} |
| 87 | + container: |
| 88 | + image: danielflook/python-minifier-build:python2.7-2025-09-26 |
| 89 | + steps: |
| 90 | + - name: Download source distribution artifact |
| 91 | + |
| 92 | + with: |
| 93 | + name: dist-sdist |
| 94 | + path: dist/ |
| 95 | + |
| 96 | + - name: Build Python 2 wheel |
| 97 | + id: package |
| 98 | + env: |
| 99 | + PYTHON3_SDIST: ${{ needs.package_python3.outputs.sdist }} |
| 100 | + run: | |
| 101 | + dnf install -y findutils |
| 102 | + pip install --upgrade wheel |
| 103 | + pip wheel dist/"$PYTHON3_SDIST" -w dist |
| 104 | + echo "wheel=$(find dist -name '*-py2-*.whl' -printf "%f\n")" >> "$GITHUB_OUTPUT" |
| 105 | +
|
| 106 | + - name: Upload Python 2 wheel artifact |
| 107 | + |
| 108 | + with: |
| 109 | + name: dist-py2-wheel |
| 110 | + path: dist/${{ steps.package.outputs.wheel }} |
| 111 | + if-no-files-found: error |
| 112 | + |
| 113 | + documentation: |
| 114 | + name: Build Documentation |
| 115 | + runs-on: ubuntu-24.04 |
| 116 | + needs: [package_python3] |
| 117 | + container: |
| 118 | + image: danielflook/python-minifier-build:python3.14-2025-09-26 |
| 119 | + permissions: |
| 120 | + contents: read |
| 121 | + steps: |
| 122 | + |
| 123 | + with: |
| 124 | + name: dist-sdist |
| 125 | + path: dist/ |
| 126 | + |
| 127 | + - name: Install package |
| 128 | + env: |
| 129 | + PYTHON3_SDIST: ${{ needs.package_python3.outputs.sdist }} |
| 130 | + run: | |
| 131 | + pip3 install dist/"$PYTHON3_SDIST" |
| 132 | + pyminify --version |
| 133 | +
|
| 134 | + - name: Checkout |
| 135 | + |
| 136 | + with: |
| 137 | + fetch-depth: 1 |
| 138 | + show-progress: false |
| 139 | + persist-credentials: false |
| 140 | + |
| 141 | + - name: Build documentation |
| 142 | + run: | |
| 143 | + pip3 install sphinx sphinxcontrib-programoutput sphinx_rtd_theme |
| 144 | + sphinx-build docs/source /tmp/build |
| 145 | +
|
| 146 | + - name: Upload documentation artifact |
| 147 | + |
| 148 | + with: |
| 149 | + path: /tmp/build |
| 150 | + |
| 151 | + test_package: |
| 152 | + name: Test Package |
| 153 | + runs-on: ubuntu-24.04 |
| 154 | + needs: [package_python2, package_python3] |
| 155 | + permissions: |
| 156 | + contents: read |
| 157 | + strategy: |
| 158 | + fail-fast: false |
| 159 | + matrix: |
| 160 | + python: ["2.7", "3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] |
| 161 | + package_type: [sdist, wheel] |
| 162 | + steps: |
| 163 | + - name: Checkout |
| 164 | + |
| 165 | + with: |
| 166 | + fetch-depth: 1 |
| 167 | + show-progress: false |
| 168 | + persist-credentials: false |
| 169 | + |
| 170 | + - name: Download distribution artifacts |
| 171 | + |
| 172 | + with: |
| 173 | + pattern: dist-* |
| 174 | + path: dist/ |
| 175 | + merge-multiple: true |
| 176 | + |
| 177 | + - name: Test |
| 178 | + uses: ./.github/actions/run-in-container |
| 179 | + with: |
| 180 | + image: danielflook/python-minifier-build:python${{ matrix.python }}-2025-09-26 |
| 181 | + run: | |
| 182 | + if [[ "${{ matrix.package_type }}" == "sdist" ]]; then |
| 183 | + pip${{ matrix.python }} install dist/${{needs.package_python3.outputs.sdist}} |
| 184 | +
|
| 185 | + # Extract sdist to access tests |
| 186 | + mkdir -p /tmp/sdist-extract |
| 187 | + cd /tmp/sdist-extract |
| 188 | + tar -xzf /github/workspace/dist/${{needs.package_python3.outputs.sdist}} --strip-components=1 |
| 189 | +
|
| 190 | + # Install test dependencies and package |
| 191 | + pip${{ matrix.python }} install -r test/requirements.txt |
| 192 | +
|
| 193 | + # Run unit tests from sdist |
| 194 | + python${{ matrix.python }} -m pytest test/ -v |
| 195 | +
|
| 196 | + elif [[ "${{ matrix.python }}" == "2.7" ]]; then |
| 197 | + pip${{ matrix.python }} install dist/${{needs.package_python2.outputs.wheel}} |
| 198 | + else |
| 199 | + pip${{ matrix.python }} install dist/${{needs.package_python3.outputs.wheel}} |
| 200 | + fi |
| 201 | +
|
| 202 | + pyminify --version |
| 203 | +
|
| 204 | + set -x |
| 205 | + cat setup.py | pyminify - |
| 206 | + pyminify setup.py > /tmp/out.min.py |
| 207 | + pyminify setup.py --output /tmp/out.min.py2 |
| 208 | + pyminify setup.py src test --in-place |
| 209 | +
|
| 210 | + test_typing: |
| 211 | + name: Test Typing |
| 212 | + runs-on: ubuntu-24.04 |
| 213 | + needs: [package_python3] |
| 214 | + strategy: |
| 215 | + matrix: |
| 216 | + package_type: [sdist, wheel] |
| 217 | + permissions: |
| 218 | + contents: read |
| 219 | + container: |
| 220 | + image: danielflook/python-minifier-build:python3.14-2025-09-26 |
| 221 | + steps: |
| 222 | + - name: Download distribution artifacts |
| 223 | + |
| 224 | + with: |
| 225 | + pattern: dist-* |
| 226 | + path: dist/ |
| 227 | + merge-multiple: true |
| 228 | + |
| 229 | + - name: Install package |
| 230 | + env: |
| 231 | + PYTHON3_SDIST: ${{ needs.package_python3.outputs.sdist }} |
| 232 | + PYTHON3_WHEEL: ${{ needs.package_python3.outputs.wheel }} |
| 233 | + run: | |
| 234 | + if [[ "${{ matrix.package_type }}" == "sdist" ]]; then |
| 235 | + pip3.14 install "dist/$PYTHON3_SDIST" |
| 236 | + else |
| 237 | + pip3.14 install "dist/$PYTHON3_WHEEL" |
| 238 | + fi |
| 239 | +
|
| 240 | + - name: Checkout |
| 241 | + |
| 242 | + with: |
| 243 | + fetch-depth: 1 |
| 244 | + show-progress: false |
| 245 | + persist-credentials: false |
| 246 | + |
| 247 | + - name: Test typing |
| 248 | + run: | |
| 249 | + pip3.14 install 'mypy<1.12.0' types-setuptools |
| 250 | + mypy --strict typing_test/test_typing.py |
| 251 | +
|
| 252 | + if mypy --strict typing_test/test_badtyping.py; then |
| 253 | + echo "Bad types weren't detected" |
| 254 | + exit 1 |
| 255 | + fi |
| 256 | +
|
| 257 | + stubtest python_minifier --allowlist typing_test/stubtest-allowlist.txt |
| 258 | +
|
| 259 | + create_release: |
| 260 | + name: Create Draft Release |
| 261 | + runs-on: ubuntu-24.04 |
| 262 | + needs: |
| 263 | + - package_python2 |
| 264 | + - package_python3 |
| 265 | + - documentation |
| 266 | + - test_package |
| 267 | + - test_typing |
| 268 | + permissions: |
| 269 | + contents: write |
| 270 | + outputs: |
| 271 | + release_id: ${{ steps.create_release.outputs.release_id }} |
| 272 | + steps: |
| 273 | + - name: Checkout |
| 274 | + |
| 275 | + with: |
| 276 | + fetch-depth: 1 |
| 277 | + show-progress: false |
| 278 | + persist-credentials: false |
| 279 | + |
| 280 | + - name: Generate Release Notes |
| 281 | + run: | |
| 282 | + cp .github/release_preamble.md release_body.md |
| 283 | + |
| 284 | + # Extract the topmost changelog section (first version found) |
| 285 | + changelog_section=$(awk '/^## \[.*\]/{if(!found){found=1; next}} /^## \[.*\]/{if(found) exit} found' CHANGELOG.md) |
| 286 | + if [ -z "$changelog_section" ]; then |
| 287 | + echo "No changelog section found, using only release preamble" |
| 288 | + else |
| 289 | + echo "$changelog_section" >> release_body.md |
| 290 | + fi |
| 291 | +
|
| 292 | + - name: Create Draft Release |
| 293 | + id: create_release |
| 294 | + env: |
| 295 | + VERSION: ${{ inputs.release_version }} |
| 296 | + GH_TOKEN: ${{ github.token }} |
| 297 | + run: | |
| 298 | + set -e |
| 299 | + release_url=$(gh release create "$VERSION" \ |
| 300 | + --draft \ |
| 301 | + --title "$VERSION" \ |
| 302 | + --notes-file release_body.md) |
| 303 | + echo "Draft release created: $release_url" |
| 304 | + |
| 305 | + # Extract the untagged release ID from the URL |
| 306 | + untagged_id="${release_url##*/tag/}" |
| 307 | + echo "release_id=$untagged_id" >> "$GITHUB_OUTPUT" |
| 308 | +
|
| 309 | + - name: Download distribution artifacts |
| 310 | + |
| 311 | + with: |
| 312 | + pattern: dist-* |
| 313 | + path: dist/ |
| 314 | + merge-multiple: true |
| 315 | + |
| 316 | + - name: Upload Release Assets |
| 317 | + env: |
| 318 | + RELEASE_ID: ${{ steps.create_release.outputs.release_id }} |
| 319 | + GH_TOKEN: ${{ github.token }} |
| 320 | + SDIST: ${{ needs.package_python3.outputs.sdist }} |
| 321 | + PYTHON3_WHEEL: ${{ needs.package_python3.outputs.wheel }} |
| 322 | + PYTHON2_WHEEL: ${{ needs.package_python2.outputs.wheel }} |
| 323 | + run: | |
| 324 | + gh release upload "$RELEASE_ID" \ |
| 325 | + --repo ${{ github.repository }} \ |
| 326 | + "dist/${SDIST}" \ |
| 327 | + "dist/${PYTHON3_WHEEL}" \ |
| 328 | + "dist/${PYTHON2_WHEEL}" |
0 commit comments