Skip to content

Commit

Permalink
chore: add GH workflows (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Idane authored Jun 1, 2024
1 parent c05697d commit 0ec19de
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 100 deletions.
59 changes: 0 additions & 59 deletions .circleci/config.yml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publish

on:
push:
branches:
- master
tags:
- v*
pull_request:
branches:
- master
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Install Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
OSSRH_GPG_SECRET_KEY_BASE64: ${{ secrets.OSSRH_GPG_SECRET_KEY_BASE64 }}
OSSRH_GPG_SECRET_KEY_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
export RELEASE_VERSION=${{ github.event.number }}-PR-SNAPSHOT
echo "Deploying version $RELEASE_VERSION"
./gradlew -Prelease jar publishToSonatype
else
if [ "${{ github.ref_type }}" = "tag" ]; then
export RELEASE_VERSION=${{ github.ref_name }}
export RELEASE_VERSION=${RELEASE_VERSION:1}
else
export RELEASE_VERSION=${{ github.sha }}-SNAPSHOT
fi
echo "Deploying version $RELEASE_VERSION"
./gradlew -Prelease jar publishToSonatype closeAndReleaseSonatypeStagingRepository
fi
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release
on:
push:
branches:
- master
- beta

permissions:
contents: read # for checkout

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.CLONE_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.CLONE_TOKEN }}
run: npx semantic-release
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test

on:
push:
branches:
- master
tags:
- v*
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Install Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew test --info
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure()
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
95 changes: 54 additions & 41 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
import org.jetbrains.dokka.gradle.DokkaTask
import java.util.*

plugins {
`java-library`
`maven-publish`
signing
id("org.jetbrains.dokka") version "1.6.0"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
}

if (hasProperty("release")) {
val releaseVersion = extra["shapeshift.version"].toString()
subprojects {
apply(plugin = "java-library")
apply(plugin = "signing")
apply(plugin = "maven-publish")
apply(plugin = "org.jetbrains.dokka")
val ossrhUsername = System.getenv("OSSRH_USERNAME")
val ossrhPassword = System.getenv("OSSRH_PASSWORD")
val releaseVersion = System.getenv("RELEASE_VERSION")
group = "dev.krud"
version = releaseVersion
nexusPublishing {
this@nexusPublishing.repositories {
sonatype {
username.set(ossrhUsername)
password.set(ossrhPassword)
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
}

allprojects {
repositories {
mavenLocal()
mavenCentral()
}
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "signing")

if (hasProperty("release")) {
val releaseVersion = System.getenv("RELEASE_VERSION")
val signingKeyBase64 = System.getenv("OSSRH_GPG_SECRET_KEY_BASE64")
val signingPassword = System.getenv("OSSRH_GPG_SECRET_KEY_PASSWORD")
group = "dev.krud"
version = releaseVersion
java.sourceCompatibility = JavaVersion.VERSION_1_8
val isSnapshot = version.toString().endsWith("-SNAPSHOT")
val repoUri = if (isSnapshot) {
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
} else {
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
}

if (!isSnapshot) {
java {
withJavadocJar()
withSourcesJar()
}
java {
withJavadocJar()
withSourcesJar()
}

publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
version = releaseVersion
repositories {
maven {
name = "OSSRH"
url = uri(repoUri)
credentials {
username = System.getenv("OSSRH_USERNAME") ?: extra["ossrh.username"]?.toString()
password = System.getenv("OSSRH_PASSWORD") ?: extra["ossrh.password"]?.toString()
}
}
}
artifactId = project.name

pom {
name.set(this@subprojects.name)
name.set(project.name)
description.set("A Kotlin library for intelligent object mapping.")
url.set("https://github.com/krud-dev/shapeshift/shapeshift")
licenses {
Expand Down Expand Up @@ -74,17 +82,22 @@ if (hasProperty("release")) {
}
}

if (!isSnapshot) {
val javadocTask = tasks.named<Javadoc>("javadoc").get()

tasks.withType<DokkaTask> {
javadocTask.dependsOn(this)
outputDirectory.set(javadocTask.destinationDir)
}
val javadocTask = tasks.named<Javadoc>("javadoc").get()

signing {
sign(publishing.publications["maven"])
}
tasks.withType<DokkaTask> {
javadocTask.dependsOn(this)
outputDirectory.set(javadocTask.destinationDir)
}
signing {
val signingKey = signingKeyBase64?.let { decodeBase64(it) }
useInMemoryPgpKeys(
signingKey, signingPassword
)
sign(publishing.publications["maven"])
}
}
}
}

fun decodeBase64(base64: String): String {
return String(Base64.getDecoder().decode(base64))
}

0 comments on commit 0ec19de

Please sign in to comment.