diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8eac766 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release +on: + workflow_dispatch: + inputs: + version: + description: 'The release version' + required: true + +jobs: + build: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache Gradle packages + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build + run: ./gradlew build --stacktrace + - name: Release + env: + RELEASE_VERSION: ${{ github.event.inputs.version }} + ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }} + ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }} + run: ./gradlew release -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=$RELEASE_VERSION diff --git a/build.gradle b/build.gradle index 4dd28c7..22de725 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,14 @@ plugins { id 'java-library' id 'jacoco' + id 'signing' + id 'maven-publish' id 'org.sonarqube' version '3.3' + id "io.github.gradle-nexus.publish-plugin" version "1.1.0" + id "net.researchgate.release" version "2.8.1" } group 'io.github.nstdio' -version '1.0-SNAPSHOT' sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 @@ -20,7 +23,6 @@ ext { commonIoVersion = '1.3.2' assertJVersion = '3.20.2' jsonPathAssertVersion = '2.6.0' - lombokDependency = 'org.projectlombok:lombok:1.18.20' } dependencies { @@ -44,6 +46,84 @@ sonarqube { } } +task javadocJar(type: Jar) { + archiveClassifier = 'javadoc' + from javadoc +} + +task sourcesJar(type: Jar) { + archiveClassifier = 'sources' + from sourceSets.main.allSource +} + +publishing { + publications { + mavenJava(MavenPublication) { + from(components.java) + artifact sourcesJar + artifact javadocJar + pom { + name = 'JDK Http Client Extensions' + description = 'The set of usefult extensions for JDK HttpClient.' + url = 'https://github.com/nstdio/http-client-ext' + + scm { + connection = 'scm:git:git@github.com:nstdio/http-client-ext.git' + developerConnection = 'scm:git:git@github.com:nstdio/http-client-ext.git' + url = 'https://github.com/nstdio/http-client-ext' + } + + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'https://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + + developers { + developer { + id = 'nstdio' + name = 'Edgar Asatryan' + email = 'nstdio@gmail.com' + } + } + + } + } + } +} + +nexusPublishing { + repositories { + sonatype { + def urlBase = "https://s01.oss.sonatype.org" + nexusUrl = uri("$urlBase/service/local/") + snapshotRepositoryUrl = uri("$urlBase/content/repositories/snapshots/") + } + } +} + +signing { + def signingKey = findProperty("signingKey") + def signingPassword = findProperty("signingPassword") + useInMemoryPgpKeys(signingKey, signingPassword) + + sign publishing.publications.mavenJava +} + +release { + tagTemplate = 'v${version}' + + git { + requireBranch = 'main' + pushToRemote = 'origin' + } +} + +afterEvaluate { + afterReleaseBuild.dependsOn publishToSonatype, closeAndReleaseSonatypeStagingRepository +} + test { useJUnitPlatform()