-
Notifications
You must be signed in to change notification settings - Fork 0
203 lines (173 loc) · 5.69 KB
/
Copy pathci-cd.yml
File metadata and controls
203 lines (173 loc) · 5.69 KB
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
196
197
198
199
200
201
202
203
# This workflow will build a Java project with Gradle, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
# 权限声明,确保 workflow 有权限写 checks 和 security-events
permissions:
contents: write
packages: write
checks: write
security-events: write
name: Java CI with Gradle
on:
push:
branches: [ "main" ]
tags:
- 'v*'
paths-ignore:
- 'README.md'
- 'LICENSE'
- '.gitignore'
- '.gitattributes'
- 'picture'
- '.dockerignore'
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
ci:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
java-version: ['17', '21', '25']
fail-fast: false
name: Build with Java ${{ matrix.java-version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: 'gradle'
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Build and Test with Gradle
run: |
./gradlew build --parallel
env:
GRADLE_OPTS: -Xmx4g -XX:MaxMetaspaceSize=1g
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure()
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
detailed_summary: true
include_passed: true
fail_on_failure: false
- name: Run SonarQube Analysis
if: matrix.java-version == '17' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
run: |
if [[ -n "${{ secrets.SONAR_TOKEN }}" ]]; then
ORG="${{ secrets.SONAR_ORGANIZATION }}"
ORG=${ORG:-default}
HOST="${{ secrets.SONAR_HOST_URL }}"
HOST=${HOST:-https://sonarcloud.io}
./gradlew sonarqube \
-Dsonar.projectKey=keystone \
-Dsonar.organization=$ORG \
-Dsonar.host.url=$HOST \
-Dsonar.login=${{ secrets.SONAR_TOKEN }} \
-Dsonar.qualitygate.wait=true \
-Dsonar.java.source=17
else
echo "Skipping SonarQube analysis - SONAR_TOKEN not configured"
fi
- name: Upload static analysis reports
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: static-analysis-reports-jdk-${{ matrix.java-version }}
if-no-files-found: warn
retention-days: 7
path: |
**/build/reports/checkstyle/**
**/build/reports/spotbugs/**
build-release:
name: Build Github release
runs-on: ubuntu-latest
needs: ci
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'temurin'
cache: 'gradle'
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Validate tag matches project version
run: |
TAG="${GITHUB_REF_NAME#v}"
VERSION=$(./gradlew -q properties | awk -F': ' '/^version:/ {print $2; exit}')
if [ "$TAG" != "$VERSION" ]; then
echo "Tag version ($TAG) does not match project version ($VERSION)"
exit 1
fi
- name: Build release
run: ./gradlew clean build -x test
- name: Generate Changelog with git-cliff
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: cliff.toml
args: --latest --strip header
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.git-cliff.outputs.content }}
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-docker:
name: Push Docker image to multiple registries
runs-on: ubuntu-latest
needs: build-release
if: startsWith(github.ref, 'refs/tags/v')
concurrency: deploy-group
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'temurin'
cache: 'gradle'
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Build application jar for Docker image
run: ./gradlew :keystone-admin:bootJar -x test
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}