Skip to content

优化ci

优化ci #3

Workflow file for this run

name: CI
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
run: dotnet build src/OneCode/OneCode.csproj -c Release -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }}
- 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 }}"
gh release create "${TAG}" --title "${TAG}" --notes "${RELEASE_NOTES}" --target "${GITHUB_SHA}"