From 034901a479f74c052ff54ef3be86465009763593 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 22 Sep 2020 18:04:10 +0600 Subject: [PATCH] add publication of github release via changelog --- .gitignore | 3 +++ CHANGELOG.md | 2 +- build.gradle | 48 ++++++++++++++++++++++++++++++++++++++++ changelog_info_retriever | 35 ++++++++++++++++++++--------- gradle.properties | 1 + 5 files changed, 77 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 5dc177e271..0546396337 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ settings.xml .gradle/ build/ out/ + +local.properties +secret.gradle diff --git a/CHANGELOG.md b/CHANGELOG.md index adbefeb070..2a831fab41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ ### 0.28.3 -* Common`: +* Common: * Version updates: * `Klock`: `0.12.0` -> `0.12.1` * `Kotlin serialization`: `1.0.0-RC` -> `1.0.0-RC2` (dependency `kotlinx-serialization-core` was replaced with diff --git a/build.gradle b/build.gradle index 59d75fc3a7..9183cb1bad 100644 --- a/build.gradle +++ b/build.gradle @@ -3,12 +3,14 @@ buildscript { mavenLocal() jcenter() mavenCentral() + maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version" + classpath "com.github.breadmoirai:github-release:$github_release_plugin_version" } } @@ -16,3 +18,49 @@ plugins { id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version" apply false id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" apply false } + +ext { + enable_github_publish=new File(projectDir, "secret.gradle").exists() + changelog_from_file="" +} + +if (ext.enable_github_publish) { + apply from: './secret.gradle' + apply plugin: "com.github.breadmoirai.github-release" +} + +private String getCurrentVersionChangelog() { + OutputStream changelogDataOS = new ByteArrayOutputStream() + exec { + standardOutput = changelogDataOS + commandLine './changelog_info_retriever', "$library_version", 'CHANGELOG.md' + } + + return changelogDataOS.toString().trim() +} + +if (enable_github_publish && project.hasProperty('GITHUB_RELEASE_TOKEN')) { + String changelogFromFile = "" + githubRelease { + token "${project.property('GITHUB_RELEASE_TOKEN')}" + + owner "InsanusMokrassar" + repo "TelegramBotAPI" + + tagName "$library_version" + releaseName "$library_version" + targetCommitish "$library_version" + + body getCurrentVersionChangelog() + } + +// tasks.getByName("githubRelease").doFirst { +// OutputStream changelogDataOS = new ByteArrayOutputStream() +// exec { +// standardOutput = changelogDataOS +// commandLine './changelog_info_retriever', "$library_version", 'CHANGELOG.md' +// } +// changelogFromFile = changelogDataOS.toString().trim() +// ext.changelog_from_file = changelogFromFile +// } +} diff --git a/changelog_info_retriever b/changelog_info_retriever index 834ae33666..9fc99fbd5d 100755 --- a/changelog_info_retriever +++ b/changelog_info_retriever @@ -1,16 +1,29 @@ #!/bin/bash +function parse() { + version=$1 + + read -r + while [ -z "`echo $REPLY | grep -e "^#\+ $version"`" ] + do + read -r + done + + read -r + while [ -z "`echo $REPLY | grep -e "^#\+"`" ] + do + echo "$REPLY" + read -r + done +} + version=$1 +file=$2 + +if [ -n "$file" ]; then + parse $version < "$file" +else + parse $version +fi -read -r -while [ -z "`echo $REPLY | grep -e "^#\+ $version"`" ] -do - read -r -done -read -r -while [ -z "`echo $REPLY | grep -e "^#\+"`" ] -do - echo "$REPLY" - read -r -done diff --git a/gradle.properties b/gradle.properties index f6c24eaf52..b6819c45aa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,3 +18,4 @@ library_group=com.github.insanusmokrassar library_version=0.28.3 gradle_bintray_plugin_version=1.8.5 +github_release_plugin_version=2.2.12