diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..bbac1d3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 + diff --git a/build.gradle b/build.gradle index 5dddc53..59630bb 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/lib/build.gradle b/lib/build.gradle index 1c1a88d..6922ba6 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -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() } @@ -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") +// } +// } } }