Skip to content

Commit ffcb811

Browse files
committed
Test and Release in Github CI
1 parent 4b59a86 commit ffcb811

File tree

4 files changed

+168
-11
lines changed

4 files changed

+168
-11
lines changed

.github/workflows/ci.yml

+133-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,146 @@
1-
name: Java CI
1+
name: Continuous Integration
22
on: [push, pull_request]
33
jobs:
4-
build:
4+
check_duplicate_workflows:
5+
name: Check for duplicate workflows
56
runs-on: ubuntu-latest
7+
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
8+
# Map a step output to a job output
9+
outputs:
10+
should_skip: ${{ steps.skip_check.outputs.should_skip }}
11+
steps:
12+
- id: skip_check
13+
uses: fkirc/skip-duplicate-actions@master
14+
with:
15+
paths_ignore: '["**/*.md"]'
16+
build:
17+
name: Build
18+
runs-on: ${{ matrix.platform }}
19+
needs: [check_duplicate_workflows]
20+
if: ${{ needs.check_duplicate_workflows.outputs.should_skip != 'true' }}
621
strategy:
722
matrix:
823
java: [ '8', '11', '15' ]
24+
platform: ['windows-latest', 'ubuntu-latest']
925
steps:
10-
- uses: actions/checkout@v1
26+
- uses: actions/checkout@v2
1127
- name: Set up JDK ${{ matrix.java }}
1228
uses: actions/setup-java@v1
1329
with:
1430
java-version: ${{ matrix.java }}
31+
- name: Cache Gradle packages
32+
uses: actions/cache@v2
33+
with:
34+
path: ~/.gradle/caches
35+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
36+
restore-keys: ${{ runner.os }}-gradle
1537
- name: print Java version
1638
run: java -version
17-
- name: Build with Gradle
18-
run: ./gradlew clean build
39+
- name: Run build
40+
run: ./gradlew clean assemble --info
41+
42+
test:
43+
name: Test
44+
runs-on: ${{ matrix.platform }}
45+
needs: [build]
46+
strategy:
47+
matrix:
48+
java: [ '8', '11', '15' ]
49+
platform: ['windows-latest', 'ubuntu-latest']
50+
steps:
51+
- uses: actions/checkout@v2
52+
- name: Set up JDK
53+
uses: actions/setup-java@v1
54+
with:
55+
java-version: ${{ matrix.java }}
56+
- name: Cache Gradle packages
57+
uses: actions/cache@v2
58+
with:
59+
path: ~/.gradle/caches
60+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
61+
restore-keys: ${{ runner.os }}-gradle
62+
- name: print Java version
63+
run: java -version
64+
- name: Run test
65+
run: ./gradlew check --info
66+
67+
publish:
68+
name : Publish
69+
runs-on: ubuntu-latest
70+
needs: [ test ]
71+
if: github.ref == 'refs/heads/master'
72+
env:
73+
# https://proandroiddev.com/publishing-a-maven-artifact-3-3-step-by-step-instructions-to-mavencentral-publishing-bd661081645d
74+
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
75+
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
76+
# https://blog.solidsoft.pl/2020/06/03/simpler-and-safer-artifact-signing-on-ci-server-with-gradle/
77+
# https://stackoverflow.com/questions/57921325/gradle-signarchives-unable-to-read-secret-key
78+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_KEY_PASSWORD }}
79+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_SIGNING_PRIVATE_KEY }}
80+
steps:
81+
- uses: actions/checkout@v2
82+
- name: Set up JDK
83+
uses: actions/setup-java@v1
84+
with:
85+
java-version: 11
86+
- name: Cache Gradle packages
87+
uses: actions/cache@v2
88+
with:
89+
path: ~/.gradle/caches
90+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
91+
restore-keys: ${{ runner.os }}-gradle
92+
- name: Set git config
93+
run: |
94+
git config user.name github-actions
95+
git config user.email [email protected]
96+
- name: Check if snapshot version
97+
run: |
98+
VERSION_NAME=$(./gradlew -q printVersionName | tail -n 1)
99+
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
100+
IS_SNAPSHOT_VERSION=$([[ "$VERSION_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT$ ]] && echo "true" || echo "false")
101+
echo "IS_SNAPSHOT_VERSION=$IS_SNAPSHOT_VERSION" >> $GITHUB_ENV
102+
- name: Publish to Sonatype Nexus
103+
run: |
104+
./gradlew publish --info
105+
106+
if [[ "$IS_SNAPSHOT_VERSION" == "true" ]]; then
107+
echo "Version is a snapshot. No closing of the repository is necessary."
108+
elif [[ "$IS_SNAPSHOT_VERSION" == "false" ]]; then
109+
echo "Version is not a snapshot. Trying to close and release repository."
110+
./gradlew closeAndReleaseRepository --info
111+
else
112+
echo "IS_SNAPSHOT_VERSION has unknown value: $IS_SNAPSHOT_VERSION"
113+
exit 1
114+
fi
115+
- name: Make github snapshot release
116+
uses: "marvinpinto/action-automatic-releases@latest"
117+
if: ${{ env.IS_SNAPSHOT_VERSION == 'true' }}
118+
with:
119+
repo_token: ${{ secrets.GITHUB_TOKEN }}
120+
automatic_release_tag: "latest"
121+
prerelease: true
122+
title: "Latest Snapshot"
123+
files: |
124+
LICENSE
125+
core/build/libs/*.*
126+
ksp/build/libs/*.*
127+
- name: Make github release
128+
uses: "marvinpinto/action-automatic-releases@latest"
129+
if: ${{ env.IS_SNAPSHOT_VERSION == 'false' }}
130+
with:
131+
repo_token: ${{ secrets.GITHUB_TOKEN }}
132+
automatic_release_tag: $VERSION_NAME
133+
prerelease: false
134+
title: $VERSION_NAME
135+
files: |
136+
LICENSE
137+
core/build/libs/*.*
138+
ksp/build/libs/*.*
139+
- name: Set next snapshot version
140+
if: ${{ env.IS_SNAPSHOT_VERSION == 'false' }}
141+
run: |
142+
echo "Setting next snapshot version"
143+
./gradlew incrementPatchVersion setSnapshotVersionSuffix --info
144+
git add gradle.properties
145+
git commit -m "Setting next snapshot version [skip ci]"
146+
git push

Releasing.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Making a release
2+
3+
The CI is configured to publish a release to Sonatype Nexus on every push to master. If the version name in gradle.properties has the SNAPSHOT suffix, then a snapshot release will be published on Sonatype and a pre-release with tag "latest" will be created/replaced on Github. If, on the other hand, the version name does not have the SNAPSHOT suffix, a proper release with that version name will be made on Sonatype and Github and subsequently, the version name in gradle.properties is updated to the SNAPSHOT of the next semantic patch version. In both cases, the Github release notes are created automatically from commit messages. Thus, to make a release it is sufficient (and recommended) to make a commit to master which only updates gradle.properties to the desired version. If a release is published manually and not through CI, it is important that the version be set to the next SNAPSHOT patch version, so that snapshot releases can continue to be published by the CI (otherwise CI will fail because the version already exist).
4+
5+
6+
## Manual release
7+
8+
Releasing is done through the `nexus-staging` Gradle plugin in combination with the `signing` and `maven-publish` plugins.
9+
10+
See: https://proandroiddev.com/publishing-a-maven-artifact-3-3-step-by-step-instructions-to-mavencentral-publishing-bd661081645d
11+
12+
Steps:
13+
- `./gradlew publish`
14+
- `./gradlew closeAndReleaseRepository` (not necessary for SNAPSHOT releases)
15+
16+
The following environment variables have to be defined:
17+
- `SONATYPE_NEXUS_USERNAME`
18+
- `SONATYPE_NEXUS_PASSWORD`
19+
20+
In `/home/<user>/.gradle/gradle.properties` the following properties have to be defined:
21+
- `signing.keyId` (last 8 digits of the RSA certify/signing-key's id/fingerprint)
22+
- `signing.password` (password for the GPG signing key)
23+
- `signing.secretKeyRingFile` (path to the armored GPG signing key)

build.gradle

+12-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,18 @@ subprojects {
134134

135135
signing {
136136
// Skip signing if publishing to mavenLocal and credentials are not available
137-
// so that jitpack works correctly
138-
required { !gradle.taskGraph.hasTask("publishToMavenLocal") }
137+
required { !gradle.taskGraph.hasTask("publishToMavenLocal") && project.hasProperty("signing.keyId") }
138+
139+
if (!project.hasProperty("signing.secretKeyRingFile") && !project.hasProperty("signing.password")) {
140+
/* If in CI, the signing password and signing key are defined in the environment variables
141+
ORG_GRADLE_PROJECT_signingPassword and ORG_GRADLE_PROJECT_signingKey
142+
(https://blog.solidsoft.pl/2020/06/03/simpler-and-safer-artifact-signing-on-ci-server-with-gradle/,
143+
https://stackoverflow.com/questions/57921325/gradle-signarchives-unable-to-read-secret-key).
144+
Otherwise they are defined in the user's home directory gradle.properties.
145+
*/
146+
useInMemoryPgpKeys(findProperty("signingKey"), findProperty("signingPassword"))
147+
}
148+
139149
sign publishing.publications.mavenJava
140150
}
141151

release.sh

-4
This file was deleted.

0 commit comments

Comments
 (0)