Skip to content

Commit

Permalink
#Changed#
Browse files Browse the repository at this point in the history
Build script changed for Github release
  • Loading branch information
hui.zhao committed Feb 26, 2020
1 parent f267c42 commit 82c0fea
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ android-godeye-toolboxes/android-godeye-okhttp/.settings
android-godeye-toolboxes/android-godeye-xcrash/.settings
android-godeye-toolboxes/android-godeye-okhttp/.classpath
android-godeye-toolboxes/android-godeye-xcrash/.classpath
github_release
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ install:

script:
- ./gradlew clean build jacocoTestReport
- ./gradlew assembleRelease

notifications:
email:
- [email protected]

before_deploy:
- ./gradlew generateChangelogOfNewVersion
- ./gradlew prepareForRelease

deploy:
- provider: script
Expand All @@ -46,8 +45,8 @@ deploy:
branch: master
- provider: releases
api_key: $GITHUB_TOKEN
file: "./android-godeye-sample/build/outputs/apk/release/android-godeye-sample-release.apk"
release_notes_file: "./CHANGELOG_NEW_VERSION.tmp"
file_glob: true
file: github_release/*
skip_cleanup: true
on:
tags: true
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ task clean(type: Delete) {
}

apply from: rootProject.file('gradle/gradle-version-support.gradle')
apply from: rootProject.file('gradle/gradle-changelog-support.gradle')
apply from: rootProject.file('gradle/gradle-changelog-support.gradle')
apply from: rootProject.file('gradle/gradle-github-release-support.gradle')
82 changes: 48 additions & 34 deletions gradle/gradle-changelog-support.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ task generateChangelog() {

generateChangelog.onlyIf { project.hasProperty('changelogVersion') }

/**
* generate CHANGELOG_3_2_1.md
*/
task generateChangelogOfNewVersion() {
doLast {
ChangelogMDFile changelogMDFile = new ChangelogMDFile()
changelogMDFile.parseFromMD(rootProject.file("CHANGELOG.md"))
Version newVersionName = changelogMDFile.getNewVersionName()
String changelogOfNewVersion = changelogMDFile.getChangelogOfNewVersion()
rootProject.file("CHANGELOG_NEW_VERSION.tmp").write(changelogOfNewVersion, "utf-8")
def changelogFile = rootProject.file("CHANGELOG_" + newVersionName.toStringOfFileName() + ".md")
changelogFile.write(changelogOfNewVersion, "utf-8")
}
}

