Skip to content

Commit

Permalink
adjusted github action for publish
Browse files Browse the repository at this point in the history
  • Loading branch information
p3t committed Jun 23, 2024
1 parent 14cdc8d commit 9e3403d
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 52 deletions.
71 changes: 56 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,52 @@ name: '[ BUILD ] Build Project (Java/Gradle)'

on:
workflow_dispatch:
inputs:
release_build:
description: 'toggles an release-build, by default false'
type: boolean
default: false
required: false
build_version:
description: 'The version to build and deploy'
type: string
required: true
default: '0-SNAPSHOT'
workflow_call:
inputs:
release_build:
description: 'toggles an release-build, by default false'
type: boolean
default: false
required: false
build_version:
description: 'The version to build and deploy'
type: string
required: true
default: '0-SNAPSHOT'
outputs:
artifact_id:
description: 'The artifact id of the project.'
value: ${{ jobs.Build.outputs.artifact_id }}
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
BUILD_VERSION: '0-SNAPSHOT'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_USERNAME: ${{ secrets.MAVENCENTRAL_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVENCENTRAL_PASSWORD }}
GITHUBPKG_USERNAME: ${{ secrets.GITHUBPKG_USERNAME }}
GITHUBPKG_PASSWORD: ${{ secrets.GITHUBPKG_PASSWORD }}

jobs:
build:
Validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v3
Build:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
outputs:
maven_artifactId: ${{ steps.maven_artifactId.outputs.artifactId }}
maven_groupId: ${{ steps.maven_groupId.outputs.groupId }}
maven_version: ${{ steps.maven_version.outputs.version }}
cache_key: ${{ steps.cache.outputs.cache_key }}
artifact_id: ${{ steps.ArtifactId.outputs.artifact_id }}

steps:
- uses: actions/checkout@v4
Expand All @@ -45,19 +61,44 @@ jobs:
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3 # v3.1.0
with:
add-job-summary-as-pr-comment: on-failure
artifact-retention-days: 5
# with:
# dependency-graph: generate-and-submit

- name: Clean
if: inputs.release_build
run: ./gradlew clean
env:
GITHUB_DEPENDENCY_GRAPH_ENABLED: false

- name: Build with Gradle Wrapper
run: ./gradlew build jacocoTestReport
run: ./gradlew -Pversion=${BUILD_VERSION} --info build jacocoTestReport signMavenJavaPublication
env:
BUILD_VERSION: ${{ inputs.build_version }}
GPG_SIGNING_KEY_PASSWORD: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}

