8181 actor : ${{ github.actor }}
8282 qms_are_allowed : " false"
8383
84+ - name : check for package.json
85+ id : check-package-json
86+ run : |
87+ if [ -f "package.json" ]; then
88+ echo "is_package_json=true" >> "$GITHUB_OUTPUT"
89+ else
90+ echo "is_package_json=false" >> "$GITHUB_OUTPUT"
91+ fi
92+
8493 - name : get release version from input
8594 if : ${{ inputs.skip_branch_check == false }}
8695 id : get-release-version-from-input
@@ -93,38 +102,41 @@ jobs:
93102 exit 1
94103 fi
95104
96- file_release_version="$(jq -r '.version' package.json | cut -d '-' -f 1)"
97- file_release_version="${file_release_version//[^0-9.]}"
98- echo "file_release_version=$file_release_version"
99- file_major=$(echo "$file_release_version" | cut -d'.' -f1)
100- file_minor=$(echo "$file_release_version" | cut -d'.' -f2)
101- file_patch=$(echo "$file_release_version" | cut -d'.' -f3)
105+ # Check if package.json exists and validate the version against it
106+ if [ "${{ steps.check-package-json.outputs.is_package_json }}" == "true" ]; then
107+ file_release_version="$(jq -r '.version' package.json | cut -d '-' -f 1)"
108+ file_release_version="${file_release_version//[^0-9.]}"
109+ echo "file_release_version=$file_release_version"
110+ file_major=$(echo "$file_release_version" | cut -d'.' -f1)
111+ file_minor=$(echo "$file_release_version" | cut -d'.' -f2)
112+ file_patch=$(echo "$file_release_version" | cut -d'.' -f3)
102113
103- echo "Stable release version: $file_major.$file_minor.$file_patch"
114+ echo "Stable release version: $file_major.$file_minor.$file_patch"
104115
105- input_major=$(echo "$input_release_version" | cut -d'.' -f1)
106- input_minor=$(echo "$input_release_version" | cut -d'.' -f2)
107- input_patch=$(echo "$input_release_version" | cut -d'.' -f3)
116+ input_major=$(echo "$input_release_version" | cut -d'.' -f1)
117+ input_minor=$(echo "$input_release_version" | cut -d'.' -f2)
118+ input_patch=$(echo "$input_release_version" | cut -d'.' -f3)
108119
109- if [ "$input_major" -eq "$file_major" ]; then
110- if [ "$input_minor" -eq "$file_minor" ]; then
111- if [ "$input_patch" -eq "$file_patch" ]; then
112- echo "Valid patch version input"
120+ if [ "$input_major" -eq "$file_major" ]; then
121+ if [ "$input_minor" -eq "$file_minor" ]; then
122+ if [ "$input_patch" -eq "$file_patch" ]; then
123+ echo "Valid patch version input"
124+ else
125+ echo "Error: Patch version must match the package.json version without the -SNAPSHOT suffix."
126+ exit 1
127+ fi
128+ elif [ "$input_minor" -gt "$file_minor" ] && [ "$input_patch" -eq 0 ]; then
129+ echo "Valid minor version input"
113130 else
114- echo "Error: Patch version must match the package.json version without the -SNAPSHOT suffix ."
131+ echo "Error: Minor version is invalid ."
115132 exit 1
116133 fi
117- elif [ "$input_minor " -gt "$file_minor" ] && [ "$input_patch" -eq 0 ]; then
118- echo "Valid minor version input"
134+ elif [ "$input_major " -gt "$file_major" ] && [ "$input_minor" -eq 0 ] && [ "$input_patch" -eq 0 ]; then
135+ echo "Valid major version input"
119136 else
120- echo "Error: Minor version is invalid."
137+ echo "Error: Version input is invalid based on semantic versioning rules ."
121138 exit 1
122139 fi
123- elif [ "$input_major" -gt "$file_major" ] && [ "$input_minor" -eq 0 ] && [ "$input_patch" -eq 0 ]; then
124- echo "Valid major version input"
125- else
126- echo "Error: Version input is invalid based on semantic versioning rules."
127- exit 1
128140 fi
129141
130142 echo "New version is $input_major.$input_minor.$input_patch"
@@ -136,6 +148,7 @@ jobs:
136148 git config user.email "<>"
137149 git checkout -b release-"$RELEASE_VERSION"
138150 - name : Update package.json
151+ if : ${{ steps.check-package-json.outputs.is_package_json == 'true' }}
139152 run : |
140153 sed -i "s/^\(\s*\)\"version\".*/\1\"version\": \"$RELEASE_VERSION\",/" package.json
141154 git add package.json
@@ -225,7 +238,7 @@ jobs:
225238 git add .
226239 - name : Commit changes
227240 run : |
228- git commit -m "Prepare release version $RELEASE_VERSION"
241+ git commit --allow-empty - m "Prepare release version $RELEASE_VERSION"
229242 - name : push all changes
230243 run : |
231244 git push origin release-"$RELEASE_VERSION"
0 commit comments