From 82c0fea3c64d29588cec0572a8a82a52cc327e56 Mon Sep 17 00:00:00 2001 From: "hui.zhao" Date: Wed, 26 Feb 2020 19:16:31 +0800 Subject: [PATCH] #Changed# Build script changed for Github release --- .gitignore | 1 + .travis.yml | 7 +- build.gradle | 3 +- gradle/gradle-changelog-support.gradle | 82 ++++++++++++--------- gradle/gradle-github-release-support.gradle | 22 ++++++ 5 files changed, 76 insertions(+), 39 deletions(-) create mode 100644 gradle/gradle-github-release-support.gradle diff --git a/.gitignore b/.gitignore index 74b026d4..50d593d1 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.travis.yml b/.travis.yml index 1c6adcc3..f45f6e67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,14 +29,13 @@ install: script: - ./gradlew clean build jacocoTestReport - - ./gradlew assembleRelease notifications: email: - tech@hikyson.cn before_deploy: - - ./gradlew generateChangelogOfNewVersion + - ./gradlew prepareForRelease deploy: - provider: script @@ -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 diff --git a/build.gradle b/build.gradle index 7a015b83..b9f1501a 100644 --- a/build.gradle +++ b/build.gradle @@ -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') \ No newline at end of file +apply from: rootProject.file('gradle/gradle-changelog-support.gradle') +apply from: rootProject.file('gradle/gradle-github-release-support.gradle') \ No newline at end of file diff --git a/gradle/gradle-changelog-support.gradle b/gradle/gradle-changelog-support.gradle index e1abb023..fc9e9895 100644 --- a/gradle/gradle-changelog-support.gradle +++ b/gradle/gradle-changelog-support.gradle @@ -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") } } @@ -103,6 +108,42 @@ class ChangelogMDFile { public List changelogVersionSectionWithContentList + public void parseFromMD(File file) { + List 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) @@ -140,39 +181,8 @@ class ChangelogMDFile { return sb.toString() } - public void parseFromMD(File file) { - List 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 comparator() { @@ -272,6 +282,10 @@ class Version { public String toString() { return majorVersion + "." + minorVersion + "." + buildVersion } + + public String toStringOfFileName() { + return majorVersion + "_" + minorVersion + "_" + buildVersion + } } class GitMessageOfChangelog { diff --git a/gradle/gradle-github-release-support.gradle b/gradle/gradle-github-release-support.gradle new file mode 100644 index 00000000..bd0e3883 --- /dev/null +++ b/gradle/gradle-github-release-support.gradle @@ -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"