-
Notifications
You must be signed in to change notification settings - Fork 64
138 lines (135 loc) · 5.61 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Continuous Integration
on: [push, pull_request, workflow_dispatch]
jobs:
check_duplicate_workflows:
name: Check for duplicate workflows
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
# Map a step output to a job output
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
skip_after_successful_duplicate: 'false'
concurrent_skipping: 'same_content'
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'
paths_ignore: '["**/*.md"]'
build:
name: Build
runs-on: ${{ matrix.platform }}
needs: [check_duplicate_workflows]
if: ${{ needs.check_duplicate_workflows.outputs.should_skip != 'true' }}
strategy:
matrix:
java: [ '8', '11', '17' ]
platform: ['windows-latest', 'ubuntu-latest']
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: ${{ matrix.java }}
cache: 'gradle'
- name: print Java version
run: java -version
- name: Run build
run: ./gradlew clean assemble --info
test:
name: Test
runs-on: ${{ matrix.platform }}
needs: [build]
strategy:
matrix:
java: [ '8', '11', '17' ]
platform: ['windows-latest', 'ubuntu-latest']
steps:
- uses: actions/checkout@v4
- name: Gradle wrapper validation
uses: gradle/wrapper-validation-action@v3
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: ${{ matrix.java }}
cache: 'gradle'
- name: print Java version
run: java -version
- name: Run test
run: ./gradlew check --info
publish:
name : Publish
runs-on: ubuntu-latest
needs: [ test ]
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'tschuchortdev/kotlin-compile-testing'
env:
# https://proandroiddev.com/publishing-a-maven-artifact-3-3-step-by-step-instructions-to-mavencentral-publishing-bd661081645d
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
# https://blog.solidsoft.pl/2020/06/03/simpler-and-safer-artifact-signing-on-ci-server-with-gradle/
# https://stackoverflow.com/questions/57921325/gradle-signarchives-unable-to-read-secret-key
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_KEY_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_SIGNING_PRIVATE_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false # without this, all access tokens set later on will be ignored
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: 11
cache: 'gradle'
- name: Set git config
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Check if snapshot version
run: |
VERSION_NAME=$(./gradlew -q printVersionName | tail -n 1)
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
IS_SNAPSHOT_VERSION=$([[ "$VERSION_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT$ ]] && echo "true" || echo "false")
echo "IS_SNAPSHOT_VERSION=$IS_SNAPSHOT_VERSION" >> $GITHUB_ENV
- name: Publish to Sonatype Nexus
run: |
# --max-workers 1 limits Gradle to a single thread even if parallel builds are enabled in the hopes
# of making the the upload to Sonatype Nexus less flaky
if [[ "$IS_SNAPSHOT_VERSION" == "true" ]]; then
echo "Version is a snapshot. No closing of the repository is necessary."
./gradlew publishToSonatype --info --max-workers 1
elif [[ "$IS_SNAPSHOT_VERSION" == "false" ]]; then
echo "Version is not a snapshot. Trying to close and release repository."
# Note: Until https://github.com/gradle-nexus/publish-plugin/issues/19 is fixed
# publish and close/release always have to be executed in the same Gradle call
# or closing will fail with error 'No staging repository with name sonatype created'.
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --info --max-workers 1
else
echo "IS_SNAPSHOT_VERSION has unknown value: $IS_SNAPSHOT_VERSION"
exit 1
fi
- name: Make release on Github
uses: marvinpinto/action-automatic-releases@latest
if: ${{ env.IS_SNAPSHOT_VERSION == 'false' }}
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: ${{ env.VERSION_NAME }}
prerelease: false
title: ${{ env.VERSION_NAME }}
files: |
LICENSE
core/build/libs/*.*
ksp/build/libs/*.*
- name: Set next snapshot version
if: ${{ env.IS_SNAPSHOT_VERSION == 'false' }}
run: |
echo "Setting next snapshot version"
./gradlew incrementPatchVersion --info
./gradlew setSnapshotVersionSuffix --info
git add gradle.properties
git commit -m "Setting next snapshot version [skip ci]"
git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git --follow-tags