Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/release_preamble.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:information_source: Note that python-minifier depends on the python interpreter for parsing source code,
and will output source code compatible with the version of the interpreter it is run with.

This means that if you minify code written for Python 3.11 using python-minifier running with Python 3.12,
the minified code may only run with Python 3.12.
328 changes: 328 additions & 0 deletions .github/workflows/create_draft_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
name: Create Draft Release

on:
workflow_call:
inputs:
release_version:
description: The version to set in setup.py
required: true
type: string
outputs:
release_id:
description: The created release ID
value: ${{ jobs.create_release.outputs.release_id }}

permissions:
contents: none

jobs:

package_python3:
name: Create sdist and Python 3 Wheel
runs-on: ubuntu-24.04
outputs:
sdist: ${{ steps.package.outputs.sdist }}
wheel: ${{ steps.package.outputs.wheel }}
container:
image: danielflook/python-minifier-build:python3.14-2025-09-26
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4.2.2
with:
fetch-depth: 1
show-progress: false
persist-credentials: false

- name: Set version statically
env:
VERSION: ${{ inputs.release_version }}
run: |
python3 -c "
import re, os
version = os.environ['VERSION']

with open('setup.py', 'r') as f:
content = f.read()

# Remove setuptools_scm configuration and set static version
content = re.sub(r'setup_requires=.*', f\"version='{version}',\", content)
content = re.sub(r'use_scm_version=.*,?\s*', '', content)

with open('setup.py', 'w') as f:
f.write(content)
"
echo "Version: $VERSION"

- name: Build distribution packages
id: package
run: |
pip3 install --upgrade build
python3 -m build

echo "sdist=$(find dist -name '*.tar.gz' -printf "%f\n")" >> "$GITHUB_OUTPUT"
echo "wheel=$(find dist -name '*-py3-*.whl' -printf "%f\n")" >> "$GITHUB_OUTPUT"

- name: Upload sdist artifact
uses: actions/upload-artifact@v4.4.3
with:
name: dist-sdist
path: dist/${{ steps.package.outputs.sdist }}
if-no-files-found: error

- name: Upload Python 3 wheel artifact
uses: actions/upload-artifact@v4.4.3
with:
name: dist-py3-wheel
path: dist/${{ steps.package.outputs.wheel }}
if-no-files-found: error

package_python2:
name: Create Python 2 Wheel
runs-on: ubuntu-24.04
needs: [package_python3]
outputs:
wheel: ${{ steps.package.outputs.wheel }}
container:
image: danielflook/python-minifier-build:python2.7-2025-09-26
steps:
- name: Download source distribution artifact
uses: actions/download-artifact@v4.1.8
with:
name: dist-sdist
path: dist/

- name: Build Python 2 wheel
id: package
env:
PYTHON3_SDIST: ${{ needs.package_python3.outputs.sdist }}
run: |
dnf install -y findutils
pip install --upgrade wheel
pip wheel dist/"$PYTHON3_SDIST" -w dist
echo "wheel=$(find dist -name '*-py2-*.whl' -printf "%f\n")" >> "$GITHUB_OUTPUT"

- name: Upload Python 2 wheel artifact
uses: actions/upload-artifact@v4.4.3
with:
name: dist-py2-wheel
path: dist/${{ steps.package.outputs.wheel }}
if-no-files-found: error

documentation:
name: Build Documentation
runs-on: ubuntu-24.04
needs: [package_python3]
container:
image: danielflook/python-minifier-build:python3.14-2025-09-26
permissions:
contents: read
steps:
- uses: actions/download-artifact@v4.1.8
with:
name: dist-sdist
path: dist/

- name: Install package
env:
PYTHON3_SDIST: ${{ needs.package_python3.outputs.sdist }}
run: |
pip3 install dist/"$PYTHON3_SDIST"
pyminify --version

- name: Checkout
uses: actions/checkout@v4.2.2
with:
fetch-depth: 1
show-progress: false
persist-credentials: false

- name: Build documentation
run: |
pip3 install sphinx sphinxcontrib-programoutput sphinx_rtd_theme
sphinx-build docs/source /tmp/build

- name: Upload documentation artifact
uses: actions/upload-pages-artifact@v3.0.1
with:
path: /tmp/build

test_package:
name: Test Package
runs-on: ubuntu-24.04
needs: [package_python2, package_python3]
permissions:
contents: read
strategy:
fail-fast: false
matrix:
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"]
package_type: [sdist, wheel]
steps:
- name: Checkout
uses: actions/checkout@v4.2.2
with:
fetch-depth: 1
show-progress: false
persist-credentials: false

- name: Download distribution artifacts
uses: actions/download-artifact@v4.1.8
with:
pattern: dist-*
path: dist/
merge-multiple: true

- name: Test
uses: ./.github/actions/run-in-container
with:
image: danielflook/python-minifier-build:python${{ matrix.python }}-2025-09-26
run: |
if [[ "${{ matrix.package_type }}" == "sdist" ]]; then
pip${{ matrix.python }} install dist/${{needs.package_python3.outputs.sdist}}

# Extract sdist to access tests
mkdir -p /tmp/sdist-extract
cd /tmp/sdist-extract
tar -xzf /github/workspace/dist/${{needs.package_python3.outputs.sdist}} --strip-components=1

# Install test dependencies and package
pip${{ matrix.python }} install -r test/requirements.txt

# Run unit tests from sdist
python${{ matrix.python }} -m pytest test/ -v

elif [[ "${{ matrix.python }}" == "2.7" ]]; then
pip${{ matrix.python }} install dist/${{needs.package_python2.outputs.wheel}}
else
pip${{ matrix.python }} install dist/${{needs.package_python3.outputs.wheel}}
fi

pyminify --version

set -x
cat setup.py | pyminify -
pyminify setup.py > /tmp/out.min.py
pyminify setup.py --output /tmp/out.min.py2
pyminify setup.py src test --in-place

test_typing:
name: Test Typing
runs-on: ubuntu-24.04
needs: [package_python3]
strategy:
matrix:
package_type: [sdist, wheel]
permissions:
contents: read
container:
image: danielflook/python-minifier-build:python3.14-2025-09-26
steps:
- name: Download distribution artifacts
uses: actions/download-artifact@v4.1.8
with:
pattern: dist-*
path: dist/
merge-multiple: true

- name: Install package
env:
PYTHON3_SDIST: ${{ needs.package_python3.outputs.sdist }}
PYTHON3_WHEEL: ${{ needs.package_python3.outputs.wheel }}
run: |
if [[ "${{ matrix.package_type }}" == "sdist" ]]; then
pip3.14 install "dist/$PYTHON3_SDIST"
else
pip3.14 install "dist/$PYTHON3_WHEEL"
fi

- name: Checkout
uses: actions/checkout@v4.2.2
with:
fetch-depth: 1
show-progress: false
persist-credentials: false

- name: Test typing
run: |
pip3.14 install 'mypy<1.12.0' types-setuptools
mypy --strict typing_test/test_typing.py

if mypy --strict typing_test/test_badtyping.py; then
echo "Bad types weren't detected"
exit 1
fi

stubtest python_minifier --allowlist typing_test/stubtest-allowlist.txt

create_release:
name: Create Draft Release
runs-on: ubuntu-24.04
needs:
- package_python2
- package_python3
- documentation
- test_package
- test_typing
permissions:
contents: write
outputs:
release_id: ${{ steps.create_release.outputs.release_id }}
steps:
- name: Checkout
uses: actions/checkout@v4.2.2
with:
fetch-depth: 1
show-progress: false
persist-credentials: false

- name: Generate Release Notes
run: |
cp .github/release_preamble.md release_body.md

# Extract the topmost changelog section (first version found)
changelog_section=$(awk '/^## \[.*\]/{if(!found){found=1; next}} /^## \[.*\]/{if(found) exit} found' CHANGELOG.md)
if [ -z "$changelog_section" ]; then
echo "No changelog section found, using only release preamble"
else
echo "$changelog_section" >> release_body.md
fi

- name: Create Draft Release
id: create_release
env:
VERSION: ${{ inputs.release_version }}
GH_TOKEN: ${{ github.token }}
run: |
set -e
release_url=$(gh release create "$VERSION" \
--draft \
--title "$VERSION" \
--notes-file release_body.md)
echo "Draft release created: $release_url"

# Extract the untagged release ID from the URL
untagged_id="${release_url##*/tag/}"
echo "release_id=$untagged_id" >> "$GITHUB_OUTPUT"

- name: Download distribution artifacts
uses: actions/download-artifact@v4.1.8
with:
pattern: dist-*
path: dist/
merge-multiple: true

- name: Upload Release Assets
env:
RELEASE_ID: ${{ steps.create_release.outputs.release_id }}
GH_TOKEN: ${{ github.token }}
SDIST: ${{ needs.package_python3.outputs.sdist }}
PYTHON3_WHEEL: ${{ needs.package_python3.outputs.wheel }}
PYTHON2_WHEEL: ${{ needs.package_python2.outputs.wheel }}
run: |
gh release upload "$RELEASE_ID" \
--repo ${{ github.repository }} \
"dist/${SDIST}" \
"dist/${PYTHON3_WHEEL}" \
"dist/${PYTHON2_WHEEL}"
Loading