Create Release Tag #5
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: Create Release Tag | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_ref: | |
| description: Git ref to tag | |
| required: true | |
| default: main | |
| bump: | |
| description: Version bump type | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| permissions: | |
| contents: write | |
| env: | |
| git_user_name: localstack[bot] | |
| git_user_email: localstack-bot@users.noreply.github.com | |
| concurrency: | |
| group: create-release-tag | |
| cancel-in-progress: false | |
| jobs: | |
| create-tag: | |
| name: Create next CalVer tag | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ inputs.release_ref }} | |
| fetch-depth: 0 | |
| token: ${{ secrets.PRO_ACCESS_TOKEN }} | |
| - name: Configure Git user | |
| env: | |
| GIT_USER_NAME: ${{ env.git_user_name }} | |
| GIT_USER_EMAIL: ${{ env.git_user_email }} | |
| run: | | |
| git config user.name "${GIT_USER_NAME}" | |
| git config user.email "${GIT_USER_EMAIL}" | |
| - name: Fetch tags | |
| run: git fetch --tags --force | |
| - name: Compute next version tag | |
| id: next_tag | |
| env: | |
| BUMP: ${{ inputs.bump }} | |
| run: | | |
| set -euo pipefail | |
| latest="$(git tag --list "v0.*.*" --sort=-v:refname | grep -E "^v0\.[0-9]+\.[0-9]+$" | head -n 1 || true)" | |
| if [[ -z "${latest}" ]]; then | |
| minor=1 | |
| patch=0 | |
| else | |
| current_minor="$(echo "${latest}" | cut -d. -f2)" | |
| current_patch="$(echo "${latest}" | cut -d. -f3)" | |
| if [[ "${BUMP}" == "minor" ]]; then | |
| minor="$(( current_minor + 1 ))" | |
| patch=0 | |
| else | |
| minor="${current_minor}" | |
| patch="$(( current_patch + 1 ))" | |
| fi | |
| fi | |
| tag="v0.${minor}.${patch}" | |
| if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then | |
| echo "Tag ${tag} already exists" | |
| exit 1 | |
| fi | |
| echo "tag=${tag}" >> "${GITHUB_OUTPUT}" | |
| - name: Create and push tag | |
| run: | | |
| tag="${{ steps.next_tag.outputs.tag }}" | |
| git tag -a "${tag}" -m "Release ${tag}" | |
| git push origin "${tag}" | |
| - name: Print created tag | |
| run: echo "Created tag ${{ steps.next_tag.outputs.tag }}" |