-
-
Notifications
You must be signed in to change notification settings - Fork 1
WIP: Move release tasks to separate scripts for better reusability #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2fbffb2
Move releasePrepare task to separate script for beter reusibility
tuancoltech 53c6f51
Import prepare_release.gradle script
tuancoltech dbb3ab0
Use dynamic module name in prepare_release gradle script
tuancoltech cbd643f
Move releaseClean and releasePerform tasks to separate scripts for be…
tuancoltech 3608b8a
Move ensureCleanRepo task to separate script. Add release related tas…
tuancoltech 10c4452
Release app and utils module together
tuancoltech 18adfb4
Add org.ajoberstar.grgit plugin for utils modulee for auto version bu…
tuancoltech 4570733
[FOR TESTING] Release utils to mavenLocal for testing
tuancoltech 146e87f
[FOR TESTING] Update gradle-build to run a test release of utils on m…
tuancoltech 832d91d
[FOR TESTING] Perform utils release and print out all release artifacts
tuancoltech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,12 @@ jobs: | |
- run: git config user.name 'Nya Ξlimu' | ||
- run: git config user.email '[email protected]' | ||
|
||
- run: ./gradlew releaseClean | ||
- run: ./gradlew releasePrepare -PbumpType=patch | ||
- run: ./gradlew releasePerform | ||
- run: | | ||
./gradlew releaseClean | ||
./gradlew app:releasePrepare -PbumpType=patch | ||
./gradlew app:releasePerform | ||
|
||
./gradlew utils:releasePrepare -PbumpType=patch | ||
./gradlew utils:releasePerform | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
ext.cleanRelease = { | ||
def clean = true | ||
def applicationId = android.defaultConfig.applicationId | ||
|
||
String headCommitMessage = grgit.head().shortMessage | ||
while (headCommitMessage.contains("[gradle-release-task]")) { | ||
clean = false | ||
println "Found git commit: $headCommitMessage" | ||
if (headCommitMessage.indexOf("$applicationId-") > -1) { | ||
def tagName = headCommitMessage.split("$applicationId-")[1] | ||
println "Removing the git tag: $tagName" | ||
try { | ||
grgit.tag.remove { | ||
names = [tagName] | ||
} | ||
} catch (Exception e) { | ||
println "Error while removing git tag:\n $e" | ||
} | ||
} | ||
println "Resetting the git commit permanently!" | ||
grgit.reset(commit: "HEAD~1", mode: "hard") | ||
headCommitMessage = grgit.head().shortMessage | ||
|
||
} | ||
if (clean){ | ||
println "Repository is already clean" | ||
} | ||
println "Done!" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ext.ensureClean = { | ||
if (!grgit.repository.jgit.status().call().clean) { | ||
throw new GradleException('Git status is not clean, please stash your changes!') | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ext.performRelease = { | ||
boolean force = false | ||
if (project.properties.containsKey("force")) { | ||
force = project.properties["force"] | ||
} | ||
println "Pushing the newest commits to the remote repository (force: $force)" | ||
try { | ||
grgit.push(force: force, tags: true) | ||
} catch (Exception e) { | ||
throw new GradleException("Failed to push to the repo,\n" + | ||
" you can try using -Pforce=true parameter to force the push, error: \n$e") | ||
} | ||
println "Done!" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
ext.prepareRelease = { | ||
def applicationId = android.defaultConfig.applicationId | ||
def versionName = android.defaultConfig.versionName | ||
|
||
if (versionName.indexOf("-") > -1) { | ||
versionName = versionName.split("-")[0] | ||
} | ||
|
||
// Prepare the release commit with the specific tag. | ||
String buildText = buildFile.getText() | ||
buildText = buildText.replaceFirst(/versionName(\s+.*)/, "versionName '$versionName'") | ||
buildFile.setText(buildText) //replace the build file's text | ||
grgit.add(patterns: [project.name + '/build.gradle']) | ||
try { | ||
grgit.commit(message: "[gradle-release-task] prepare release $applicationId-$versionName") | ||
} catch (Exception e) { | ||
throw new GradleException("Failed to commit, error:\n $e") | ||
} | ||
try { | ||
grgit.tag.add { | ||
name = versionName | ||
message = "Release of $versionName" | ||
} | ||
} catch (Exception e) { | ||
throw new GradleException("Failed to tag the repo, error:\n $e") | ||
} | ||
|
||
// Set new version name from input parameters. | ||
def newVersionName | ||
if (project.properties.containsKey("bumpVersion")) { | ||
newVersionName = project.properties["bumpVersion"] | ||
println "Bumping the version directly (bumpVersion=$newVersionName)" | ||
} else if (project.properties.containsKey("bumpType")) { | ||
def (major, minor, patch) = versionName.tokenize('.') | ||
switch (bumpType) { | ||
case "major": | ||
major = major.toInteger() + 1 | ||
minor = 0 | ||
patch = 0 | ||
break | ||
case "minor": | ||
minor = minor.toInteger() + 1 | ||
break | ||
case "patch": | ||
patch = patch.toInteger() + 1 | ||
break | ||
} | ||
newVersionName = "$major.$minor.$patch" | ||
} else { | ||
throw new GradleException('Either bumpType or bumpVersion parameters should be provided') | ||
} | ||
|
||
// Prepare for next development iteration. | ||
def versionCode = android.defaultConfig.versionCode | ||
def newVersionCode = versionCode + 1 | ||
println "Bumping versionName from $versionName to $newVersionName" | ||
println "Bumping versionCode from $versionCode to $newVersionCode" | ||
buildText = buildFile.getText() | ||
buildText = buildText.replaceFirst(/versionName(\s+.*)/, "versionName '$newVersionName-SNAPSHOT'") | ||
buildText = buildText.replaceFirst(/versionCode(\s+.*)/, "versionCode $newVersionCode") | ||
buildFile.setText(buildText) //replace the build file's text | ||
grgit.add(patterns: [project.name + '/build.gradle']) | ||
grgit.commit(message: "[gradle-release-task] prepare for next development iteration") | ||
println "Done!" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter Handling for Version Bumping
There is a potential issue in the switch-case block: the variable
bumpType
is referenced without being explicitly defined. This could lead to runtime errors ifbumpType
is not already available in the scope. To improve clarity and reliability, extract the property into a local variable before using it. For instance:This ensures that
bumpType
is defined and clarifies its provenance.📝 Committable suggestion