Skip to content

Commit

Permalink
all: add signing and publish the library and plugins in CD (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: Rotem Tamir <rotemtamir@gmail.com>
  • Loading branch information
dorav and rotemtam authored Dec 12, 2023
1 parent 32c4c04 commit 3e96f91
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 14 deletions.
40 changes: 36 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ on:
branches:
- master
pull_request:

workflow_dispatch:
inputs:
version:
type: string
description: the version to publish
jobs:
gradle:
runs-on: ubuntu-latest
Expand All @@ -14,12 +18,23 @@ jobs:
with:
distribution: temurin
java-version: 11
gpg-private-key: ${{ secrets.gpg_key }}
gpg-passphrase: ${{ secrets.gpg_passphrase }}

- name: Setup Gradle
uses: gradle/gradle-build-action@v2.4.2

- name: Import GPG key
run: |
echo "${{ secrets.GPG_BASE64 }}" | base64 --decode > /tmp/gpg.key
echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --batch --import --passphrase-fd 0 /tmp/gpg.key
echo "signing.keyId=BB19097D" >> ~/.gradle/gradle.properties
echo "signing.password=${{ secrets.GPG_PASSPHRASE }}" >> ~/.gradle/gradle.properties
echo "signing.secretKeyRingFile=/tmp/gpg.key" >> ~/.gradle/gradle.properties
echo "ossrhUsername=${{ secrets.OSSRH_USERNAME }}" >> ~/.gradle/gradle.properties
echo "ossrhPassword=${{ secrets.OSSRH_PASSWORD }}" >> ~/.gradle/gradle.properties
echo "gradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }}" >> ~/.gradle/gradle.properties
echo "gradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }}" >> ~/.gradle/gradle.properties
sed "s@MAVEN_CENTRAL_PASSWORD@${{ secrets.OSSRH_PASSWORD }}@" maven-plugin/settings.xml.tmpl | sed "s@MAVEN_CENTRAL_USERNAME@${{ secrets.OSSRH_USERNAME }}@" > maven-plugin/settings.xml
- name: Setup Atlas
uses: ariga/setup-atlas@master

Expand All @@ -28,7 +43,7 @@ jobs:

- name: Integration tests with local plugin repo
run: |
./gradlew publishAllPublicationsToLocalPluginRepositoryRepository
PROVIDER_VERSION=0.1.1 ./gradlew publishAllPublicationsToLocalPluginRepositoryRepository
cd examples/with_local_plugin_repository
./gradlew -q schema | tee schema_output
diff schema_output src/test/expected_default_schema
Expand Down Expand Up @@ -101,3 +116,20 @@ jobs:
cd examples/maven_project_example/allowed_types
output=$(atlas migrate diff --env hibernate)
[ "$output" = "The migration directory is synced with the desired state, no changes to be made" ] || (echo "diff detected? unexpected output: $output"; ls -l migrations; exit 1)
- name: Release
if: github.event_name == 'workflow_dispatch'
run: |
export PROVIDER_VERSION=${{ inputs.provider-version }}
cd hibernate-provider
./gradlew publishPluginMavenPublicationToOssrhRepository
cd ../gradle-plugin
./gradlew publishPlugins
cd ../maven-plugin
mvn clean deploy --batch-mode -Dprovider.version=$PROVIDER_VERSION -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} -s settings.xml
- name: Cleanup
if: always()
run: |
rm ~/.gradle/gradle.properties
rm /tmp/gpg.key
2 changes: 1 addition & 1 deletion examples/e2e_java_example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("java")
id("io.atlasgo.hibernate-provider-gradle-plugin") version "0.1"
id("io.atlasgo.hibernate-provider-gradle-plugin") version "0.1.1"
}

group = "org.example"
Expand Down
2 changes: 1 addition & 1 deletion examples/maven_project_example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<plugin>
<groupId>io.atlasgo</groupId>
<artifactId>hibernate-provider-maven-plugin</artifactId>
<version>0.1</version>
<version>0.0-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
2 changes: 1 addition & 1 deletion examples/maven_project_spring_example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>io.atlasgo</groupId>
<artifactId>hibernate-provider-maven-plugin</artifactId>
<version>0.1</version>
<version>0.0-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion examples/with_forbidden_generation_type/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import io.atlasgo.gradle.SchemaTask

plugins {
kotlin("jvm") version "1.9.21"
id("io.atlasgo.hibernate-provider-gradle-plugin") version "0.1"
id("io.atlasgo.hibernate-provider-gradle-plugin") version "0.1.1"
}

group = "org.example"
Expand Down
2 changes: 1 addition & 1 deletion examples/with_local_plugin_repository/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import io.atlasgo.gradle.SchemaTask

plugins {
application
id("io.atlasgo.hibernate-provider-gradle-plugin") version "0.1"
id("io.atlasgo.hibernate-provider-gradle-plugin") version "0.1.1"
}

group = "org.example"
Expand Down
2 changes: 1 addition & 1 deletion examples/with_spring_gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ java {

dependencies {
runtimeOnly("com.h2database:h2:2.2.224")
implementation("io.atlasgo:hibernate-provider:0.1")
implementation("io.atlasgo:hibernate-provider:0.1.1")
implementation("org.hibernate.orm:hibernate-core:6.3.1.Final")
implementation("org.springframework.boot:spring-boot-autoconfigure:3.2.0")
implementation("org.springframework.boot:spring-boot-starter-data-jpa:3.2.0") {
Expand Down
2 changes: 1 addition & 1 deletion gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "io.atlasgo"
version = "0.1"
version = System.getenv("PROVIDER_VERSION")

repositories {
mavenCentral()
Expand Down
12 changes: 10 additions & 2 deletions hibernate-provider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
`java-library`
signing
id("com.gradle.plugin-publish") version "1.1.0"
kotlin("jvm") version "1.9.20"
}

group = "io.atlasgo"
version = "0.1"
version = System.getenv("PROVIDER_VERSION")

repositories {
mavenCentral()
Expand Down Expand Up @@ -48,6 +49,9 @@ tasks.jar {
publishing {
publications {
create<MavenPublication>("hibernate-provider") {
signing {
sign(publishing.publications["hibernate-provider"])
}
pom {
name = "hibernate-provider"
description = "A Hibernate schema provider for Atlas"
Expand Down Expand Up @@ -80,7 +84,11 @@ publishing {
maven {
name = "ossrh"
credentials(PasswordCredentials::class)
url = uri("https://s01.oss.sonatype.org/content/groups/staging/")
if (version.toString().endsWith("SNAPSHOT")) {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
} else {
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
}
}
maven {
name = "localPluginRepository"
Expand Down
4 changes: 3 additions & 1 deletion maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<groupId>io.atlasgo</groupId>
<artifactId>hibernate-provider-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>0.2-SNAPSHOT</version>
<description>Atlas Hibernate schema provider</description>

<name>hibernate-provider-maven-plugin Maven Mojo</name>
Expand All @@ -15,8 +14,11 @@
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<provider.version>0.0-SNAPSHOT</provider.version>
</properties>

<version>${provider.version}</version>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
Expand Down
10 changes: 10 additions & 0 deletions maven-plugin/settings.xml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<settings>
<servers>
<server>
<id>ossrh</id>
<username>MAVEN_CENTRAL_USERNAME</username>
<password>MAVEN_CENTRAL_PASSWORD</password>
</server>
</servers>
</settings>

0 comments on commit 3e96f91

Please sign in to comment.