Skip to content

增加多平台支持 #7

增加多平台支持

增加多平台支持 #7

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: 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}"