Pre-release - Bump version & draft release #11
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: Pre-release - Bump version & draft release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| target_branch: | |
| description: > | |
| "This workflow will create a commit to bump version on a branch. | |
| Enter the target branch: main for SaaS, or release/XX.Y for an LTS version: " | |
| required: true | |
| type: string | |
| default: "main" | |
| permissions: | |
| contents: write | |
| jobs: | |
| pre_release: | |
| runs-on: ubuntu-latest | |
| name: Bump version & draft release | |
| steps: | |
| - name: Checkout target branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.inputs.target_branch }} | |
| token: ${{ secrets.RELEASE_BOT_PAT }} # <<< service PAT | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.12 | |
| cache: "pip" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install bump2version | |
| - name: Set git identity | |
| run: | | |
| git config user.name "kili-release-bot" | |
| git config user.email "kili-release-bot@users.noreply.github.com" | |
| - name: Add the bump commit | |
| env: | |
| GH_TOKEN: ${{ secrets.RELEASE_BOT_PAT }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| git fetch --quiet | |
| curl https://raw.githubusercontent.com/kili-technology/kili-python-sdk/main/.github/scripts/utils.sh --output utils.sh | |
| source ./utils.sh # exposes bump_version | |
| # create bump commit (major / minor / patch) | |
| new_version=$(bump_version commit patch) | |
| echo "New version (bump_version): $new_version" | |
| # Push back to the same branch explicitly | |
| git push origin HEAD:${{ github.event.inputs.target_branch }} | |
| - name: Create tag and draft release | |
| env: | |
| GH_TOKEN: ${{ secrets.RELEASE_BOT_PAT }} # used by gh CLI | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| curl https://raw.githubusercontent.com/kili-technology/kili-python-sdk/main/.github/scripts/utils.sh --output utils.sh | |
| source ./utils.sh | |
| # Get release version from pyproject.toml (now bumped) | |
| release_version=$(get_sdk_version_from_pyproject_toml) | |
| echo "Release version: $release_version" | |
| # Get previous release tag (closest inferior version) | |
| latest_release=$(get_previous_release_tag "$release_version") | |
| echo "Previous release tag: $latest_release" | |
| git fetch --tags --quiet | |
| # Create annotated tag on this commit & push it | |
| git tag -a "$release_version" -m "Release $release_version" | |
| git push origin "$release_version" | |
| # Create draft release | |
| link_to_draft=$(gh release create "$release_version" \ | |
| --draft \ | |
| --title "Release $release_version" \ | |
| --generate-notes \ | |
| --notes-start-tag "$latest_release") | |
| # Extract URL from gh output | |
| link_to_draft=$(echo "$link_to_draft" | grep -o 'https://[^ ]*') | |
| echo "Link to draft release: $link_to_draft" | |
| echo "LINK_TO_DRAFT=$link_to_draft" >> "$GITHUB_ENV" | |
| echo "RELEASE_VERSION=$release_version" >> "$GITHUB_ENV" |