Skip to content

Commit 537a678

Browse files
author
Evilazaro Alves
committed
Update CI and Release
1 parent bb48d91 commit 537a678

File tree

4 files changed

+318
-750
lines changed

4 files changed

+318
-750
lines changed

.github/actions/ci/bicep-standard-ci/action.yml

Lines changed: 0 additions & 301 deletions
Original file line numberDiff line numberDiff line change
@@ -13,307 +13,6 @@ runs:
1313
sudo apt-get update
1414
echo "✅ Packages updated successfully"
1515
16-
- name: Setup Git identity
17-
shell: bash
18-
run: |
19-
git config user.name "github-actions"
20-
git config user.email "github-actions@github.com"
21-
22-
- name: Debug trigger information
23-
shell: bash
24-
run: |
25-
echo "🐛 Debug Information:"
26-
echo "Event name: ${{ github.event_name }}"
27-
echo "Ref: ${{ github.ref }}"
28-
echo "Head ref: ${{ github.head_ref }}"
29-
echo "Base ref: ${{ github.base_ref }}"
30-
echo "Repository: ${{ github.repository }}"
31-
echo "Actor: ${{ github.actor }}"
32-
echo "SHA: ${{ github.sha }}"
33-
34-
- name: Get branch information
35-
shell: bash
36-
id: branch_info
37-
run: |
38-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
39-
branch_name="${{ github.ref_name }}"
40-
elif [ "${{ github.event_name }}" = "pull_request" ]; then
41-
branch_name="${{ github.head_ref }}"
42-
else
43-
branch_name="${{ github.ref_name }}"
44-
fi
45-
46-
echo "branch_name=$branch_name" >> $GITHUB_OUTPUT
47-
echo "✅ Current branch: $branch_name"
48-
49-
- name: Get latest tag
50-
shell: bash
51-
id: get_tag
52-
run: |
53-
# Fetch all tags
54-
git fetch --tags --force
55-
tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
56-
echo "tag=$tag" >> $GITHUB_OUTPUT
57-
echo "✅ Latest tag: $tag"
58-
59-
- name: Determine release type and strategy
60-
shell: bash
61-
id: determine_release_type
62-
run: |
63-
branch_name="${{ steps.branch_info.outputs.branch_name }}"
64-
should_release="true"
65-
should_publish="true"
66-
67-
echo "🔍 Analyzing branch: $branch_name"
68-
69-
# For PR events, only create pre-releases
70-
if [ "${{ github.event_name }}" = "pull_request" ]; then
71-
echo "📋 Pull Request detected - Creating pre-release"
72-
should_publish="false"
73-
fi
74-
75-
if [[ "$branch_name" == "main" ]]; then
76-
# Main branch: conditional major increment with new rule
77-
release_type="main"
78-
should_publish="true"
79-
echo "✅ Main branch detected - Conditional major release strategy with new rule"
80-
81-
elif [[ "$branch_name" == feature/* ]]; then
82-
# Feature branch: patch increment with overflow logic
83-
release_type="feature"
84-
should_publish="false"
85-
echo "✅ Feature branch detected - Patch increment with overflow strategy (no release publication)"
86-
87-
elif [[ "$branch_name" == fix/* ]]; then
88-
# Fix branch: minor increment with overflow logic
89-
release_type="fix"
90-
should_publish="false"
91-
echo "✅ Fix branch detected - Minor increment with overflow strategy (no release publication)"
92-
93-
else
94-
echo "⚠️ Unsupported branch pattern: $branch_name"
95-
echo "Only main, feature/*, and fix/* branches are supported for releases"
96-
should_release="false"
97-
should_publish="false"
98-
release_type="none"
99-
fi
100-
101-
echo "release_type=$release_type" >> $GITHUB_OUTPUT
102-
echo "should_release=$should_release" >> $GITHUB_OUTPUT
103-
echo "should_publish=$should_publish" >> $GITHUB_OUTPUT
104-
105-
echo "📋 Release Summary:"
106-
echo " - Will create tag and version: $should_release"
107-
echo " - Will publish GitHub release: $should_publish"
108-
109-
- name: Count commits since last tag
110-
shell: bash
111-
id: count_commits
112-
if: steps.determine_release_type.outputs.should_release == 'true'
113-
run: |
114-
last_tag="${{ steps.get_tag.outputs.tag }}"
115-
branch_name="${{ steps.branch_info.outputs.branch_name }}"
116-
117-
echo "🔍 Counting commits for branch: $branch_name"
118-
echo "🏷️ Last tag: $last_tag"
119-
120-
if [ "$last_tag" = "v0.0.0" ]; then
121-
# No previous tags, count all commits
122-
if [[ "$branch_name" == "main" ]]; then
123-
commit_count=$(git rev-list --count HEAD)
124-
else
125-
# For feature/fix branches, count commits in this branch only
126-
merge_base=$(git merge-base HEAD origin/main 2>/dev/null || git merge-base HEAD main 2>/dev/null || echo "")
127-
if [ -n "$merge_base" ]; then
128-
commit_count=$(git rev-list --count ${merge_base}..HEAD)
129-
else
130-
commit_count=$(git rev-list --count HEAD)
131-
fi
132-
fi
133-
else
134-
# Count commits since last tag
135-
if [[ "$branch_name" == "main" ]]; then
136-
commit_count=$(git rev-list --count ${last_tag}..HEAD)
137-
else
138-
# For feature/fix branches, count commits since branch diverged from main
139-
merge_base=$(git merge-base HEAD origin/main 2>/dev/null || git merge-base HEAD main 2>/dev/null || echo "")
140-
if [ -n "$merge_base" ]; then
141-
commit_count=$(git rev-list --count ${merge_base}..HEAD)
142-
else
143-
commit_count=$(git rev-list --count ${last_tag}..HEAD)
144-
fi
145-
fi
146-
fi
147-
148-
# Ensure minimum commit count of 1
149-
if [ "$commit_count" -eq 0 ]; then
150-
commit_count=1
151-
fi
152-
153-
echo "commit_count=$commit_count" >> $GITHUB_OUTPUT
154-
echo "✅ Commits to include: $commit_count"
155-
156-
- name: Calculate next version
157-
shell: bash
158-
id: calculate_next_version
159-
if: steps.determine_release_type.outputs.should_release == 'true'
160-
run: |
161-
current_version="${{ steps.get_tag.outputs.tag }}"
162-
release_type="${{ steps.determine_release_type.outputs.release_type }}"
163-
commit_count="${{ steps.count_commits.outputs.commit_count }}"
164-
branch_name="${{ steps.branch_info.outputs.branch_name }}"
165-
166-
# Remove 'v' prefix if present
167-
current_version=${current_version#v}
168-
IFS='.' read -r major minor patch <<< "$current_version"
169-
170-
echo "📊 Current version: v$major.$minor.$patch"
171-
echo "📊 Release type: $release_type"
172-
echo "📊 Commit count: $commit_count"
173-
174-
case "$release_type" in
175-
main)
176-
# NEW RULE: Main branch conditional major increment
177-
# Only increase major if minor and patch are both 0
178-
# Otherwise, keep major and update minor/patch accordingly
179-
180-
echo "🎯 Main branch: Applying new conditional major increment rule"
181-
echo "📋 Current state: major=$major, minor=$minor, patch=$patch"
182-
183-
if [ "$minor" -eq 0 ] && [ "$patch" -eq 0 ]; then
184-
# Rule condition met: minor=0 AND patch=0 -> increment major
185-
major=$((major + 1))
186-
minor=0
187-
patch=0
188-
echo "✅ Rule condition met (minor=0 AND patch=0): Incrementing major to $major"
189-
else
190-
# Rule condition NOT met: keep major, update minor/patch
191-
echo "⚠️ Rule condition NOT met (minor≠0 OR patch≠0): Keeping major=$major"
192-
193-
# Increment patch first, then handle overflow
194-
new_patch=$((patch + 1))
195-
196-
if [ $new_patch -gt 99 ]; then
197-
# Patch overflow: reset patch to 0 and increment minor
198-
patch=0
199-
minor=$((minor + 1))
200-
201-
# Check if minor also overflows
202-
if [ $minor -gt 99 ]; then
203-
# Minor overflow: reset minor to 0 and increment major
204-
minor=0
205-
major=$((major + 1))
206-
echo "⚠️ Minor overflow detected: Incrementing major to $major, resetting minor to 0"
207-
fi
208-
209-
echo "⚠️ Patch overflow detected: Incrementing minor to $minor, resetting patch to 0"
210-
else
211-
patch=$new_patch
212-
echo "✅ Incrementing patch to $patch"
213-
fi
214-
fi
215-
216-
version_suffix=""
217-
echo "🎯 Main branch result: major=$major, minor=$minor, patch=$patch"
218-
;;
219-
feature)
220-
# Feature branch: patch increment with overflow logic
221-
# patch: if previous patch + commits > 99, then patch = 0 and minor += 1
222-
new_patch=$((patch + commit_count))
223-
224-
echo "🔢 Calculating patch overflow: $patch + $commit_count = $new_patch"
225-
226-
if [ $new_patch -gt 99 ]; then
227-
# Overflow: reset patch to 0 and increment minor
228-
patch=0
229-
minor=$((minor + 1))
230-
231-
# Check if minor also overflows
232-
if [ $minor -gt 99 ]; then
233-
minor=0
234-
major=$((major + 1))
235-
echo "⚠️ Minor overflow detected: Incrementing major to $major, resetting minor to 0"
236-
fi
237-
238-
echo "⚠️ Patch overflow detected: Incrementing minor to $minor, resetting patch to 0"
239-
else
240-
patch=$new_patch
241-
echo "✅ No overflow: Setting patch to $patch"
242-
fi
243-
244-
# Clean branch name for version suffix
245-
clean_branch_name=$(echo "${branch_name#feature/}" | sed 's/[^a-zA-Z0-9]/-/g')
246-
version_suffix="-feature.$clean_branch_name"
247-
;;
248-
fix)
249-
# Fix branch: minor increment with overflow logic
250-
# minor: if previous minor + commits > 99, then minor = 0 and major += 1
251-
new_minor=$((minor + commit_count))
252-
253-
echo "🔢 Calculating minor overflow: $minor + $commit_count = $new_minor"
254-
255-
if [ $new_minor -gt 99 ]; then
256-
# Overflow: reset minor to 0 and increment major
257-
minor=0
258-
major=$((major + 1))
259-
echo "⚠️ Minor overflow detected: Incrementing major to $major, resetting minor to 0"
260-
else
261-
minor=$new_minor
262-
echo "✅ No overflow: Setting minor to $minor"
263-
fi
264-
265-
# Clean branch name for version suffix
266-
clean_branch_name=$(echo "${branch_name#fix/}" | sed 's/[^a-zA-Z0-9]/-/g')
267-
version_suffix="-fix.$clean_branch_name"
268-
;;
269-
*)
270-
echo "❌ Invalid release type: $release_type"
271-
exit 1
272-
;;
273-
esac
274-
275-
# Add PR suffix if this is a pull request
276-
if [ "${{ github.event_name }}" = "pull_request" ]; then
277-
version_suffix="${version_suffix}-pr${{ github.event.number }}"
278-
fi
279-
280-
new_version="v$major.$minor.$patch$version_suffix"
281-
echo "✅ Next version: $new_version"
282-
echo "📊 Final version breakdown: major=$major, minor=$minor, patch=$patch"
283-
echo "new_version=$new_version" >> $GITHUB_OUTPUT
284-
285-
- name: Create and push tag
286-
shell: bash
287-
run: |
288-
tag_name="${{ steps.calculate_next_version.outputs.new_version }}"
289-
branch_name="${{ steps.branch_info.outputs.branch_name }}"
290-
should_publish="${{ steps.determine_release_type.outputs.should_publish }}"
291-
292-
echo "🏷️ Preparing to create tag: $tag_name"
293-
echo "🔀 For branch: $branch_name"
294-
echo "📋 Will publish release: $should_publish"
295-
296-
# Fetch latest tags first to check for existing tags
297-
git fetch --tags --force
298-
299-
# Check if tag already exists before creating it
300-
if git rev-parse "$tag_name" >/dev/null 2>&1; then
301-
echo "⚠️ Tag $tag_name already exists locally or remotely. Skipping tag creation and push."
302-
else
303-
echo "✅ Tag $tag_name does not exist. Creating new tag..."
304-
305-
# Create annotated tag
306-
if [[ "$branch_name" == "main" ]]; then
307-
git tag -a "$tag_name" -m "Release $tag_name from main branch"
308-
else
309-
git tag -a "$tag_name" -m "Development tag $tag_name from $branch_name branch (no release)"
310-
fi
311-
312-
# Push the newly created tag
313-
git push origin "$tag_name"
314-
echo "✅ Tag $tag_name created and pushed successfully"
315-
fi
316-
31716
- name: Build Accelerator Bicep
31817
shell: bash
31918
run: |

0 commit comments

Comments
 (0)