# - name: Sign artifacts
# if: inputs.release_build
# run: ./gradlew -Pversion=${build_version} --info signMavenJavaPublication

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: ~/**/build/libs/*.jar

dependency-submission:
- name: Artifact Id
id: ArtifactId
run: echo artifact_id=echo ${$(ls build/libs/*${BUILD_VERSION}.jar| xargs -n 1 basename )%-${BUILD_VERSION}.jar} >> $GITHUB_OUTPUT
env:
BUILD_VERSION: ${{ inputs.build_version }}

DependencySubmission:
name: "Dependency Submission"
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ env:
RELEASE_TAG: ${{ github.event.release.tag_name }}

jobs:
publish:

ReleaseVersion:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

outputs:
BUILD_VERSION: ${{ steps.release_version.outputs.BUILD_VERSION }}

build_version: ${{ steps.release_version.outputs.build_version }}
steps:
- name: "Release Version"
id: release_version
Expand All @@ -34,15 +28,27 @@ jobs:
echo "BUILD_VERSION=${RELEASE_TAG#v}" >> "$GITHUB_ENV"
echo "BUILD_VERSION=${RELEASE_TAG#v}" >> "$GITHUB_OUTPUT"
echo "Release version is $VERSION"
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Print output variables
run: |
echo BUILD_VERSION: ${{ steps.release_version.outputs.build_version }}
Build:
uses: ./.github/workflows/build.yml
with:
build_version: ${{ needs.ReleaseVersion.outputs.build_version }}
release_build: true
secrets: inherit

Publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
BUILD_VERSION: ${{ needs.ReleaseVersion.outputs.build_version }}
ARTIFACT_ID: ${{ needs.Build.outputs.artifact_id }}

steps:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3 # v3.1.0

Expand All @@ -53,16 +59,13 @@ jobs:
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
GITHUB_DEPENDENCY_GRAPH_ENABLED: false

- name: publish to sonar central
run: ./gradlew sonatypeCentralUpload
env:
GPG_SIGNING_KEY_PASSWORD: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
SONATYPE_CENTRAL_USERNAME: ${{ secrets.SONATYPE_CENTRAL_USERNAME }}
SONATYPE_CENTRAL_PASSWORD: ${{ secrets.SONATYPE_CENTRAL_PASSWORD }}
SONATYPE_CENTRAL_PASSWORD: ${{ secrets.SONATYPE_CENTRAL_PASSWORD }}
GITHUB_DEPENDENCY_GRAPH_ENABLED: false
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id("io.freefair.lombok")
id("org.springframework.boot") apply false
id("io.spring.dependency-management")
id("org.kordamp.gradle.project")
`jacoco`
id("org.kordamp.gradle.spotbugs")
id("com.github.kt3k.coveralls")
id("org.kordamp.gradle.coveralls")
Expand All @@ -24,14 +24,18 @@ dependencyManagement {
}

}
//java {
// withSourcesJar()
// withJavadocJar()
//}
// This is needed for sontarTypeCentralUpload! Has conflict with kordamp.java-project
java {
withSourcesJar()
withJavadocJar()
}
tasks.named<Jar>("bootJar") {
enabled = false
}
tasks {
jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
}
delombok {
enabled = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
groupId = "io.vigier.cursorpaging"
artifactId = artifactId.orEmpty()
}
withType<MavenPublication> {
pom {
Expand Down Expand Up @@ -72,14 +70,18 @@ signing {
val GPG_SIGNING_KEY_PASSWORD: String? by project
val GPG_SIGNING_KEY: String? by project
val GPG_KEY_ID: String? by project

val signingKey = (GPG_SIGNING_KEY ?: System.getenv("GPG_SIGNING_KEY"))
val signingKeyId = (GPG_KEY_ID ?: System.getenv("GPG_KEY_ID"))
val signingKeyPassphrase = (GPG_SIGNING_KEY_PASSWORD ?: System.getenv("GPG_SIGNING_KEY_PASSWORD"))

isRequired = true

logger.info("Signing> Key ID: $GPG_KEY_ID")
logger.info("Signing> Password is present: {}", GPG_SIGNING_KEY_PASSWORD.orEmpty().length)
logger.info("Signing> Key is present: {}", GPG_SIGNING_KEY.orEmpty().length)
logger.info("Signing> Key ID: $signingKey")
logger.info("Signing> Password is present: {}", signingKeyPassphrase.orEmpty().length)
logger.info("Signing> Key is present: {}", signingKey.orEmpty().length)

useInMemoryPgpKeys(GPG_KEY_ID, GPG_SIGNING_KEY, GPG_SIGNING_KEY_PASSWORD)
useInMemoryPgpKeys(signingKeyId, signingKey, signingKeyPassphrase)
sign(publishing.publications["mavenJava"])
}

Expand Down
4 changes: 2 additions & 2 deletions cursorpaging-jpa-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ plugins {
id("com.google.protobuf")
}

group = "io.vigier.cursorpaging.jpa.api"
group = "io.vigier.cursorpaging"
version = "0-SNAPSHOT"
ext["artifactId"] = findProperty("artifactId") ?: "spring-cursorpaging-jpa-api"
ext["artifactId"] = findProperty("artifactId") ?: "cursorpaging-jpa-api"

configurations {
compileOnly {
Expand Down
4 changes: 2 additions & 2 deletions cursorpaging-jpa/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ plugins {
id("org.kordamp.gradle.coveralls")
}

group = "io.vigier.cursorpaging-jpa"
group = "io.vigier.cursorpaging"
version = "0-SNAPSHOT"

ext["artifactId"] = findProperty("artifactId") ?: "spring-cursorpaging-jpa"
ext["artifactId"] = findProperty("artifactId") ?: "cursorpaging-jpa"


dependencies {
Expand Down

0 comments on commit 9e3403d

Please sign in to comment.