diff --git a/scripts/set-versions.sh b/scripts/set-versions.sh index c4cc8015964..4f840b93471 100755 --- a/scripts/set-versions.sh +++ b/scripts/set-versions.sh @@ -15,9 +15,10 @@ SEMVER_REGEX="\ (\\-(${IDENT})(\\.(${IDENT}))*)?\ (\\+${FIELD}(\\.${FIELD})*)?$" -# get current numbers -CURRENT_SEMVER=$(awk '/VERSION_NAME: /{print $2}' bitrise.yml); -CURRENT_VERSION_NUMBER=$(awk '/VERSION_NUMBER: /{print $2}' bitrise.yml); +PACKAGE_JSON_FILE=package.json +ANDROID_BUILD_GRADLE_FILE=android/app/build.gradle +BITRISE_YML_FILE=bitrise.yml +IOS_PROJECT_FILE=ios/MetaMask.xcodeproj/project.pbxproj semver_to_nat () { echo "${1//./}" @@ -28,31 +29,48 @@ log_and_exit () { } perform_updates () { - echo -e "creating release\nsemver version: $SEMVER_VERSION\nversion number: $VERSION_NUMBER" - # update package.json - tmp="package.json_temp" - jq --arg semverVersion "$SEMVER_VERSION" '.version = $semverVersion' package.json > "$tmp" - mv "$tmp" package.json + jq ".version = \"$SEMVER_VERSION\"" $PACKAGE_JSON_FILE | sponge $PACKAGE_JSON_FILE + echo "- $PACKAGE_JSON_FILE updated" # update android/app/build.gradle - sed -i -e 's/versionCode [0-9]\+/versionCode '"$VERSION_NUMBER"'/' android/app/build.gradle - sed -i -e 's/versionName ".*"/versionName "'"$SEMVER_VERSION"'"/' android/app/build.gradle + sed -Ei 's/(\s*versionCode )[0-9]+/\1'"$VERSION_NUMBER"'/' $ANDROID_BUILD_GRADLE_FILE + sed -Ei 's/(\s*versionName )".*"/\1"'"$SEMVER_VERSION"'"/' $ANDROID_BUILD_GRADLE_FILE + echo "- $ANDROID_BUILD_GRADLE_FILE updated" # update bitrise.yml - sed -i -e 's/VERSION_NAME: .*/VERSION_NAME: '"$SEMVER_VERSION"'/' bitrise.yml - sed -i -e 's/VERSION_NUMBER: [0-9]\+/VERSION_NUMBER: '"$VERSION_NUMBER"'/' bitrise.yml + sed -Ei 's/(\s*VERSION_NAME: ).*/\1'"$SEMVER_VERSION"'/' $BITRISE_YML_FILE + sed -Ei 's/(\s*VERSION_NUMBER: )[0-9]+/\1'"$VERSION_NUMBER"'/' $BITRISE_YML_FILE # update flask version numbers in bitrise.yml - sed -i -e 's/FLASK_VERSION_NAME: .*/FLASK_VERSION_NAME: '"$SEMVER_VERSION"'/' bitrise.yml - sed -i -e 's/FLASK_VERSION_NUMBER: [0-9]\+/FLASK_VERSION_NUMBER: '"$VERSION_NUMBER"'/' bitrise.yml + sed -Ei 's/(\s*VERSION_NUMBER: )[0-9]+/\1'"$VERSION_NUMBER"'/' $BITRISE_YML_FILE + sed -Ei 's/(\s*FLASK_VERSION_NUMBER: )[0-9]+/\1'"$VERSION_NUMBER"'/' $BITRISE_YML_FILE + echo "- $BITRISE_YML_FILE updated" + # update ios/MetaMask.xcodeproj/project.pbxproj - sed -i -e 's/MARKETING_VERSION = .*/MARKETING_VERSION = '"$SEMVER_VERSION;"'/' ios/MetaMask.xcodeproj/project.pbxproj - sed -i -e 's/CURRENT_PROJECT_VERSION = [0-9]\+/CURRENT_PROJECT_VERSION = '"$VERSION_NUMBER"'/' ios/MetaMask.xcodeproj/project.pbxproj + sed -Ei 's/(\s*MARKETING_VERSION = ).*/\1'"$SEMVER_VERSION;"'/' $IOS_PROJECT_FILE + sed -Ei 's/(\s*CURRENT_PROJECT_VERSION = )[0-9]+/\1'"$VERSION_NUMBER"'/' $IOS_PROJECT_FILE + echo "- $IOS_PROJECT_FILE updated" + + echo -e "-------------------" + echo -e "files updated with:" + echo -e "semver version: $SEMVER_VERSION" + echo -e "version number: $VERSION_NUMBER" } +# get current numbers +CURRENT_SEMVER=$(awk '/^\s+VERSION_NAME: /{print $2}' $BITRISE_YML_FILE); +CURRENT_VERSION_NUMBER=$(awk '/^\s+VERSION_NUMBER: /{print $2}' $BITRISE_YML_FILE); +CURRENT_FLASK_VERSION_NUMBER=$(awk '/^\s+FLASK_VERSION_NUMBER: /{print $2}' $BITRISE_YML_FILE); + +# ensure version number of main variant and flask are aligned +if [[ "$CURRENT_VERSION_NUMBER" != "$CURRENT_FLASK_VERSION_NUMBER" ]]; then + echo "VERSION_NUMBER $CURRENT_VERSION_NUMBER and FLASK_VERSION_NUMBER $CURRENT_FLASK_VERSION_NUMBER should be the same" + log_and_exit "Check why they are different and fix it before proceeding" +fi + # abort if values are empty if [[ -z $SEMVER_VERSION ]]; then log_and_exit "SEMVER_VERSION not specified, aborting!" @@ -72,20 +90,14 @@ if ! [[ $VERSION_NUMBER =~ $NAT ]] || [[ $VERSION_NUMBER =~ $SEMVER_REGEX ]]; th log_and_exit "$VERSION_NUMBER is not a natural number!" fi -# ensure SEMVER_VERSION goes up -CURRENT_SEMVER_NAT=$(semver_to_nat "$CURRENT_SEMVER") -SEMVER_VERSION_NAT=$(semver_to_nat "$SEMVER_VERSION") - -# if [[ "$SEMVER_VERSION_NAT" -le "$CURRENT_SEMVER_NAT" ]]; then -# echo "semver $SEMVER_VERSION is less than or equal to current: $CURRENT_SEMVER" -# exit 1 -# fi - # ensure VERSION_NUMBER goes up if [[ "$VERSION_NUMBER" -le "$CURRENT_VERSION_NUMBER" ]]; then echo "version $VERSION_NUMBER is less than or equal to current: $CURRENT_VERSION_NUMBER" exit 1 fi -echo "VERSION_NUMBER and SEMVER_VERSION are valid" +echo "VERSION_NUMBER and SEMVER_VERSION are valid." +echo -e "-------------------" +echo "Updating files:" + perform_updates