Skip to content

Commit

Permalink
Merge pull request #2127 from bugsnag/ValidateVersionSyntaxInBump
Browse files Browse the repository at this point in the history
Update makefile version checking
  • Loading branch information
clr182 authored Jan 20, 2025
2 parents 0ac2816 + 3f03bad commit f325a5f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
19 changes: 6 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,13 @@ example-app:
@cd ./examples/sdk-app-example/ && ./gradlew clean assembleRelease

bump:
ifneq ($(shell git diff --staged),)
@git diff --staged
@$(error You have uncommitted changes. Push or discard them to continue)
ifneq ($(VERSION),)
@echo "Bumping version to $(VERSION)"
@./scripts/bump-version.sh $(VERSION)
else
@echo "Please provide a version number"
@./scripts/bump-version.sh
endif
ifeq ($(VERSION),)
@$(error VERSION is not defined. Run with `make VERSION=number bump`)
endif
@echo Bumping the version number to $(VERSION)
@sed -i '' "s/bugsnag-android:.*\"/bugsnag-android:$(VERSION)\"/" examples/sdk-app-example/app/build.gradle
@sed -i '' "s/bugsnag-plugin-android-okhttp:.*\"/bugsnag-plugin-android-okhttp:$(VERSION)\"/" examples/sdk-app-example/app/build.gradle
@sed -i '' "s/VERSION_NAME=.*/VERSION_NAME=$(VERSION)/" gradle.properties
@sed -i '' "s/var version: String = .*/var version: String = \"$(VERSION)\",/"\
bugsnag-android-core/src/main/java/com/bugsnag/android/Notifier.kt
@sed -i '' "s/## TBD/## $(VERSION) ($(shell date '+%Y-%m-%d'))/" CHANGELOG.md

.PHONY: check
check:
Expand Down
28 changes: 28 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -e

BRANCH=$(git rev-parse --abbrev-ref HEAD)

if [[ "$1" != "" ]]; then
VERSION=$1
elif [[ "$BRANCH" =~ ^release/v.*$ ]]; then
VERSION=${BRANCH#release/v}
else
echo "Error: Current branch '$BRANCH' does not appear to be a release branch."
echo "Please specify VERSION manually:"
echo "$(basename $0) <version-number>"
exit 1
fi

if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: VERSION '$VERSION' is not in a valid format (e.g., 1.2.3)."
exit 1
fi

echo Bumping the version number to $VERSION
sed -i '' "s/bugsnag-android:.*\"/bugsnag-android:$VERSION\"/" examples/sdk-app-example/app/build.gradle
sed -i '' "s/bugsnag-plugin-android-okhttp:.*\"/bugsnag-plugin-android-okhttp:$VERSION\"/" examples/sdk-app-example/app/build.gradle
sed -i '' "s/VERSION_NAME=.*/VERSION_NAME=$VERSION/" gradle.properties
sed -i '' "s/var version: String = .*/var version: String = \"$VERSION\",/"\
bugsnag-android-core/src/main/java/com/bugsnag/android/Notifier.kt
sed -i '' "s/## TBD/## $VERSION ($(date '+%Y-%m-%d'))/" CHANGELOG.md

0 comments on commit f325a5f

Please sign in to comment.