Skip to content

Commit fb7b0b9

Browse files
author
Alex Godoroja
committed
ci: test versioning in ci
1 parent 0c047fb commit fb7b0b9

1 file changed

Lines changed: 55 additions & 7 deletions

File tree

.github/workflows/publish-python-sdk.yml

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,30 @@ jobs:
107107
run: |
108108
cd sdk/python
109109
110-
# Get latest git tag matching sdk-v*.*.* pattern (SDK-specific tags)
111-
LATEST_TAG=$(git describe --tags --match "sdk-v[0-9]*.[0-9]*.[0-9]*" --abbrev=0 2>/dev/null || echo "sdk-v0.1.0")
110+
# Get current branch name
111+
if [ "${{ github.event_name }}" = "push" ]; then
112+
BRANCH="${{ github.ref_name }}"
113+
elif [ "${{ github.event_name }}" = "workflow_run" ]; then
114+
BRANCH="${{ github.event.workflow_run.head_branch }}"
115+
else
116+
BRANCH="${{ github.ref_name }}"
117+
fi
118+
119+
echo "Branch: $BRANCH"
112120
113-
# Extract version without 'sdk-v' prefix
114-
BASE_VERSION=${LATEST_TAG#sdk-v}
121+
# Get latest SDK tag based on environment
122+
if [ "${{ needs.setup.outputs.environment }}" = "production" ]; then
123+
# Production: Use only production tags (sdk-v*.*.*)
124+
LATEST_TAG=$(git describe --tags --match "sdk-v[0-9]*.[0-9]*.[0-9]*" --abbrev=0 2>/dev/null || echo "sdk-v0.1.0")
125+
else
126+
# Test/Dev: Use dev tags for this branch (sdk-dev-branchname-v*.*.*)
127+
SAFE_BRANCH=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/^build-//')
128+
DEV_TAG_PATTERN="sdk-dev-${SAFE_BRANCH}-v[0-9]*.[0-9]*.[0-9]*"
129+
LATEST_TAG=$(git describe --tags --match "$DEV_TAG_PATTERN" --abbrev=0 2>/dev/null || echo "sdk-dev-${SAFE_BRANCH}-v0.1.0")
130+
fi
131+
132+
# Extract version without prefix
133+
BASE_VERSION=$(echo "$LATEST_TAG" | grep -oP '(?<=v)[0-9]+\.[0-9]+\.[0-9]+$')
115134
116135
# Count commits since last tag (only in sdk/python directory)
117136
COMMITS_SINCE_TAG=$(git rev-list ${LATEST_TAG}..HEAD --count -- . 2>/dev/null || echo "0")
@@ -131,12 +150,13 @@ jobs:
131150
VERSION="${MAJOR}.${MINOR}.${PATCH}"
132151
fi
133152
else
134-
# Test/Dev: Use dev version with commit info
153+
# Test/Dev: Use dev version with branch name and commit info
135154
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
155+
SAFE_BRANCH=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/^build-//')
136156
if [ "$COMMITS_SINCE_TAG" = "0" ]; then
137-
VERSION="${MAJOR}.${MINOR}.${PATCH}.dev1+${SHORT_SHA}"
157+
VERSION="${MAJOR}.${MINOR}.${PATCH}.dev1+${SAFE_BRANCH}.${SHORT_SHA}"
138158
else
139-
VERSION="${MAJOR}.${MINOR}.${PATCH}.dev${COMMITS_SINCE_TAG}+${SHORT_SHA}"
159+
VERSION="${MAJOR}.${MINOR}.${PATCH}.dev${COMMITS_SINCE_TAG}+${SAFE_BRANCH}.${SHORT_SHA}"
140160
fi
141161
fi
142162
@@ -284,6 +304,34 @@ jobs:
284304
echo "3. Package metadata issue"
285305
exit 1
286306
}
307+
308+
- name: Create git tag for dev release
309+
if: needs.setup.outputs.environment == 'test' && steps.check-testpypi.outputs.exists == 'false'
310+
run: |
311+
VERSION=${{ steps.extract-version.outputs.version }}
312+
313+
# Get branch name
314+
if [ "${{ github.event_name }}" = "push" ]; then
315+
BRANCH="${{ github.ref_name }}"
316+
elif [ "${{ github.event_name }}" = "workflow_run" ]; then
317+
BRANCH="${{ github.event.workflow_run.head_branch }}"
318+
else
319+
BRANCH="${{ github.ref_name }}"
320+
fi
321+
322+
SAFE_BRANCH=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/^build-//')
323+
BASE_VERSION=$(echo "$VERSION" | grep -oP '^[0-9]+\.[0-9]+\.[0-9]+')
324+
325+
git config user.name "github-actions[bot]"
326+
git config user.email "github-actions[bot]@users.noreply.github.com"
327+
328+
# Create branch-specific dev tag
329+
git tag -a "sdk-dev-${SAFE_BRANCH}-v${BASE_VERSION}" -m "Python SDK Dev Release v$VERSION (branch: $BRANCH)"
330+
331+
# Push tag
332+
git push origin "sdk-dev-${SAFE_BRANCH}-v${BASE_VERSION}" || echo "Tag already exists or push failed"
333+
334+
echo "✓ Created branch-specific dev tag: sdk-dev-${SAFE_BRANCH}-v${BASE_VERSION}"
287335
288336
- name: Publish to PyPI
289337
if: needs.setup.outputs.environment == 'production' && steps.check-pypi.outputs.exists == 'false'

0 commit comments

Comments
 (0)