Merge pull request #279 from ghantoos/f/engine-v2 #60
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: Publish Python 🐍 distribution 📦 to PyPI | |
| on: | |
| push: | |
| branches: | |
| - pre-release | |
| tags: | |
| - "*" | |
| permissions: | |
| contents: read | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/limited-shell | |
| permissions: | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.x" | |
| - name: Decide whether to publish | |
| id: decide | |
| env: | |
| REF_TYPE: ${{ github.ref_type }} | |
| REF_NAME: ${{ github.ref_name }} | |
| SHA: ${{ github.sha }} | |
| BEFORE_SHA: ${{ github.event.before }} | |
| run: | | |
| set -euo pipefail | |
| CURRENT_VERSION="$(python3 -c 'from lshell.variables import __version__; print(__version__)')" | |
| echo "version=${CURRENT_VERSION}" >> "${GITHUB_OUTPUT}" | |
| # Official releases: tag is required and must match package version. | |
| if [[ "${REF_TYPE}" == "tag" ]]; then | |
| if [[ "${REF_NAME}" == "${CURRENT_VERSION}" ]]; then | |
| echo "should_publish=true" >> "${GITHUB_OUTPUT}" | |
| echo "reason=tag_release" >> "${GITHUB_OUTPUT}" | |
| else | |
| echo "should_publish=false" >> "${GITHUB_OUTPUT}" | |
| echo "reason=tag_version_mismatch" >> "${GITHUB_OUTPUT}" | |
| fi | |
| exit 0 | |
| fi | |
| # Auto RC release from pre-release only when version file changed. | |
| if [[ "${REF_NAME}" != "pre-release" ]]; then | |
| echo "should_publish=false" >> "${GITHUB_OUTPUT}" | |
| echo "reason=not_pre_release_branch" >> "${GITHUB_OUTPUT}" | |
| exit 0 | |
| fi | |
| if [[ "${CURRENT_VERSION}" != *rc* ]]; then | |
| echo "should_publish=false" >> "${GITHUB_OUTPUT}" | |
| echo "reason=not_rc_version" >> "${GITHUB_OUTPUT}" | |
| exit 0 | |
| fi | |
| if [[ -z "${BEFORE_SHA}" || "${BEFORE_SHA}" =~ ^0+$ ]]; then | |
| echo "should_publish=false" >> "${GITHUB_OUTPUT}" | |
| echo "reason=missing_before_sha" >> "${GITHUB_OUTPUT}" | |
| exit 0 | |
| fi | |
| if ! git diff --name-only "${BEFORE_SHA}..${SHA}" | grep -qx "lshell/variables.py"; then | |
| echo "should_publish=false" >> "${GITHUB_OUTPUT}" | |
| echo "reason=version_file_not_changed" >> "${GITHUB_OUTPUT}" | |
| exit 0 | |
| fi | |
| echo "should_publish=true" >> "${GITHUB_OUTPUT}" | |
| echo "reason=rc_version_file_changed" >> "${GITHUB_OUTPUT}" | |
| - name: Decision summary | |
| run: | | |
| echo "should_publish=${{ steps.decide.outputs.should_publish }}" | |
| echo "version=${{ steps.decide.outputs.version }}" | |
| echo "reason=${{ steps.decide.outputs.reason }}" | |
| - name: Build distribution 📦 | |
| if: steps.decide.outputs.should_publish == 'true' | |
| run: | | |
| python3 -m pip install --upgrade build | |
| python3 -m build | |
| - name: Publish distribution 📦 to PyPI | |
| if: steps.decide.outputs.should_publish == 'true' | |
| uses: pypa/gh-action-pypi-publish@release/v1 |