Skip to content

Commit

Permalink
fix: make version setting script work with both main and flask (#9780)
Browse files Browse the repository at this point in the history
- Fix the release number search and replace for Flask
- fix the package.json parsing with Jq and sponge (thanks @legobeat)
- fix sed -e commands to be more robust
- make the syntax specifically work for Ubuntu Sed version as it's the
CI target (thanks @legobeat)
  - add capture group and back ref to prevent repeating the key string
- check for spaces before the key (that's what actually broke the script
as `VERSION_NUMBER` matches `VERSION_NUMBER` and `FLASK_VERSION_NUMBER`.
With a space before, there's no confusion)
- move sed -i command as it was creating backups and mistakingly use
"-e" as the suffix
- Extract file names in constants
- improve console output messages to actually match steps
- add check that `VERSION_NUMBER` and `FLASK_VERSION_NUMBER` are similar
before starting. They should be.
- remove dead code.

Fixes #9770
  • Loading branch information
NicolasMassart authored May 29, 2024
1 parent b013c71 commit 63e9ff9
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions scripts/set-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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//./}"
Expand All @@ -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!"
Expand All @@ -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

0 comments on commit 63e9ff9

Please sign in to comment.