release autowrap #25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: release autowrap | |
| on: | |
| workflow_dispatch: # manual trigger | |
| inputs: | |
| version: | |
| description: 'Version to release (empty = use version from autowrap/version.py)' | |
| default: '' | |
| next_version: | |
| description: 'Next development version (empty = minor bump from release version)' | |
| default: '' | |
| jobs: | |
| build_publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Determine release version | |
| id: version | |
| run: | | |
| INPUT_VER="${{ github.event.inputs.version }}" | |
| if [ -z "$INPUT_VER" ]; then | |
| # Deduce version from autowrap/version.py | |
| RELEASE_VER=$(python3 -c 'from autowrap.version import __version__; print(__version__)') | |
| echo "Using version from autowrap/version.py: $RELEASE_VER" | |
| else | |
| # Validate version format (only allow digits and dots) | |
| if ! echo "$INPUT_VER" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then | |
| echo "Error: Invalid version format. Expected format: X.Y.Z (e.g., 1.2.3)" | |
| exit 1 | |
| fi | |
| RELEASE_VER="$INPUT_VER" | |
| echo "Using input version: $RELEASE_VER" | |
| # Update version.py with the specified version | |
| sed -i -e "s/^__version__ = \".*\"/__version__ = \"$RELEASE_VER\"/g" autowrap/version.py | |
| TUPLE_VER=$(echo $RELEASE_VER | sed 's/\./, /g') | |
| sed -i -e "s/^__version_tuple__ = (.*)/__version_tuple__ = ($TUPLE_VER)/g" autowrap/version.py | |
| fi | |
| echo "version=$RELEASE_VER" >> $GITHUB_OUTPUT | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install -U pip build | |
| - name: Build wheel and source distribution | |
| run: | | |
| python -m build | |
| - name: Publish package to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_RELEASE_AUTOWRAP }} | |
| packages-dir: ${{ github.workspace }}/dist | |
| - name: Create github release | |
| uses: softprops/action-gh-release@v2 | |
| id: create_release | |
| with: | |
| draft: false | |
| prerelease: false | |
| name: ${{ steps.version.outputs.version }} | |
| tag_name: release/${{ steps.version.outputs.version }} | |
| body_path: CHANGELOG.md | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - name: Setup things for new cycle | |
| id: setup_new | |
| run: | | |
| NEXT_VER="${{ github.event.inputs.next_version }}" | |
| RELEASE_VER="${{ steps.version.outputs.version }}" | |
| if [ -z "$NEXT_VER" ]; then | |
| NEXT_VER=$(echo $RELEASE_VER | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') | |
| else | |
| # Validate version format (only allow digits and dots) | |
| if ! echo "$NEXT_VER" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then | |
| echo "Error: Invalid next version format. Expected format: X.Y.Z (e.g., 1.2.3)" | |
| exit 1 | |
| fi | |
| fi | |
| echo >> HISTORY.md | |
| cat CHANGELOG.md >> HISTORY.md | |
| echo >> HISTORY.md | |
| rm CHANGELOG.md && echo "autowrap $NEXT_VER" > CHANGELOG.md | |
| # Update string version | |
| sed -i -e "s/^__version__ = \".*\"/__version__ = \"$NEXT_VER\"/g" autowrap/version.py | |
| # Update tuple version for backward compatibility | |
| TUPLE_VER=$(echo $NEXT_VER | sed 's/\./, /g') | |
| sed -i -e "s/^__version_tuple__ = (.*)/__version_tuple__ = ($TUPLE_VER)/g" autowrap/version.py | |
| - uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: New release cycle | |
| file_pattern: CHANGELOG.md HISTORY.md autowrap/version.py |