Skip to content

Commit

Permalink
feat: clean up build scripts and release action
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Dwairi committed Sep 12, 2024
1 parent 1f4fabe commit ee8c1be
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 127 deletions.
68 changes: 27 additions & 41 deletions .github/workflows/release-sdk.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release SDK to Maven Central
name: Release SDK

on:
workflow_dispatch:
Expand All @@ -10,54 +10,40 @@ on:
required: true

jobs:
build:
release-code:
timeout-minutes: 60
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3

- uses: gradle/actions/wrapper-validation@v3

- uses: actions/setup-java@v4
- name: Set up Java 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
server-id: oss-sonatype
server-username: SONATYPE_USERNAME
server-password: SONATYPE_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: GPG_PASSPHRASE
settings-path: ${{ github.workspace }}

- name: Prepare Environment and Version
id: prepare
run: |
git config user.name s-github-actions
git config user.email [email protected]
echo "branch_name=release/${{ inputs.version }}" >> $GITHUB_OUTPUT
- name: Build library with Gradle
run: ./gradlew clean build

- name: Prepare Release
id: prepare_release
- name: Publish library with Gradle
run: |
cd code
chmod a+x ../gradlew && ../gradlew --no-daemon versionsSet -Pversion=${{ inputs.version }}
- name: Create PR
uses: peter-evans/create-pull-request@v7
with:
branch: "publish-v${{ inputs.version }}"
commit-message: "chore: prepare release ${{ inputs.version }}"
title: "chore: Publish v${{ inputs.version }}"
body: |
This PR publishes the source code for `v${{ inputs.version }}`.
Generated by the EG SDK generator.
add-paths: |
code/*
- name: Build and Publish
echo "New version: ${{ inputs.version }}"
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository publishPlugins -Pversion=${{ inputs.version }}
env:
ARTYLAB_USER: ${{ secrets.SONATYPE_USERNAME }}
ARTYLAB_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GPG_SECRET: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PRIVATE_KEY_PASSPHRASE }}
run: |
echo "Publishing version ${{ inputs.version }}"
cd code
../gradlew --no-daemon clean jar build publish -Pversion=${{ inputs.version }}
PLUGIN_PORTAL_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
PLUGIN_PORTAL_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}

- name: Archive failure build reports
uses: actions/upload-artifact@v3
if: failure()
with:
name: build-reports
path: |
./**/build/reports
retention-days: 7
62 changes: 62 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import java.time.Duration

plugins {
id 'org.jetbrains.kotlin.jvm' version '2.0.20'
id 'io.github.gradle-nexus.publish-plugin' version "1.1.0"
}

kotlin {
jvmToolchain(11)
}

compileJava {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

allprojects {
buildscript {
repositories {
mavenCentral()
mavenLocal {
content {
includeGroup("com.expediagroup")
}
}
}
}

repositories {
mavenCentral()
mavenLocal {
content {
includeGroup("com.expediagroup")
}
}
}
}

subprojects {
if (project.name != "examples") {
nexusPublishing {
repositories {
sonatype {
username.set(System.getenv("SONATYPE_USERNAME"))
password.set(System.getenv("SONATYPE_PASSWORD"))
}
}

transitionCheckOptions {
maxRetries.set(60)
delayBetween.set(Duration.ofMillis(5000))
}
}
}

if (project.name == 'examples') {
tasks.withType(Jar).configureEach {
enabled = false
}
}
}

81 changes: 0 additions & 81 deletions code/build.gradle
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
import org.jetbrains.dokka.gradle.DokkaTask

buildscript {
ext {
artyUser = findProperty('ARTIFACTORY_USER')
artyPass = findProperty('ARTIFACTORY_PASS')
}

repositories {
mavenCentral {
credentials {
username = System.getenv("SONATYPE_USERNAME") ?: findProperty('ARTIFACTORY_USER')
password = System.getenv("SONATYPE_PASSWORD") ?: findProperty('ARTIFACTORY_PASS')
}
}
}
}

plugins {
id 'org.jetbrains.kotlin.jvm' version '2.0.20'
id 'org.jetbrains.dokka' version '1.9.20'
id 'com.apollographql.apollo' version '4.0.0'
id 'maven-publish'
}

repositories {
mavenCentral {
credentials {
username = System.getenv("SONATYPE_USERNAME") ?: findProperty('ARTIFACTORY_USER')
password = System.getenv("SONATYPE_PASSWORD") ?: findProperty('ARTIFACTORY_PASS')
}
}
}

dependencies {
Expand All @@ -52,16 +26,6 @@ dependencies {
implementation("javax.validation:validation-api:2.0.1.Final")
implementation("org.hibernate.validator:hibernate-validator:6.2.5.Final")
implementation("jakarta.validation:jakarta.validation-api:2.0.2")

}

kotlin {
jvmToolchain(11)
}

compileJava {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

sourceSets {
Expand All @@ -72,51 +36,6 @@ sourceSets {
}
}

subprojects {
afterEvaluate { project ->
if (project.name == System.getenv('EXCLUDE_MODULE')) {
// Disable all tasks for this module
tasks.configureEach { task ->
task.enabled = false
}
}
}
}

publishing {
repositories {
mavenCentral {
credentials {
username = System.getenv("SONATYPE_USERNAME")
password = System.getenv("SONATYPE_PASSWORD")
}
}
}

publications {
mavenJava(MavenPublication) {
from components.java
artifactId project.name
groupId project.property('groupId')
version project.property('version')
description project.property('description')
}
}
}

tasks.register('versionsSet') {
doLast {
def pattern = ~/(\R|^)(version\s*=\s*)([-.A-Z0-9]+)(\R|$)/
String gradleProperties = file('gradle.properties').text
String currentVersion = (gradleProperties =~ pattern)[0][3]
println("Current version: $currentVersion")
println("Project version: ${project.version}")
if (project.version != currentVersion) {
file('gradle.properties').text = gradleProperties.replaceFirst(pattern, "\$1\$2${project.version}\$4")
}
}
}

tasks.withType(DokkaTask.class) {

moduleName.set("Lodging Connectivity Java SDK")
Expand Down
4 changes: 0 additions & 4 deletions code/gradle.properties

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin.code.style=official
groupId=com.expediagroup
version=1.0.2-SNAPSHOT
version=0.0.1-SNAPSHOT
description=SDK for Lodging Connectivity APIs

0 comments on commit ee8c1be

Please sign in to comment.