-
Notifications
You must be signed in to change notification settings - Fork 2
195 lines (173 loc) · 6.82 KB
/
build.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: build-release
on:
push:
branches: [ main ]
tags: [ 'v*' ]
paths-ignore:
- '.github/ISSUE_TEMPLATE/**'
- '.github/*.yml'
- '*.md'
- 'LICENSE'
pull_request:
types: [ opened, synchronize, reopened, closed ]
branches: [ main ]
env:
ENABLE_TEST: true
ENABLE_SONAR: true
ENABLE_GH_MAVEN: false
JAVA_DIST: 'temurin'
JAVA_VERSION: '17'
jobs:
context:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.context.outputs.branch }}
shouldBuild: ${{ steps.context.outputs.decision_build }}
shouldPublish: ${{ steps.context.outputs.decision_publish }}
isRelease: ${{ steps.context.outputs.isTag }}
version: ${{ steps.context.outputs.version }}
commitId: ${{ steps.context.outputs.shortCommitId }}
semanticVersion: ${{ steps.dynamic_prop.outputs.semanticVersion }}
steps:
- uses: actions/[email protected]
with:
token: ${{ secrets.BEEIO_CI_TOKEN }}
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
git_push_gpgsign: false
gpg_private_key: ${{ secrets.OSS_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.OSS_GPG_PASSPHARSE }}
- name: Project context
id: context
uses: zero88/[email protected]
with:
mustSign: true
nextVerMode: PATCH
- name: Query dynamic properties
id: dynamic_prop
shell: bash
run: |
[[ "${{ steps.context.outputs.isTag }}" == "true" ]] && sv="" || sv=$(grep semanticVersion gradle.properties | cut -d'=' -f2)
echo semanticVersion=$sv >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: context
if: needs.context.outputs.shouldBuild == 'true'
steps:
- uses: actions/[email protected]
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
if: needs.context.outputs.shouldPublish == 'true'
with:
git_user_signingkey: true
gpg_private_key: ${{ secrets.OSS_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.OSS_GPG_PASSPHARSE }}
- name: Set up JDK
uses: actions/[email protected]
with:
distribution: ${{ env.JAVA_DIST }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'
- name: Build
run: |
./gradlew clean build -x test \
-Pversion=${{ needs.context.outputs.version }} \
-PsemanticVersion=${{ needs.context.outputs.semanticVersion }} \
-PbuildBy="GitHub Action" -PbuildHash=${{ needs.context.outputs.commitId }}
- name: Publish Sonatype OSSRH
if: needs.context.outputs.shouldPublish == 'true' && needs.context.outputs.isRelease != 'true'
run: |
args=( -Pversion=${{ needs.context.outputs.version }} \
-PsemanticVersion=${{ needs.context.outputs.semanticVersion }} \
-Pnexus.username=${{ secrets.ORG_NEXUS_USER }} \
-Pnexus.password=${{ secrets.ORG_NEXUS_TOKEN }} )
./gradlew publish "${args[@]}"
analysis:
runs-on: ubuntu-latest
needs: context
if: needs.context.outputs.shouldBuild == 'true'
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/[email protected]
with:
distribution: ${{ env.JAVA_DIST }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar-qwe
restore-keys: ${{ runner.os }}-sonar-qwe
- name: Test
if: env.ENABLE_TEST == 'true'
run: ./gradlew test jacocoTestReport -PjacocoHtml=false
- name: SonarQube
if: needs.context.outputs.shouldPublish == 'true' && env.ENABLE_SONAR == 'true'
run: |
./gradlew sonarqube --info -x test \
-Dsonar.branch.name=${{ needs.context.outputs.branch }} \
-Dorg.gradle.jvmargs="-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.OSS_SONARQUBE_TOKEN }}
release:
runs-on: ubuntu-latest
needs: [ build, context ]
if: needs.context.outputs.isRelease == 'true'
steps:
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.context.outputs.branch }}
release_name: Release ${{ needs.context.outputs.branch }}
draft: false
prerelease: false
promote:
name: Promote Sonatype OSSRH
runs-on: ubuntu-latest
needs: [ build, context ]
if: needs.context.outputs.isRelease == 'true'
steps:
- uses: actions/[email protected]
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
git_user_signingkey: true
gpg_private_key: ${{ secrets.OSS_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.OSS_GPG_PASSPHARSE }}
- name: Publish Sonatype OSSRH
run: |
args=( -Pversion=${{ needs.context.outputs.version }} \
-PsemanticVersion=${{ needs.context.outputs.semanticVersion }} \
-PbuildBy="GitHub Action" -PbuildHash=${{ needs.context.outputs.commitId }} \
-Psigning.gnupg.homeDir=/home/runner/.gnupg \
-Psigning.gnupg.keyName=${{ steps.import_gpg.outputs.keyid }} \
-Psigning.gnupg.passphrase=${{ secrets.OSS_GPG_PASSPHARSE }} \
-Pnexus.username=${{ secrets.ORG_NEXUS_USER }} \
-Pnexus.password=${{ secrets.ORG_NEXUS_TOKEN }} )
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -Prelease "${args[@]}"
- name: Publish GitHub Package
if: env.ENABLE_GH_MAVEN == 'true'
run: |
args=( -Pversion=${{ needs.context.outputs.version }} \
-PsemanticVersion=${{ needs.context.outputs.semanticVersion }} \
-PbuildBy="GitHub Action" -PbuildHash=${{ needs.context.outputs.commitId }} \
-Psigning.gnupg.homeDir=/home/runner/.gnupg \
-Psigning.gnupg.keyName=${{ steps.import_gpg.outputs.keyid }} \
-Psigning.gnupg.passphrase=${{ secrets.OSS_GPG_PASSPHARSE }} \
-Pnexus.username=${{ github.repository_owner }} \
-Pnexus.password=${{ secrets.BEEIO_CI_TOKEN }} )
args+=( -Pgithub )
./gradlew publishMavenPublicationToMavenRepository -Prelease "${args[@]}"