release #15
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 | |
| on: | |
| push: | |
| tags: | |
| - "*-release" | |
| - "*-beta" | |
| workflow_dispatch: | |
| inputs: | |
| tag_name: | |
| description: 'Tag name to simulate (e.g., v1.0.0-release)' | |
| required: true | |
| default: 'v0.1.0-release' | |
| jobs: | |
| details: | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| package_name: ${{ steps.package_information.outputs.package_name }} | |
| new_version: ${{ steps.release.outputs.new_version }} | |
| suffix: ${{ steps.release.outputs.suffix }} | |
| tag_name: ${{ steps.release.outputs.tag_name }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Extract tag and Details | |
| id: release | |
| run: | | |
| if [ "${{ github.ref_type }}" = "tag" ]; then | |
| TAG_NAME=${GITHUB_REF#refs/tags/} | |
| NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}') | |
| SUFFIX=$(echo $TAG_NAME | awk -F'-' '{print $2}') | |
| echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT" | |
| echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "No tag found" | |
| exit 1 | |
| fi | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.12" | |
| - name: Install Poetry | |
| run: | | |
| curl -sSL https://install.python-poetry.org | python3 - | |
| echo "$HOME/.local/bin" >> $GITHUB_PATH | |
| export PATH="$HOME/.local/bin:$PATH" | |
| poetry --version # Ensure poetry is installed | |
| - name: Get Name of Package | |
| id: package_information | |
| run: | | |
| PACKAGE_NAME=$(poetry version | awk '{print $1}') | |
| echo "Package name: $PACKAGE_NAME" | |
| echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT" | |
| check_pypi: | |
| needs: details | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Fetch information from PyPI | |
| run: | | |
| PACKAGE_NAME=${{ needs.details.outputs.package_name }} | |
| response=$(curl -s https://pypi.org/pypi/$PACKAGE_NAME/json || echo "{}") | |
| latest_previous_version=$(echo $response | grep -oP '"releases":\{"\K[^"]+' | sort -rV | head -n 1) | |
| if [ -z "$latest_previous_version" ]; then | |
| latest_previous_version="0.0.0" | |
| fi | |
| echo "Latest version on PyPI: $latest_previous_version" | |
| echo "latest_previous_version=$latest_previous_version" >> $GITHUB_ENV | |
| - name: Compare versions and exit if not newer | |
| run: | | |
| NEW_VERSION=${{ needs.details.outputs.new_version }} | |
| LATEST_VERSION=$latest_previous_version | |
| if [ "$(printf '%s\n' "$LATEST_VERSION" "$NEW_VERSION" | sort -rV | head -n 1)" != "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$LATEST_VERSION" ]; then | |
| echo "The new version $NEW_VERSION is not greater than the latest version $LATEST_VERSION on PyPI." | |
| exit 1 | |
| fi | |
| setup_and_build: | |
| needs: details | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python and Install Poetry | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.12" | |
| - name: Install Poetry | |
| run: | | |
| curl -sSL https://install.python-poetry.org | python3 - | |
| echo "$HOME/.local/bin" >> $GITHUB_PATH | |
| export PATH="$HOME/.local/bin:$PATH" | |
| poetry --version # Ensure poetry is installed | |
| - name: Set project version with Poetry | |
| run: poetry version ${{ needs.details.outputs.new_version }} | |
| - name: Install dependencies | |
| run: poetry install --no-interaction --sync | |
| - name: Build source and wheel distribution | |
| run: poetry build | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| pypi_publish: | |
| name: Upload release to PyPI | |
| needs: [setup_and_build, details] | |
| runs-on: ubuntu-24.04 | |
| environment: | |
| name: release | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - name: Publish distribution to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 |