Expand Down Expand Up @@ -103,6 +108,42 @@ class ChangelogMDFile {

public List<ChangelogVersionSectionWithContent> changelogVersionSectionWithContentList

public void parseFromMD(File file) {
List<String> lines = file.readLines()
changelogVersionSectionWithContentList = new LinkedList<>()
ChangelogVersionSectionWithContent currentChangelogVersionSectionWithContent
ChangelogTypeWithContent currentChangelogTypeWithContent
for (String line : lines) {
line = line.trim()
if (line.startsWith("##") && !line.startsWith("###")) {
ChangelogVersionSectionWithContent changelogVersionSectionWithContent = new ChangelogVersionSectionWithContent(new Version(line.substring(2).trim()), new ArrayList<>())
changelogVersionSectionWithContentList.add(changelogVersionSectionWithContent)
currentChangelogVersionSectionWithContent = changelogVersionSectionWithContent
// println "[CHANGELOG] parseFromMD get section line: " + line + ",currentChangelogVersionSectionWithContent:" + currentChangelogVersionSectionWithContent
} else if (line.startsWith("###") && !line.startsWith("####")) {
if (currentChangelogVersionSectionWithContent != null) {
ChangelogTypeWithContent changelogTypeWithContent = new ChangelogTypeWithContent(ChangelogType.valueOf(line.substring(3).trim()), new ArrayList<>())
currentChangelogVersionSectionWithContent.contents.add(changelogTypeWithContent)
currentChangelogTypeWithContent = changelogTypeWithContent
// println "[CHANGELOG] parseFromMD get type line: " + line + ",currentChangelogTypeWithContent:" + currentChangelogTypeWithContent
} else {
// println "[CHANGELOG] parseFromMD WARNING! get type line but version is null: " + line
}
} else if (line.startsWith("-")) {
if (currentChangelogTypeWithContent != null) {
currentChangelogTypeWithContent.changelogContents.add(line.substring(1).trim())
// println "[CHANGELOG] parseFromMD get content line: " + line
} else {
// println "[CHANGELOG] parseFromMD WARNING! get content line but type is null: " + line
}
} else {
// println "[CHANGELOG] parseFromMD ignore line: " + line
}
}
Collections.sort(changelogVersionSectionWithContentList, comparator())
}


public void writeToMD(File file) {
File tmp = new File(file.path + "_tmp")
file.renameTo(tmp)
Expand Down Expand Up @@ -140,39 +181,8 @@ class ChangelogMDFile {
return sb.toString()
}

public void parseFromMD(File file) {
List<String> lines = file.readLines()
changelogVersionSectionWithContentList = new LinkedList<>()
ChangelogVersionSectionWithContent currentChangelogVersionSectionWithContent
ChangelogTypeWithContent currentChangelogTypeWithContent
for (String line : lines) {
line = line.trim()
if (line.startsWith("##") && !line.startsWith("###")) {
ChangelogVersionSectionWithContent changelogVersionSectionWithContent = new ChangelogVersionSectionWithContent(new Version(line.substring(2).trim()), new ArrayList<>())
changelogVersionSectionWithContentList.add(changelogVersionSectionWithContent)
currentChangelogVersionSectionWithContent = changelogVersionSectionWithContent
// println "[CHANGELOG] parseFromMD get section line: " + line + ",currentChangelogVersionSectionWithContent:" + currentChangelogVersionSectionWithContent
} else if (line.startsWith("###") && !line.startsWith("####")) {
if (currentChangelogVersionSectionWithContent != null) {
ChangelogTypeWithContent changelogTypeWithContent = new ChangelogTypeWithContent(ChangelogType.valueOf(line.substring(3).trim()), new ArrayList<>())
currentChangelogVersionSectionWithContent.contents.add(changelogTypeWithContent)
currentChangelogTypeWithContent = changelogTypeWithContent
// println "[CHANGELOG] parseFromMD get type line: " + line + ",currentChangelogTypeWithContent:" + currentChangelogTypeWithContent
} else {
// println "[CHANGELOG] parseFromMD WARNING! get type line but version is null: " + line
}
} else if (line.startsWith("-")) {
if (currentChangelogTypeWithContent != null) {
currentChangelogTypeWithContent.changelogContents.add(line.substring(1).trim())
// println "[CHANGELOG] parseFromMD get content line: " + line
} else {
// println "[CHANGELOG] parseFromMD WARNING! get content line but type is null: " + line
}
} else {
// println "[CHANGELOG] parseFromMD ignore line: " + line
}
}
Collections.sort(changelogVersionSectionWithContentList, comparator())
public Version getNewVersionName() {
return changelogVersionSectionWithContentList.get(0).version
}

private Comparator<ChangelogVersionSectionWithContent> comparator() {
Expand Down Expand Up @@ -272,6 +282,10 @@ class Version {
public String toString() {
return majorVersion + "." + minorVersion + "." + buildVersion
}

public String toStringOfFileName() {
return majorVersion + "_" + minorVersion + "_" + buildVersion
}
}

class GitMessageOfChangelog {
Expand Down
22 changes: 22 additions & 0 deletions gradle/gradle-github-release-support.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
task copyForGithubRelease(type: Copy) {
from './android-godeye-sample/build/outputs/apk/release/android-godeye-sample-release.apk'
from(rootProject.rootDir.absolutePath) {
include 'CHANGELOG_*.md'
}
into "github_release"
}

/**
* ./gradlew prepareForRelease
*/
task prepareForRelease() {
doLast {
println "[Github Release] preparing..."
file('github_release').deleteDir()
tasks.copyForGithubRelease.execute()
println "[Github Release] done."
}
}

prepareForRelease.dependsOn "generateChangelogOfNewVersion"
prepareForRelease.dependsOn ":android-godeye-sample:assembleRelease"

0 comments on commit 82c0fea

Please sign in to comment.