Skip to content

Commit 5586fa6

Browse files
committed
ci: update version based on upgrade type
1 parent fa82619 commit 5586fa6

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

.github/workflows/update-version.yml

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
---
2-
name: "Update version in package.json"
2+
name: "Update SDK version"
33

44
on:
55
workflow_dispatch:
66
inputs:
7-
version:
8-
description: 'Version to update to (e.g. 1.20.0)'
7+
upgrade_type:
8+
type: choice
9+
description: Upgrade Type
10+
options:
11+
- patch
12+
- minor
13+
# - major
914
required: true
15+
default: none
16+
17+
env:
18+
UPGRADE_TYPE: ${{ github.event.inputs.upgrade_type || 'patch' }}
1019

1120
jobs:
1221
update:
@@ -37,26 +46,54 @@ jobs:
3746
- name: Install jq
3847
run: sudo apt-get install -y jq
3948

40-
- name: Replace version string
49+
- name: Update Version in package.json
4150
id: replace_version
4251
run: |
4352
FILE=./src/Packages/Passport/package.json
44-
VERSION=${{ github.event.inputs.version }}
45-
jq --arg version "$VERSION" '.version = $version' $FILE > tmp.$$.json && mv tmp.$$.json $FILE
53+
54+
CURRENT_VERSION=$(jq -r '.version' $FILE)
55+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
56+
57+
# Increment version based on UPGRADE_TYPE
58+
case "$UPGRADE_TYPE" in
59+
major)
60+
MAJOR=$((MAJOR + 1))
61+
MINOR=0
62+
PATCH=0
63+
;;
64+
minor)
65+
MINOR=$((MINOR + 1))
66+
PATCH=0
67+
;;
68+
patch)
69+
PATCH=$((PATCH + 1))
70+
;;
71+
*)
72+
echo "Invalid upgrade type: $UPGRADE_TYPE"
73+
exit 1
74+
;;
75+
esac
76+
77+
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
78+
jq --arg version "$NEW_VERSION" '.version = $version' $FILE > tmp.$$.json && mv tmp.$$.json $FILE
79+
echo "Updated version in package.json from $CURRENT_VERSION to $NEW_VERSION"
80+
81+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
4682
47-
- name: Replace engine sdk version string
83+
- name: Update SDK Version in SdkVersionInfoHelpers.cs
4884
id: replace_engine_sdk_version
4985
run: |
5086
FILE=./src/Packages/Passport/Runtime/Scripts/Private/Helpers/SdkVersionInfoHelpers.cs
51-
VERSION=${{ github.event.inputs.version }}
52-
sed -i -E "s/[0-9]+\.[0-9]+\.[0-9]+/$VERSION/g" $FILE
87+
NEW_VERSION="${{ steps.replace_version.outputs.version }}"
88+
sed -i -E "s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" $FILE
89+
echo "Updated SDK version in SdkVersionInfoHelpers.cs to $NEW_VERSION"
5390
5491
- uses: gr2m/create-or-update-pull-request-action@v1
5592
env:
5693
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5794
with:
5895
title: "chore: update version"
5996
body: "Update version in package.json"
60-
branch: "chore/update-version-${{ github.event.inputs.version }}"
97+
branch: "chore/update-version-${{ steps.replace_version.outputs.version }}"
6198
commit-message: "chore: update version"
6299
labels: release

0 commit comments

Comments
 (0)