Skip to content

Commit 14dcb0a

Browse files
committed
testing github actions for versioning
1 parent 8c14c24 commit 14dcb0a

2 files changed

Lines changed: 52 additions & 108 deletions

File tree

.github/workflows/main-build.yml

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,85 @@
11
name: Version and Tag on Merge to Main
22

33
on:
4+
push:
5+
branches:
6+
- feature/auto-increment-version-and-tag-repo
47
pull_request:
58
branches:
69
- main
710
types:
811
- closed
912

13+
permissions:
14+
contents: write
15+
1016
jobs:
1117
tag-version:
1218
if: github.event.pull_request.merged == true
13-
runs-on: ubuntu-latest
19+
runs-on:
20+
group: databricks-solutions-protected-runner-group
1421

1522
steps:
1623
- name: Checkout repo
1724
uses: actions/checkout@v4
1825
with:
19-
fetch-depth: 0 # So tags are available
26+
ref: main
27+
fetch-depth: 0
2028

21-
- name: Get latest tag
22-
id: get_tag
29+
- name: Read current version
30+
id: current
2331
run: |
24-
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
25-
echo "LAST_TAG=$LAST_TAG"
26-
echo "last_tag=$LAST_TAG" >> $GITHUB_OUTPUT
32+
VERSION=$(cat VERSION | tr -d '[:space:]')
33+
VERSION=${VERSION#v}
34+
IFS='.' read -r MAJOR MINOR FIX <<< "$VERSION"
35+
echo "major=$MAJOR" >> $GITHUB_OUTPUT
36+
echo "minor=$MINOR" >> $GITHUB_OUTPUT
37+
echo "fix=$FIX" >> $GITHUB_OUTPUT
38+
echo "Current version: $MAJOR.$MINOR.$FIX"
2739
28-
- name: Compute next version
40+
- name: Determine version bump from branch name
2941
id: bump
3042
run: |
31-
OLD=${{ steps.get_tag.outputs.last_tag }}
32-
VERS=${OLD#v}
33-
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERS"
34-
PATCH=$((PATCH + 1))
35-
NEW="v$MAJOR.$MINOR.$PATCH"
36-
echo "NEW_VERSION=$NEW"
37-
echo "new_version=$NEW" >> $GITHUB_OUTPUT
38-
39-
- name: Fail if version is not incremented
40-
run: |
41-
if [ "${{ steps.get_tag.outputs.last_tag }}" = "${{ steps.bump.outputs.new_version }}" ]; then
42-
echo "❌ Version not incremented. Current tag (${{ steps.get_tag.outputs.last_tag }}) is the same as the new tag."
43-
exit 1
43+
BRANCH="${{ github.event.pull_request.head.ref }}"
44+
BRANCH_LOWER=$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]')
45+
echo "Merged branch: $BRANCH (normalized: $BRANCH_LOWER)"
46+
47+
MAJOR=${{ steps.current.outputs.major }}
48+
MINOR=${{ steps.current.outputs.minor }}
49+
FIX=${{ steps.current.outputs.fix }}
50+
51+
if [[ "$BRANCH_LOWER" == feature* ]]; then
52+
MINOR=$((MINOR + 1))
53+
FIX=0
54+
echo "Feature branch — bumping minor, resetting fix to 0"
55+
elif [[ "$BRANCH_LOWER" == fix* ]]; then
56+
FIX=$((FIX + 1))
57+
echo "Fix branch — bumping fix"
58+
else
59+
echo "::warning::Branch '$BRANCH' does not start with 'feature' or 'fix'. Skipping version bump."
60+
echo "skip=true" >> $GITHUB_OUTPUT
61+
exit 0
4462
fi
4563
64+
NEW_VERSION="$MAJOR.$MINOR.$FIX"
65+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
66+
echo "New version: $NEW_VERSION"
67+
4668
- name: Write VERSION file
69+
if: steps.bump.outputs.skip != 'true'
4770
run: |
48-
echo "${{ steps.bump.outputs.new_version }}" | sed 's/^v//' > VERSION
71+
echo "v${{ steps.bump.outputs.new_version }}" > VERSION
4972
cat VERSION
5073
51-
- name: Tag and push
74+
- name: Commit, tag, and push
75+
if: steps.bump.outputs.skip != 'true'
5276
env:
53-
TAG: ${{ steps.bump.outputs.new_version }}
77+
NEW_VERSION: ${{ steps.bump.outputs.new_version }}
5478
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5579
run: |
5680
git config user.name "github-actions"
5781
git config user.email "github-actions@github.com"
58-
git tag $TAG
59-
git push origin $TAG
82+
git add VERSION
83+
git commit -m "Bump version to $NEW_VERSION"
84+
git tag "v$NEW_VERSION"
85+
git push origin main --tags

.github/workflows/main-versioning.yml

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)