Skip to content

更新端口 更新代码逻辑 #9

更新端口 更新代码逻辑

更新端口 更新代码逻辑 #9

Workflow file for this run

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/OneCode/wwwroot
rsync -a --delete web/dist/ src/OneCode/wwwroot/
- name: Build backend
if: github.event_name != 'workflow_dispatch'
run: dotnet build src/OneCode/OneCode.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 win-x64 osx-x64; do
dotnet publish src/OneCode/OneCode.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
- 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 "OneCode is running at $ASPNETCORE_URLS"
echo "Open: http://localhost:9110"
if [[ -f "./OneCode" ]]; then
chmod +x "./OneCode"
./OneCode
else
dotnet "./OneCode.dll"
fi
EOF
chmod +x "artifacts/publish/linux-x64/run.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 "OneCode is running at $ASPNETCORE_URLS"
echo "Open: http://localhost:9110"
if [[ -f "./OneCode" ]]; then
chmod +x "./OneCode"
./OneCode
else
dotnet "./OneCode.dll"
fi
EOF
chmod +x "artifacts/publish/osx-x64/run.sh"
cat > "artifacts/publish/win-x64/OneCode.bat" <<'EOF'
@echo off
setlocal
cd /d "%~dp0"
set "DOTNET_ENVIRONMENT=Production"
set "ASPNETCORE_URLS=http://0.0.0.0:9110"
echo OneCode is running at %ASPNETCORE_URLS%
echo Open: http://localhost:9110
if exist "OneCode.exe" (
"OneCode.exe"
) else (
dotnet "OneCode.dll"
)
endlocal
EOF
cat > "artifacts/publish/win-x64/install-service.ps1" <<'EOF'
param(
[string]$ServiceName = "OneCode",
[string]$DisplayName = "OneCode",
[string]$Description = "OneCode service",
[string]$Urls = "http://0.0.0.0:9110"
)
$installDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$exePath = Join-Path $installDir "OneCode.exe"
if (-not (Test-Path $exePath)) {
$exePath = Join-Path $installDir "OneCode.dll"
if (-not (Test-Path $exePath)) {
Write-Error "OneCode executable not found in $installDir"
exit 1
}
$binaryPath = "dotnet `"$exePath`" --urls `"$Urls`""
} else {
$binaryPath = "`"$exePath`" --urls `"$Urls`""
}
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Error "Run this script as Administrator."
exit 1
}
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($null -eq $service) {
New-Service -Name $ServiceName -DisplayName $DisplayName -BinaryPathName $binaryPath -Description $Description -StartupType Automatic | Out-Null
} else {
sc.exe config $ServiceName binPath= "$binaryPath" start= auto | Out-Null
}
Start-Service -Name $ServiceName
$service = Get-Service -Name $ServiceName
Write-Host "Service status: $service.Status"
Write-Host "URL: $Urls"
Write-Host "Open: http://localhost:9110"
EOF
- name: Package release assets
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
set -euo pipefail
mkdir -p artifacts
tar -czf "artifacts/OneCode-${{ steps.version.outputs.version }}-linux-x64.tar.gz" -C artifacts/publish/linux-x64 .
tar -czf "artifacts/OneCode-${{ steps.version.outputs.version }}-osx-x64.tar.gz" -C artifacts/publish/osx-x64 .
(cd artifacts/publish/win-x64 && zip -r "../../OneCode-${{ 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/OneCode-${{ steps.version.outputs.version }}-linux-x64.tar.gz"
"artifacts/OneCode-${{ steps.version.outputs.version }}-osx-x64.tar.gz"
"artifacts/OneCode-${{ steps.version.outputs.version }}-win-x64.zip"
)
gh release create "${TAG}" "${ASSETS[@]}" --title "${TAG}" --notes "${RELEASE_NOTES}" --target "${GITHUB_SHA}"