diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 65f648c..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Build - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Build with Gradle - run: ./gradlew build diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml new file mode 100644 index 0000000..fe71d6c --- /dev/null +++ b/.github/workflows/build_and_publish.yml @@ -0,0 +1,27 @@ +name: Build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Rewrite version + run: | + branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`" + cat gradle.properties | sed -e "s/^version=\([0-9\.]*\)/version=\1-branch_$branch-build${{ github.run_number }}/" > gradle.properties.tmp + rm gradle.properties + mv gradle.properties.tmp gradle.properties + - name: Build + run: ./gradlew build + - name: Publish + continue-on-error: true + run: ./gradlew publishAllPublicationsToGiteaRepository + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} diff --git a/build.gradle b/build.gradle index 723a7c4..2326bde 100644 --- a/build.gradle +++ b/build.gradle @@ -23,4 +23,4 @@ allprojects { } apply from: "./extensions.gradle" -// apply from: "./github_release.gradle" +apply from: "./github_release.gradle" diff --git a/changelog_parser.sh b/changelog_parser.sh new file mode 100644 index 0000000..9dd39e6 --- /dev/null +++ b/changelog_parser.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +function parse() { + version="$1" + + while IFS= read -r line && [ -z "`echo "$line" | grep -e "^#\+ $version"`" ] + do + : # do nothing + done + + while IFS= read -r line && [ -z "`echo "$line" | grep -e "^#\+"`" ] + do + echo "$line" + done +} + +version="$1" +file="$2" + +if [ -n "$file" ]; then + parse "$version" < "$file" +else + parse "$version" +fi diff --git a/extensions.gradle b/extensions.gradle index 2e89947..4312fc0 100644 --- a/extensions.gradle +++ b/extensions.gradle @@ -20,6 +20,6 @@ allprojects { defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle" - // publishGradlePath = "${rootProject.projectDir.absolutePath}/publish.gradle" + publishGradlePath = "${rootProject.projectDir.absolutePath}/publish.gradle" } } diff --git a/github_release.gradle b/github_release.gradle new file mode 100644 index 0000000..9a9a67e --- /dev/null +++ b/github_release.gradle @@ -0,0 +1,31 @@ +private String getCurrentVersionChangelog() { + OutputStream changelogDataOS = new ByteArrayOutputStream() + exec { + commandLine 'chmod', "+x", './changelog_parser.sh' + } + exec { + standardOutput = changelogDataOS + commandLine './changelog_parser.sh', "${project.version}", 'CHANGELOG.md' + } + + return changelogDataOS.toString().trim() +} + +if (new File(projectDir, "secret.gradle").exists()) { + apply from: './secret.gradle' + apply plugin: "com.github.breadmoirai.github-release" + + githubRelease { + token "${project.property('GITHUB_RELEASE_TOKEN')}" + + owner "InsanusMokrassar" + repo "PlaguPoster" + + tagName "v${project.version}" + releaseName "${project.version}" + targetCommitish "${project.version}" + + body getCurrentVersionChangelog() + } +} + diff --git a/mppJavaProject.gradle b/mppJavaProject.gradle index 529ea12..df75ca1 100644 --- a/mppJavaProject.gradle +++ b/mppJavaProject.gradle @@ -1,7 +1,7 @@ project.version = "$version" project.group = "$group" -// apply from: "$publishGradlePath" +apply from: "$publishGradlePath" kotlin { jvm { diff --git a/mppJsProject.gradle b/mppJsProject.gradle index 9f27e75..f7499b3 100644 --- a/mppJsProject.gradle +++ b/mppJsProject.gradle @@ -1,7 +1,7 @@ project.version = "$version" project.group = "$group" -// apply from: "$publishGradlePath" +apply from: "$publishGradlePath" kotlin { js (IR) { diff --git a/mppProjectWithSerialization.gradle b/mppProjectWithSerialization.gradle index 7caf028..920edea 100644 --- a/mppProjectWithSerialization.gradle +++ b/mppProjectWithSerialization.gradle @@ -1,7 +1,7 @@ project.version = "$version" project.group = "$group" -// apply from: "$publishGradlePath" +apply from: "$publishGradlePath" kotlin { jvm() diff --git a/publish.gradle b/publish.gradle new file mode 100644 index 0000000..3ce0f5c --- /dev/null +++ b/publish.gradle @@ -0,0 +1,82 @@ +apply plugin: 'maven-publish' + +task javadocsJar(type: Jar) { + classifier = 'javadoc' +} + +publishing { + publications.all { + artifact javadocsJar + + pom { + description = "${project.name}" + name = "${project.name}" + url = "https://github.com/InsanusMokrassar/PlaguPoster" + + scm { + developerConnection = "scm:git:[fetch=]https://github.com/InsanusMokrassar/PlaguPoster.git[push=]https://github.com/InsanusMokrassar/PlaguPoster.git" + url = "https://github.com/InsanusMokrassar/PlaguPoster.git" + } + + developers { + + developer { + id = "InsanusMokrassar" + name = "Aleksei Ovsiannikov" + email = "ovsyannikov.alexey95@gmail.com" + } + + } + + licenses { + + } + } + repositories { + if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) { + maven { + name = "Gitea" + url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven") + + credentials(HttpHeaderCredentials) { + name = "Authorization" + value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN') + } + + authentication { + header(HttpHeaderAuthentication) + } + + } + } + if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) { + maven { + name = "sonatype" + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + + credentials { + username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER') + password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD') + } + + } + } + } + } +} + +if (project.hasProperty("signing.gnupg.keyName")) { + apply plugin: 'signing' + + signing { + useGpgCmd() + + sign publishing.publications + } + + task signAll { + tasks.withType(Sign).forEach { + dependsOn(it) + } + } +} diff --git a/publish.kpsb b/publish.kpsb new file mode 100644 index 0000000..90124dc --- /dev/null +++ b/publish.kpsb @@ -0,0 +1 @@ +{"licenses":[],"mavenConfig":{"name":"${project.name}","description":"${project.name}","url":"https://github.com/InsanusMokrassar/PlaguPoster","vcsUrl":"https://github.com/InsanusMokrassar/PlaguPoster.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"Gitea","url":"https://git.inmo.dev/api/packages/InsanusMokrassar/maven","credsType":{"type":"dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository.CredentialsType.HttpHeaderCredentials","headerName":"Authorization","headerValueProperty":"GITEA_TOKEN"}},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}} \ No newline at end of file