|
| 1 | +name: Create Release Tag |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_ref: |
| 7 | + description: Git ref to tag |
| 8 | + required: true |
| 9 | + default: main |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +env: |
| 15 | + git_user_name: localstack[bot] |
| 16 | + git_user_email: localstack-bot@users.noreply.github.com |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: create-release-tag |
| 20 | + cancel-in-progress: false |
| 21 | + |
| 22 | +jobs: |
| 23 | + create-tag: |
| 24 | + name: Create next CalVer tag |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v6 |
| 29 | + with: |
| 30 | + ref: ${{ inputs.release_ref }} |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Configure Git user |
| 34 | + run: | |
| 35 | + git config user.name "${git_user_name}" |
| 36 | + git config user.email "${git_user_email}" |
| 37 | +
|
| 38 | + - name: Fetch tags |
| 39 | + run: git fetch --tags --force |
| 40 | + |
| 41 | + - name: Compute next CalVer tag |
| 42 | + id: next_tag |
| 43 | + run: | |
| 44 | + set -euo pipefail |
| 45 | + year="$(date -u +%Y)" |
| 46 | + month="$(date -u +%-m)" |
| 47 | + prefix="${year}.${month}." |
| 48 | +
|
| 49 | + latest="$(git tag --list "${prefix}*" --sort=-v:refname | grep -E "^${year}\.${month}\.[0-9]+$" | head -n 1 || true)" |
| 50 | + if [[ -z "${latest}" ]]; then |
| 51 | + patch=0 |
| 52 | + else |
| 53 | + patch="$(( ${latest##*.} + 1 ))" |
| 54 | + fi |
| 55 | +
|
| 56 | + tag="${year}.${month}.${patch}" |
| 57 | + if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then |
| 58 | + echo "Tag ${tag} already exists" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +
|
| 62 | + echo "tag=${tag}" >> "${GITHUB_OUTPUT}" |
| 63 | +
|
| 64 | + - name: Create and push tag |
| 65 | + run: | |
| 66 | + tag="${{ steps.next_tag.outputs.tag }}" |
| 67 | + git tag -a "${tag}" -m "Release ${tag}" |
| 68 | + git push origin "${tag}" |
| 69 | +
|
| 70 | + - name: Print created tag |
| 71 | + run: echo "Created tag ${{ steps.next_tag.outputs.tag }}" |
0 commit comments