Skip to content

Commit

Permalink
Github actions for release and publish to maven central.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Fuchs committed Apr 12, 2021
1 parent 5e12648 commit bc99219
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 28 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish package to the Maven Central Repository
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Set Version from Tag
run: echo "CI_RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Publish package
run: ./gradlew publish
env:
ORG_GRADLE_PROJECT_GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
ORG_GRADLE_PROJECT_GPG_SIGNING_KEY_PASSWORD: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
OSSRH_MAVEN_USERNAME: ${{ secrets.OSSRH_MAVEN_USERNAME }}
OSSRH_MAVEN_PASSWORD: ${{ secrets.OSSRH_MAVEN_PASSWORD }}
- name: Cleanup Gradle Cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
13 changes: 9 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@

group 'org.example'
version '1.0-SNAPSHOT'


subprojects {
// sourceCompatibility = 1.8
// targetCompatibility = 1.8
def releaseVersion = System.getenv("CI_RELEASE_VERSION")
def runId = System.getenv("GITHUB_RUN_ID")

version = releaseVersion != null ? releaseVersion
: runId != null ? "build-${runId}-SNAPSHOT"
: "LOCAL-SNAPSHOT"

group 'de.fumix'
}

78 changes: 54 additions & 24 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,10 @@ plugins {
id 'maven-publish'
}

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8

task sourcesJar(type: Jar) {
classifier 'sources'
from sourceSets.main.allJava
}
task javadocJar(type: Jar) {
classifier 'javadoc'
from javadoc
}


repositories {
mavenCentral()
}
Expand All @@ -34,31 +22,73 @@ dependencies {

}

test {
useJUnitPlatform()
java {
withJavadocJar()
withSourcesJar()
}

artifacts {
archives javadocJar, sourcesJar
test {
useJUnitPlatform()
}

signing {
def signingKey = findProperty("GPG_SIGNING_KEY")
def signingPassword = findProperty("GPG_SIGNING_KEY_PASSWORD")
def signingKey = findProperty("GPG_SIGNING_KEY") // ORG_GRADLE_PROJECT_GPG_SIGNING_KEY -> ascii armored private PGP key
def signingPassword = findProperty("GPG_SIGNING_KEY_PASSWORD") // ORG_GRADLE_PROJECT_GPG_SIGNING_KEY_PASSWORD
useInMemoryPgpKeys(signingKey, signingPassword)

sign configurations.archives
}

publishing {
publications {
maven(MavenPublication) {
groupId = project.group
artifactId = "holidays"
version = project.version

from components.java

pom {
name = "holidays"
description = "Legal holidays, weekends, workdays by date (for Germany, but extendable)"
url = "https://github.com/fumiX/holidays"
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'michael-fuchs'
name = 'Michael Fuchs'
email = 'michael.fuchs@fumix.de'
}
}
scm {
connection = 'scm:git:https://github.com/fumix/holidays.git'
developerConnection = 'scm:git:git@github.com:fumix/holidays.git'
url = 'https://github.com/fumix/holidays'
}
}
}
}
// telling gradle to publish artifact to local directory (3)
repositories {
maven {
name = "OSSRH"
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username = System.getenv("OSSRH_MAVEN_USERNAME")
password = System.getenv("OSSRH_MAVEN_PASSWORD")
}
url "file:/${project.projectDir}/build/artifacts"
}
// maven {
// name = "OSSRH"
//
// def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
// def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
// url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
//
// credentials {
// username = System.getenv("OSSRH_MAVEN_USERNAME")
// password = System.getenv("OSSRH_MAVEN_PASSWORD")
// }
// }
}
}

0 comments on commit bc99219

Please sign in to comment.