-
Notifications
You must be signed in to change notification settings - Fork 14
309 lines (264 loc) · 10.4 KB
/
ci.yml
File metadata and controls
309 lines (264 loc) · 10.4 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
name: CI
permissions:
contents: write
on:
push:
branches: ["**"]
tags: ["v*"]
pull_request:
workflow_dispatch:
inputs:
version:
description: "Release version (e.g., 1.2.3)"
required: true
type: string
release_notes:
description: "Release notes / changelog"
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
shell: bash
run: |
set -euo pipefail
BASE_VERSION="1.0"
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
VERSION="${{ inputs.version }}"
elif [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF_NAME#v}"
else
VERSION="${BASE_VERSION}.${GITHUB_RUN_NUMBER}"
fi
VERSION="${VERSION#v}"
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "Version: ${VERSION}"
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
working-directory: web
run: npm ci
- name: Build frontend
working-directory: web
run: npm run build
- name: Sync frontend into backend wwwroot
shell: bash
run: |
set -euo pipefail
mkdir -p src/MoYuCode/wwwroot
rsync -a --delete web/dist/ src/MoYuCode/wwwroot/
- name: Build backend
if: github.event_name != 'workflow_dispatch'
run: dotnet build src/MoYuCode/MoYuCode.csproj -c Release -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }}
- name: Publish backend
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
set -euo pipefail
for RID in linux-x64 osx-x64; do
dotnet publish src/MoYuCode/MoYuCode.csproj -c Release -r "${RID}" --self-contained false -o "artifacts/publish/${RID}" -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }}
done
WIN_PUBLISH_ROOT="artifacts/publish/win-x64"
rm -rf "${WIN_PUBLISH_ROOT}"
mkdir -p "${WIN_PUBLISH_ROOT}"
dotnet publish src/MoYuCode.Win/MoYuCode.Win.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }} -p:DebugType=None -p:DebugSymbols=false -o "${WIN_PUBLISH_ROOT}"
if [[ ! -f "${WIN_PUBLISH_ROOT}/MoYuCode.Win.exe" ]]; then
echo "MoYuCode.Win.exe not found in win-x64 publish output."
exit 1
fi
- name: Add platform scripts
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
set -euo pipefail
cat > "artifacts/publish/linux-x64/run.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
export DOTNET_ENVIRONMENT=Production
export ASPNETCORE_URLS="http://0.0.0.0:9110"
echo "MoYuCode is running at $ASPNETCORE_URLS"
echo "Open: http://localhost:9110"
if [[ -f "./MoYuCode" ]]; then
chmod +x "./MoYuCode"
./MoYuCode
else
dotnet "./MoYuCode.dll"
fi
EOF
chmod +x "artifacts/publish/linux-x64/run.sh"
cat > "artifacts/publish/linux-x64/install-service.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
SERVICE_NAME="${SERVICE_NAME:-myyucode}"
URLS="${URLS:-http://0.0.0.0:9110}"
INSTALL_DIR="$(cd "$(dirname "$0")" && pwd)"
if [[ $EUID -ne 0 ]]; then
echo "Run this script with sudo." >&2
exit 1
fi
if [[ -x "$INSTALL_DIR/MoYuCode" ]]; then
EXECUTABLE="$INSTALL_DIR/MoYuCode"
elif [[ -f "$INSTALL_DIR/MoYuCode.dll" ]]; then
DOTNET_PATH="$(command -v dotnet || true)"
if [[ -z "$DOTNET_PATH" ]]; then
echo "dotnet not found in PATH." >&2
exit 1
fi
EXECUTABLE="$DOTNET_PATH $INSTALL_DIR/MoYuCode.dll"
else
echo "MoYuCode executable not found in $INSTALL_DIR" >&2
exit 1
fi
SERVICE_PATH="/etc/systemd/system/${SERVICE_NAME}.service"
cat > "$SERVICE_PATH" <<SERVICE_EOF
[Unit]
Description=MoYuCode service
After=network.target
[Service]
WorkingDirectory=$INSTALL_DIR
ExecStart=$EXECUTABLE --urls $URLS
Restart=always
RestartSec=5
Environment=DOTNET_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=$URLS
[Install]
WantedBy=multi-user.target
SERVICE_EOF
systemctl daemon-reload
systemctl enable --now "$SERVICE_NAME"
systemctl status "$SERVICE_NAME" --no-pager
echo "URL: $URLS"
echo "Open: http://localhost:9110"
EOF
chmod +x "artifacts/publish/linux-x64/install-service.sh"
cat > "artifacts/publish/osx-x64/run.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
export DOTNET_ENVIRONMENT=Production
export ASPNETCORE_URLS="http://0.0.0.0:9110"
echo "MoYuCode is running at $ASPNETCORE_URLS"
echo "Open: http://localhost:9110"
if [[ -f "./MoYuCode" ]]; then
chmod +x "./MoYuCode"
./MoYuCode
else
dotnet "./MoYuCode.dll"
fi
EOF
chmod +x "artifacts/publish/osx-x64/run.sh"
cat > "artifacts/publish/osx-x64/install-service.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
SERVICE_NAME="${SERVICE_NAME:-com.myyucode.service}"
URLS="${URLS:-http://0.0.0.0:9110}"
INSTALL_DIR="$(cd "$(dirname "$0")" && pwd)"
if [[ $EUID -ne 0 ]]; then
echo "Run this script with sudo." >&2
exit 1
fi
if [[ -x "$INSTALL_DIR/MoYuCode" ]]; then
program_args=("$INSTALL_DIR/MoYuCode" "--urls" "$URLS")
else
dll="$INSTALL_DIR/MoYuCode.dll"
if [[ ! -f "$dll" ]]; then
echo "MoYuCode executable not found in $INSTALL_DIR" >&2
exit 1
fi
dotnet_path="$(command -v dotnet || true)"
if [[ -z "$dotnet_path" ]]; then
for candidate in /usr/local/share/dotnet/dotnet /opt/homebrew/bin/dotnet; do
if [[ -x "$candidate" ]]; then
dotnet_path="$candidate"
break
fi
done
fi
if [[ -z "$dotnet_path" ]]; then
echo "dotnet not found in PATH." >&2
exit 1
fi
program_args=("$dotnet_path" "$dll" "--urls" "$URLS")
fi
plist_path="/Library/LaunchDaemons/${SERVICE_NAME}.plist"
{
echo '<?xml version="1.0" encoding="UTF-8"?>'
echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
echo '<plist version="1.0">'
echo '<dict>'
echo ' <key>Label</key>'
echo " <string>${SERVICE_NAME}</string>"
echo ' <key>ProgramArguments</key>'
echo ' <array>'
for arg in "${program_args[@]}"; do
printf ' <string>%s</string>\n' "$arg"
done
echo ' </array>'
echo ' <key>WorkingDirectory</key>'
echo " <string>${INSTALL_DIR}</string>"
echo ' <key>EnvironmentVariables</key>'
echo ' <dict>'
echo ' <key>DOTNET_ENVIRONMENT</key>'
echo ' <string>Production</string>'
echo ' <key>ASPNETCORE_URLS</key>'
echo " <string>${URLS}</string>"
echo ' </dict>'
echo ' <key>RunAtLoad</key>'
echo ' <true/>'
echo ' <key>KeepAlive</key>'
echo ' <true/>'
echo ' <key>StandardOutPath</key>'
echo " <string>${INSTALL_DIR}/myyucode.out.log</string>"
echo ' <key>StandardErrorPath</key>'
echo " <string>${INSTALL_DIR}/myyucode.err.log</string>"
echo '</dict>'
echo '</plist>'
} > "$plist_path"
launchctl bootout system "$plist_path" >/dev/null 2>&1 || true
launchctl bootstrap system "$plist_path"
launchctl enable system/"${SERVICE_NAME}"
launchctl kickstart -k system/"${SERVICE_NAME}"
echo "URL: $URLS"
echo "Open: http://localhost:9110"
EOF
chmod +x "artifacts/publish/osx-x64/install-service.sh"
- name: Package release assets
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
set -euo pipefail
mkdir -p artifacts
tar -czf "artifacts/MoYuCode-${{ steps.version.outputs.version }}-linux-x64.tar.gz" -C artifacts/publish/linux-x64 .
tar -czf "artifacts/MoYuCode-${{ steps.version.outputs.version }}-osx-x64.tar.gz" -C artifacts/publish/osx-x64 .
(cd artifacts/publish/win-x64 && zip -r "../../MoYuCode-${{ steps.version.outputs.version }}-win-x64.zip" .)
- name: Create release
if: github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ github.token }}
RELEASE_NOTES: ${{ inputs.release_notes }}
shell: bash
run: |
set -euo pipefail
TAG="v${{ steps.version.outputs.version }}"
ASSETS=(
"artifacts/MoYuCode-${{ steps.version.outputs.version }}-linux-x64.tar.gz"
"artifacts/MoYuCode-${{ steps.version.outputs.version }}-osx-x64.tar.gz"
"artifacts/MoYuCode-${{ steps.version.outputs.version }}-win-x64.zip"
)
gh release create "${TAG}" "${ASSETS[@]}" --title "${TAG}" --notes "${RELEASE_NOTES}" --target "${GITHUB_SHA}"