Skip to content

[DX-3571] ci: update version gh action to handle alpha releases #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: "Update SDK version"

on:
Expand All @@ -13,9 +12,15 @@ on:
# - major
required: true
default: patch
mark_as_alpha:
type: boolean
description: Mark as alpha release
required: false
default: false

env:
UPGRADE_TYPE: ${{ github.event.inputs.upgrade_type || 'patch' }}
MARK_AS_ALPHA: ${{ github.event.inputs.mark_as_alpha || false }}

jobs:
update:
Expand All @@ -30,7 +35,6 @@ jobs:
id: check_team
run: |
./.github/scripts/check_team_membership.sh "${{ github.actor }}" "${{ secrets.UNITY_IMMUTABLE_SDK_GITHUB_TOKEN }}"
# shellcheck disable=SC1090
source "$GITHUB_ENV"
echo "${{ github.actor }} is a member of the SDK team: $IS_MEMBER"
if [[ "$IS_MEMBER" != "true" ]]; then
Expand All @@ -53,29 +57,35 @@ jobs:
MARKETPLACE_FILE=./src/Packages/Marketplace/package.json

CURRENT_VERSION=$(jq -r '.version' $PASSPORT_FILE)
echo "CURRENT_VERSION: $CURRENT_VERSION"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"

# Increment version based on UPGRADE_TYPE
case "$UPGRADE_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
HAS_ALPHA=$(echo "$CURRENT_VERSION" | grep -q "\.alpha" && echo "true" || echo "false")
echo "HAS_ALPHA: $HAS_ALPHA"
NEW_VERSION=""

if [[ "$HAS_ALPHA" == "true" ]]; then
# If version is alpha and upgrade type is patch, don't increment patch
if [ "$UPGRADE_TYPE" == "patch" ]; then
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
elif [ "$UPGRADE_TYPE" == "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
fi
else
if [ "$UPGRADE_TYPE" == "patch" ]; then
PATCH=$((PATCH + 1))
;;
*)
echo "Invalid upgrade type: $UPGRADE_TYPE"
exit 1
;;
esac

NEW_VERSION="$MAJOR.$MINOR.$PATCH"
elif [ "$UPGRADE_TYPE" == "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
fi
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
fi

if [[ "$MARK_AS_ALPHA" == "true" && "$HAS_ALPHA" == "false" ]]; then
NEW_VERSION="$NEW_VERSION.alpha"
fi

# Update Passport package.json
jq --arg version "$NEW_VERSION" '.version = $version' $PASSPORT_FILE > tmp.$$.json && mv tmp.$$.json $PASSPORT_FILE
Expand Down
Loading