-
Notifications
You must be signed in to change notification settings - Fork 31
211 lines (184 loc) · 5.91 KB
/
Copy pathnative-image.yml
File metadata and controls
211 lines (184 loc) · 5.91 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
204
205
206
207
208
209
210
211
name: native-image
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
# 新增:发布 API 模块到 GitHub Packages
publish-api:
name: publish api
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'liberica'
server-id: github # 对应 pom.xml 中的 distributionManagement.repository.id
- name: Publish API to GitHub Packages
run: mvn -B clean deploy -pl push-server-api -am -DskipTests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
name: build (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
artifact: linux-amd64
arch: amd64
ext: ""
- os: ubuntu-24.04-arm
artifact: linux-arm64
arch: arm64
ext: ""
- os: macos-latest
artifact: macos
arch: macos
ext: ""
- os: windows-latest
artifact: windows
arch: windows
ext: ".exe"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Liberica NIK
uses: graalvm/setup-graalvm@v1
with:
java-version: '25'
distribution: 'liberica'
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: 'maven'
- name: Select Maven command
shell: bash
run: |
if [ -f ./mvnw ]; then
chmod +x ./mvnw
echo "MVN_CMD=./mvnw" >> "$GITHUB_ENV"
else
echo "MVN_CMD=mvn" >> "$GITHUB_ENV"
fi
# 修复:先安装父工程和 API 模块到本地仓库,解决核心模块编译时的依赖问题
- name: Install parent and api
shell: bash
run: |
${{ env.MVN_CMD }} install -N -B
${{ env.MVN_CMD }} install -pl push-server-api -am -B -DskipTests
- name: Checkout Frontend
uses: actions/checkout@v4
with:
repository: qingzhou-dev/push-server-web
path: push-server-web
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Build Frontend
shell: bash
run: |
cd push-server-web
npm install
npm run build
cd ..
mkdir -p push-server-core/src/main/resources/static
cp -r push-server-web/dist/* push-server-core/src/main/resources/static/
- name: Build native image
shell: bash
run: ${{ env.MVN_CMD }} -B -pl push-server-core -Pnative -DskipTests native:compile
- name: Rename binary
shell: bash
run: |
mkdir -p target-bin
# 尝试从不同的可能位置查找生成的二进制文件
FOUND_BIN=""
for f in push-server-core/target/push-server-core${{ matrix.ext }} push-server-core/target/push-server${{ matrix.ext }}; do
if [ -f "$f" ]; then
FOUND_BIN="$f"
break
fi
done
if [ -z "$FOUND_BIN" ]; then
echo "Error: Native image binary not found!"
ls -R push-server-core/target/
exit 1
fi
dest="target-bin/push-server-${{ matrix.artifact }}${{ matrix.ext }}"
echo "Moving $FOUND_BIN to $dest"
mv "$FOUND_BIN" "$dest"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: push-server-${{ matrix.artifact }}
path: target-bin/push-server-${{ matrix.artifact }}${{ matrix.ext }}
if-no-files-found: error
- name: Upload release asset
if: github.event_name == 'release'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
files: target-bin/push-server-${{ matrix.artifact }}${{ matrix.ext }}
docker-push:
name: docker push
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download amd64 binary
uses: actions/download-artifact@v4
with:
name: push-server-linux-amd64
path: bin-amd64
- name: Download arm64 binary
uses: actions/download-artifact@v4
with:
name: push-server-linux-arm64
path: bin-arm64
- name: Prepare binaries
run: |
mkdir -p target
cp bin-amd64/push-server-linux-amd64 target/push-server-amd64
cp bin-arm64/push-server-linux-arm64 target/push-server-arm64
ls -R target
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
qingzhoudev/push-server
ghcr.io/qingzhou-dev/push-server
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}