Skip to content

Commit a3bf665

Browse files
Fix automated releases (#171)
1 parent 4c01efd commit a3bf665

3 files changed

Lines changed: 84 additions & 67 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Create Release Tag
2+
description: Compute the next version tag, create it, and push it.
3+
4+
inputs:
5+
bump:
6+
description: Version bump type (patch or minor)
7+
required: true
8+
9+
outputs:
10+
tag:
11+
description: The created tag
12+
value: ${{ steps.next_tag.outputs.tag }}
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Configure Git user
18+
shell: bash
19+
run: |
20+
git config user.name "localstack[bot]"
21+
git config user.email "localstack-bot@users.noreply.github.com"
22+
23+
- name: Compute next version tag
24+
id: next_tag
25+
shell: bash
26+
env:
27+
BUMP: ${{ inputs.bump }}
28+
run: |
29+
set -euo pipefail
30+
31+
latest="$(git tag --list "v0.*.*" --sort=-v:refname | grep -E "^v0\.[0-9]+\.[0-9]+$" | head -n 1 || true)"
32+
if [[ -z "${latest}" ]]; then
33+
minor=1
34+
patch=0
35+
else
36+
current_minor="$(echo "${latest}" | cut -d. -f2)"
37+
current_patch="$(echo "${latest}" | cut -d. -f3)"
38+
if [[ "${BUMP}" == "minor" ]]; then
39+
minor="$(( current_minor + 1 ))"
40+
patch=0
41+
else
42+
minor="${current_minor}"
43+
patch="$(( current_patch + 1 ))"
44+
fi
45+
fi
46+
47+
tag="v0.${minor}.${patch}"
48+
if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
49+
echo "Tag ${tag} already exists"
50+
exit 1
51+
fi
52+
53+
echo "tag=${tag}" >> "${GITHUB_OUTPUT}"
54+
55+
- name: Create and push tag
56+
shell: bash
57+
run: |
58+
tag="${{ steps.next_tag.outputs.tag }}"
59+
git tag -a "${tag}" -m "Release ${tag}"
60+
git push origin "${tag}"
61+
62+
- name: Print created tag
63+
shell: bash
64+
run: echo "Created tag ${{ steps.next_tag.outputs.tag }}"

.github/workflows/automated-release.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,19 @@ jobs:
6262
name: Create release tag
6363
needs: [check-changes, ci]
6464
if: needs.check-changes.outputs.has_changes == 'true'
65-
uses: ./.github/workflows/create-release-tag.yml
66-
with:
67-
release_ref: main
68-
bump: patch
69-
secrets: inherit
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: Checkout code
68+
uses: actions/checkout@v6
69+
with:
70+
ref: main
71+
fetch-depth: 0
72+
token: ${{ secrets.PRO_ACCESS_TOKEN }}
73+
74+
- name: Fetch tags
75+
run: git fetch --tags --force
76+
77+
- name: Create release tag
78+
uses: ./.github/actions/create-release-tag
79+
with:
80+
bump: patch

.github/workflows/create-release-tag.yml

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,10 @@ on:
1414
options:
1515
- patch
1616
- minor
17-
workflow_call:
18-
inputs:
19-
release_ref:
20-
description: Git ref to tag
21-
required: true
22-
default: main
23-
type: string
24-
bump:
25-
description: Version bump type (patch or minor)
26-
required: true
27-
type: string
2817

2918
permissions:
3019
contents: write
3120

32-
env:
33-
git_user_name: localstack[bot]
34-
git_user_email: localstack-bot@users.noreply.github.com
35-
3621
concurrency:
3722
group: create-release-tag
3823
cancel-in-progress: false
@@ -49,53 +34,10 @@ jobs:
4934
fetch-depth: 0
5035
token: ${{ secrets.PRO_ACCESS_TOKEN }}
5136

52-
- name: Configure Git user
53-
env:
54-
GIT_USER_NAME: ${{ env.git_user_name }}
55-
GIT_USER_EMAIL: ${{ env.git_user_email }}
56-
run: |
57-
git config user.name "${GIT_USER_NAME}"
58-
git config user.email "${GIT_USER_EMAIL}"
59-
6037
- name: Fetch tags
6138
run: git fetch --tags --force
6239

63-
- name: Compute next version tag
64-
id: next_tag
65-
env:
66-
BUMP: ${{ inputs.bump }}
67-
run: |
68-
set -euo pipefail
69-
70-
latest="$(git tag --list "v0.*.*" --sort=-v:refname | grep -E "^v0\.[0-9]+\.[0-9]+$" | head -n 1 || true)"
71-
if [[ -z "${latest}" ]]; then
72-
minor=1
73-
patch=0
74-
else
75-
current_minor="$(echo "${latest}" | cut -d. -f2)"
76-
current_patch="$(echo "${latest}" | cut -d. -f3)"
77-
if [[ "${BUMP}" == "minor" ]]; then
78-
minor="$(( current_minor + 1 ))"
79-
patch=0
80-
else
81-
minor="${current_minor}"
82-
patch="$(( current_patch + 1 ))"
83-
fi
84-
fi
85-
86-
tag="v0.${minor}.${patch}"
87-
if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
88-
echo "Tag ${tag} already exists"
89-
exit 1
90-
fi
91-
92-
echo "tag=${tag}" >> "${GITHUB_OUTPUT}"
93-
94-
- name: Create and push tag
95-
run: |
96-
tag="${{ steps.next_tag.outputs.tag }}"
97-
git tag -a "${tag}" -m "Release ${tag}"
98-
git push origin "${tag}"
99-
100-
- name: Print created tag
101-
run: echo "Created tag ${{ steps.next_tag.outputs.tag }}"
40+
- name: Create release tag
41+
uses: ./.github/actions/create-release-tag
42+
with:
43+
bump: ${{ inputs.bump }}

0 commit comments

Comments
 (0)