Skip to content

Commit

Permalink
Add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
supl committed Aug 22, 2023
1 parent 8a1bfe0 commit 1cb63ee
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 3 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish the Java Package to Maven Central Repository and upload tool to GitHub

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
branches:
- main

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'

- name: Set version
id: version
run: |
VERSION=$(echo ${{ github.ref }} | sed -e "s#refs/tags/v##g")
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Upload the package to Maven Central Repository
run: |
echo "${{ secrets.SIGNING_SECRET_KEY_RING }}" | base64 -d > ~/.gradle/secring.gpg
./gradlew publish \
-Pversion=${{ steps.version.outputs.version }} \
-Psigning.keyId="${{ secrets.SIGNING_KEY_ID }}" \
-P'signing.password'="${{ secrets.SIGNING_PASSWORD }}" \
-Psigning.secretKeyRingFile="$(echo ~/.gradle/secring.gpg)" \
-PossrhUsername="${{ secrets.OSSRH_USERNAMAE }}" \
-PossrhPassword="${{ secrets.OSSRH_PASSWORD }}"
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- name: Build Docker image
run: ./gradlew docker

- name: Push Docker image to GitHub Container Registry
run: docker push ghcr.io/scalar-labs/scalar-admin-k8s:${{ steps.version.outputs.version }}
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ subprojects {
}

group = "com.scalar-labs"
project.version = project.findProperty('projVersion') ?: '1.0.0-SNAPSHOT'
project.version = project.findProperty('projVersion') ?: '1.1.0-SNAPSHOT'

ext {
scalarAdminVersion = '2.1.2'
Expand All @@ -20,6 +20,8 @@ subprojects {
mockitoVersion = '4.11.0'
jacksonVersion = '2.15.2'
spotbugsVersion = '4.7.3'
dockerPluginVersion = '0.34.0'
shadowJarPluginVersion = '7.1.2'
}

repositories {
Expand Down
10 changes: 10 additions & 0 deletions cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ghcr.io/scalar-labs/jre8:1.1.14

COPY scalar-admin-k8s-*.jar /app.jar

RUN groupadd -r --gid 201 scalar && \
useradd -r --uid 201 -g scalar scalar

USER 201

ENTRYPOINT ["java", "-jar", "/app.jar"]
9 changes: 8 additions & 1 deletion cli/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.github.johnrengelman.shadow' version "${shadowJarPluginVersion}"
id 'com.palantir.docker' version "${dockerPluginVersion}"
}

dependencies {
Expand All @@ -18,3 +19,9 @@ shadowJar {
// this is to merge gRPC service files into the shadow jar
mergeServiceFiles()
}

docker {
dependsOn shadowJar
name "ghcr.io/scalar-labs/scalar-admin-k8s:${project.version}"
files tasks.shadowJar.outputs
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
54 changes: 54 additions & 0 deletions lib/archive.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'scalar-admin-k8s'
from components.java
pom {
name = 'Scalar Admin for Kubernetes'
description = 'This library provides a fault-tolerant manner to pause Scalar products in Kubernetes environments and ensure the data is transactionally consistent.'
url = 'https://github.com/scalar-labs/scalar-admin'
licenses {
license {
name = 'Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0'
}
}
developers {
developer {
id = 'hiroyuki'
name = 'Hiroyuki Yamada'
email = '[email protected]'
}
developer {
id = 'supl'
name = 'Plenty Su'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:https://github.com/scalar-labs/scalar-admin-k8s.git'
developerConnection = 'scm:git:https://github.com/scalar-labs/scalar-admin-k8s.git'
url = 'https://github.com/scalar-labs/scalar-admin-k8s'
}
}
}
}
repositories {
maven {
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = "${ossrhUsername}"
password = "${ossrhPassword}"
}
}
}
}

signing {
sign publishing.publications.mavenJava
}
6 changes: 6 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ test {
events "passed", "skipped", "failed"
}
}

if (!project.gradle.startParameter.taskNames.isEmpty() &&
(project.gradle.startParameter.taskNames[0].endsWith('publish') ||
project.gradle.startParameter.taskNames[0].endsWith('publishToMavenLocal'))) {
apply from: 'archive.gradle'
}

0 comments on commit 1cb63ee

Please sign in to comment.