From 848389815a2b8c20922c02d3f3f09f4d61a908e2 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Fri, 2 Feb 2024 15:54:25 +0400 Subject: [PATCH] [RM-84612] publish hand as lib * updated github workflow --- .github/workflows/build-dev-release.yml | 18 +++++ .github/workflows/build-release.yml | 18 +++++ .github/workflows/build-sanpshot.yml | 23 ++++++ .github/workflows/dev-docker-publish.yml | 54 ------------- .github/workflows/docker-publish.yml | 39 ---------- Dockerfile | 4 +- build.gradle | 96 ++++++++++++++++++++++++ gradle.properties | 4 +- 8 files changed, 160 insertions(+), 96 deletions(-) create mode 100644 .github/workflows/build-dev-release.yml create mode 100644 .github/workflows/build-release.yml create mode 100644 .github/workflows/build-sanpshot.yml delete mode 100644 .github/workflows/dev-docker-publish.yml delete mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/build-dev-release.yml b/.github/workflows/build-dev-release.yml new file mode 100644 index 0000000..86f34c1 --- /dev/null +++ b/.github/workflows/build-dev-release.yml @@ -0,0 +1,18 @@ +name: Build and publish dev release jar to sonatype repository + +on: workflow_dispatch + +jobs: + build: + uses: th2-net/.github/.github/workflows/compound-java.yml@main + with: + build-target: 'Sonatype,Docker' + devRelease: true + createTag: true + docker-username: ${{ github.actor }} + secrets: + docker-password: ${{ secrets.GITHUB_TOKEN }} + sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} + sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }} + sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..a72a337 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,18 @@ +name: Build and publish release jar to sonatype repository + +on: workflow_dispatch + +jobs: + build: + uses: th2-net/.github/.github/workflows/compound-java.yml@main + with: + build-target: 'Sonatype,Docker' + devRelease: false + createTag: true + docker-username: ${{ github.actor }} + secrets: + docker-password: ${{ secrets.GITHUB_TOKEN }} + sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} + sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }} + sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/build-sanpshot.yml b/.github/workflows/build-sanpshot.yml new file mode 100644 index 0000000..46c237d --- /dev/null +++ b/.github/workflows/build-sanpshot.yml @@ -0,0 +1,23 @@ +name: Build and publish jar to sonatype snapshot repository + +on: + push: + branches-ignore: + - master + - version-* + - dependabot* + paths-ignore: + - README.md + +jobs: + build-job: + uses: th2-net/.github/.github/workflows/compound-java-dev.yml@main + with: + build-target: 'Sonatype,Docker' + docker-username: ${{ github.actor }} + secrets: + docker-password: ${{ secrets.GITHUB_TOKEN }} + sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} + sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }} + sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/dev-docker-publish.yml b/.github/workflows/dev-docker-publish.yml deleted file mode 100644 index 10a95ab..0000000 --- a/.github/workflows/dev-docker-publish.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Dev build and publish Docker distributions to Github Container Registry ghcr.io - -on: - push: - branches-ignore: - - master - - version-* - - dependabot** - paths-ignore: - - README.md - - gradle.properties - -jobs: - build: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - # Prepare custom build version - - name: Get branch name - id: branch - run: echo ::set-output name=branch_name::${GITHUB_REF#refs/*/} - - name: Get release_version - id: ver - uses: christian-draeger/read-properties@1.1.1 - with: - path: gradle.properties - properties: release_version - - name: Get SHA of the commit - id: sha - run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - name: Build custom release version - id: release_ver - run: echo value="${{ steps.ver.outputs.release_version }}-${{ steps.branch.outputs.branch_name }}-${{ github.run_id }}-${{ steps.sha.outputs.sha_short }}" >> $GITHUB_OUTPUT - - name: Show custom release version - run: echo ${{ steps.release_ver.outputs.value }} - # Build and publish image - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - run: echo "::set-output name=REPOSITORY_NAME::$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" - id: meta - - name: Build and push - id: docker_build - uses: docker/build-push-action@v3 - with: - push: true - tags: ghcr.io/${{ github.repository }}:${{ steps.release_ver.outputs.value }} - labels: com.exactpro.th2.${{ steps.meta.outputs.REPOSITORY_NAME }}=${{ steps.ver.outputs.value }} - build-args: | - release_version=${{ steps.read_property.outputs.value }} \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml deleted file mode 100644 index 3d8706e..0000000 --- a/.github/workflows/docker-publish.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Build and publish Docker distributions to Github Container Registry ghcr.io - -on: - push: - branches: - - master - - version-* - paths: - - gradle.properties - -jobs: - build: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT - id: meta - - name: Read version from gradle.properties - id: read_property - uses: christian-draeger/read-properties@1.1.1 - with: - path: ./gradle.properties - properties: release_version - - name: Build and push - id: docker_build - uses: docker/build-push-action@v3 - with: - push: true - tags: ghcr.io/${{ github.repository }}:${{ steps.read_property.outputs.release_version }} - labels: com.exactpro.th2.${{ steps.meta.outputs.REPOSITORY_NAME }}=${{ steps.read_property.outputs.release_version }} - build-args: | - release_version=${{ steps.read_property.outputs.value }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4d80c26..e5ac521 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,9 +14,9 @@ RUN apk add --no-cache make git gcc musl-dev swig \ -I../src -L../src libwebp_java_wrap.c -lwebp -o libwebp.so FROM gradle:7.6-jdk11 AS build -ARG app_version=0.0.0 +ARG release_version=0.0.0 COPY ./ . -RUN gradle dockerPrepare -Prelease_version=${app_version} +RUN gradle dockerPrepare -Prelease_version=${release_version} FROM adoptopenjdk/openjdk11:alpine WORKDIR /home diff --git a/build.gradle b/build.gradle index 53cc56e..e5df93f 100644 --- a/build.gradle +++ b/build.gradle @@ -21,11 +21,15 @@ plugins { id 'java' id 'java-library' id 'application' + id 'maven-publish' + id "io.github.gradle-nexus.publish-plugin" version "1.3.0" id 'com.palantir.docker' version '0.34.0' id "org.owasp.dependencycheck" version "9.0.9" id "com.gorylenko.gradle-git-properties" version "2.4.1" id 'com.github.jk1.dependency-license-report' version '2.5' id "de.undercouch.download" version "5.4.0" + id 'signing' + id "com.google.protobuf" version "0.9.3" } group 'com.exactpro.th2' @@ -77,6 +81,98 @@ dependencies { implementation "org.apache.commons:commons-csv:1.9.0" } +java { + withJavadocJar() + withSourcesJar() +} + +// conditionals for publications +tasks.withType(PublishToMavenRepository).configureEach { + onlyIf { + (repository == publishing.repositories.nexusRepository && + project.hasProperty('nexus_user') && + project.hasProperty('nexus_password') && + project.hasProperty('nexus_url')) || + (repository == publishing.repositories.sonatype && + project.hasProperty('sonatypeUsername') && + project.hasProperty('sonatypePassword')) + } +} +tasks.withType(Sign).configureEach { + onlyIf { + project.hasProperty('signingKey') && + project.hasProperty('signingPassword') + } +} +// disable running task 'initializeSonatypeStagingRepository' on a gitlab +tasks.configureEach { task -> + if (task.name == 'initializeSonatypeStagingRepository' && + !(project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')) + ) { + task.enabled = false + } +} + +publishing { + publications { + mavenJava(MavenPublication) { + from(components.java) + pom { + name = rootProject.name + packaging = 'jar' + description = rootProject.description + url = vcs_url + scm { + url = vcs_url + } + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'developer' + name = 'developer' + email = 'developer@exactpro.com' + } + } + scm { + url = vcs_url + } + } + } + } + repositories { + //Nexus repo to publish from gitlab + maven { + name = 'nexusRepository' + credentials { + username = project.findProperty('nexus_user') + password = project.findProperty('nexus_password') + } + url = project.findProperty('nexus_url') + } + } +} + +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + } + } +} + +signing { + String signingKey = findProperty("signingKey") + String signingPassword = findProperty("signingPassword") + useInMemoryPgpKeys(signingKey, signingPassword) + sign publishing.publications.mavenJava +} + applicationName = 'service' application { diff --git a/gradle.properties b/gradle.properties index bb05d67..c8ad482 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,4 @@ release_version = 5.0.0 -docker_image_name = th2-hand \ No newline at end of file +docker_image_name = th2-hand + +vcs_url=https://github.com/th2-net/th2-hand \ No newline at end of file