v0.5.4 - Py <3.11 crash fix #1
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: Build, test n' release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version to release (e.g. 0.5.4 or 0.6.0-beta). Leave empty to use rites/_version.py" | |
| required: false | |
| type: string | |
| jobs: | |
| test: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install package | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install . | |
| - name: Smoke test (import + run examples) | |
| run: python test.py | |
| build-and-release: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.ref == 'refs/heads/main' | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Determine version | |
| id: check_version | |
| run: | | |
| SHOULD_RELEASE=false | |
| VERSION="" | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| INPUT_VERSION="${{ github.event.inputs.version }}" | |
| if [[ -n "$INPUT_VERSION" ]]; then | |
| VERSION="${INPUT_VERSION#v}" | |
| else | |
| VERSION=$(grep -E '^__version__' rites/_version.py | sed -E 's/.*"([^"]+)".*/\1/') | |
| fi | |
| SHOULD_RELEASE=true | |
| else | |
| COMMIT_MSG=$(git log -1 --pretty=%B) | |
| echo "Commit message: $COMMIT_MSG" | |
| if [[ $COMMIT_MSG =~ v([0-9]+\.[0-9]+\.[0-9]+([-+][a-zA-Z0-9.-]+)?) ]]; then | |
| VERSION="${BASH_REMATCH[1]}" | |
| SHOULD_RELEASE=true | |
| fi | |
| fi | |
| if [[ "$SHOULD_RELEASE" == "true" ]]; then | |
| TAG="v${VERSION}" | |
| echo "Releasing version: $VERSION (tag: $TAG)" | |
| echo "SHOULD_RELEASE=true" >> $GITHUB_OUTPUT | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| echo "TAG=$TAG" >> $GITHUB_OUTPUT | |
| if [[ "$VERSION" == *"-"* || "$VERSION" == *"+"* ]]; then | |
| echo "PRERELEASE=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "PRERELEASE=false" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "No release version found; skipping release." | |
| echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up Python | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.x" | |
| - name: Install build tooling | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install build twine | |
| - name: Sync version into rites/_version.py | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| run: | | |
| python - <<'PY' | |
| import os, re | |
| v = os.environ["VERSION"] | |
| path = "rites/_version.py" | |
| with open(path, "r", encoding="utf-8") as f: | |
| content = f.read() | |
| new = re.sub(r'__version__\s*=\s*".*"', f'__version__ = "{v}"', content) | |
| with open(path, "w", encoding="utf-8") as f: | |
| f.write(new) | |
| print(f"Set version to {v}") | |
| PY | |
| env: | |
| VERSION: ${{ steps.check_version.outputs.VERSION }} | |
| - name: Build sdist and wheel | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| run: python -m build | |
| env: | |
| RITES_PKG_VERSION: ${{ steps.check_version.outputs.VERSION }} | |
| - name: Get previous tag | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| id: prev_tag | |
| run: | | |
| tag=$(git tag --sort=-creatordate | head -1 || true) | |
| echo "Most recent tag: $tag" | |
| echo "tag=$tag" >> "$GITHUB_OUTPUT" | |
| - name: Get commit log | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| id: commit_log | |
| run: | | |
| if [ -z "${{ steps.prev_tag.outputs.tag }}" ]; then | |
| echo "log=- First release" >> "$GITHUB_OUTPUT" | |
| else | |
| TEMP_LOG=$(mktemp) | |
| git log ${{ steps.prev_tag.outputs.tag }}..HEAD --pretty=format:"- %s (%an)" > "$TEMP_LOG" | |
| DELIMITER="COMMIT_LOG_DELIMITER_$(date +%s)" | |
| echo "log<<$DELIMITER" >> "$GITHUB_OUTPUT" | |
| cat "$TEMP_LOG" >> "$GITHUB_OUTPUT" | |
| echo "" >> "$GITHUB_OUTPUT" | |
| echo "$DELIMITER" >> "$GITHUB_OUTPUT" | |
| rm "$TEMP_LOG" | |
| fi | |
| - name: Create tag | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| if git rev-parse "${{ steps.check_version.outputs.TAG }}" >/dev/null 2>&1; then | |
| echo "Tag ${{ steps.check_version.outputs.TAG }} already exists; skipping tag creation." | |
| else | |
| git tag -a ${{ steps.check_version.outputs.TAG }} -m "Release ${{ steps.check_version.outputs.TAG }}" | |
| git push origin ${{ steps.check_version.outputs.TAG }} | |
| fi | |
| - name: Create GitHub Release | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.check_version.outputs.TAG }} | |
| name: "rites ${{ steps.check_version.outputs.TAG }}" | |
| body: | | |
| ## rites ${{ steps.check_version.outputs.TAG }} | |
| ### Changes | |
| ${{ steps.commit_log.outputs.log }} | |
| ### Install | |
| ``` | |
| pip install rites==${{ steps.check_version.outputs.VERSION }} | |
| ``` | |
| draft: false | |
| prerelease: ${{ steps.check_version.outputs.PRERELEASE }} | |
| files: dist/* | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to PyPI | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| - name: Upload build artifacts | |
| if: steps.check_version.outputs.SHOULD_RELEASE == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/* |