78 lines
3.1 KiB
YAML
78 lines
3.1 KiB
YAML
name: ci
|
||
on:
|
||
push:
|
||
branches: [main, master]
|
||
pull_request:
|
||
|
||
jobs:
|
||
build-test:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
# 内网无 GitHub,不能用 actions/checkout@v4;手动 clone 本仓库(Gitea Actions 已注入 GITHUB_TOKEN)
|
||
- name: 拉取源码(内网手动 clone)
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
run: |
|
||
git clone --depth 1 --branch "$GITHUB_REF_NAME" "http://x-access-token:${GITHUB_TOKEN}@gitea.yunhaixingtong.com/${{ github.repository }}.git" /tmp/src
|
||
cp -a /tmp/src/. .
|
||
rm -rf /tmp/src
|
||
|
||
- name: 确认 dotnet SDK
|
||
run: |
|
||
if ! command -v dotnet >/dev/null 2>&1; then
|
||
echo "dotnet 不存在,安装 .NET 8 SDK..."
|
||
curl -sSL https://dot.net/v1/dotnet-install.sh -o /tmp/dotnet-install.sh
|
||
chmod +x /tmp/dotnet-install.sh
|
||
/tmp/dotnet-install.sh --channel 8.0 --install-dir /usr/share/dotnet
|
||
ln -s /usr/share/dotnet/dotnet /usr/local/bin/dotnet
|
||
fi
|
||
dotnet --version
|
||
|
||
- name: Restore
|
||
run: dotnet restore BasePlatformDotnet/yh-platform-net.sln
|
||
|
||
- name: Build
|
||
run: dotnet build BasePlatformDotnet/yh-platform-net.sln --no-restore -c Release
|
||
|
||
- name: Test
|
||
run: dotnet test BasePlatformDotnet/yh-platform-net.sln --no-build -c Release --logger "console;verbosity=normal"
|
||
|
||
- name: Pack
|
||
run: dotnet pack BasePlatformDotnet/yh-platform-net.sln --no-build -c Release -o BasePlatformDotnet/artifacts
|
||
|
||
publish:
|
||
# 仅主分支 push 时发版到 Nexus 私服(PR 不触发)
|
||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
|
||
needs: build-test
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: 拉取源码(无内网 GitHub)
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
run: |
|
||
git clone --depth 1 --branch "$GITHUB_REF_NAME" "http://x-access-token:${GITHUB_TOKEN}@gitea.yunhaixingtong.com/${{ github.repository }}.git" /tmp/src
|
||
cp -a /tmp/src/. .
|
||
rm -rf /tmp/src
|
||
|
||
- name: 确认 dotnet SDK
|
||
run: |
|
||
if ! command -v dotnet >/dev/null 2>&1; then
|
||
echo "dotnet 不存在,安装 .NET 8 SDK..."
|
||
curl -sSL https://dot.net/v1/dotnet-install.sh -o /tmp/dotnet-install.sh
|
||
chmod +x /tmp/dotnet-install.sh
|
||
/tmp/dotnet-install.sh --channel 8.0 --install-dir /usr/share/dotnet
|
||
ln -s /usr/share/dotnet/dotnet /usr/local/bin/dotnet
|
||
fi
|
||
dotnet --version
|
||
|
||
- name: Pack
|
||
run: dotnet pack BasePlatformDotnet/yh-platform-net.sln -c Release -o BasePlatformDotnet/artifacts
|
||
|
||
- name: Push to Nexus
|
||
# 委托独立脚本:生成带凭据 nuget.config(dotnet nuget push 不支持 --configfile)、
|
||
# 按 Disable redeploy 策略先查重再推送,凭据全部走 Gitea Secrets,不入 git。
|
||
env:
|
||
NEXUS_URL: ${{ secrets.NEXUS_URL }}
|
||
NEXUS_USER: ${{ secrets.NEXUS_USER }}
|
||
NEXUS_PASS: ${{ secrets.NEXUS_PASS }}
|
||
run: bash .gitea/scripts/push-to-nexus.sh |