aspnet/action.yaml

114 lines
3.3 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: aspnet
description: ASP.NET 项目自动化编译、构建和发布插件
author: qxa
inputs:
project_name:
description: 要编译的项目名称(相对于工作目录的路径)
required: true
configuration:
description: 发布所对应的配置,默认值为 "Release"
required: false
default: Release
runtime:
description: 要发布的目标运行时,在创建自包含部署时使用
required: false
os:
description: 目标操作系统
required: false
publish:
description: 输出目录
required: false
default: publish
nuget_dir:
description: NuGet包还原地址如需缓存请挂载目录
required: false
default: /opt/hostedtoolcache/.nuget/packages
self_contained:
description: 是否创建自包含部署
required: false
default: false
runs:
using: composite
steps:
- name: 创建编译脚本
shell: bash
run: |
cat > entrypoint.sh << 'EOF'
#!/bin/bash
# 设置错误时退出
set -e
echo "===== ASP.NET 编译插件开始执行 ====="
echo "项目名称: $INPUT_PROJECT_NAME"
echo "配置: $INPUT_CONFIGURATION"
echo "输出目录: $INPUT_PUBLISH"
if [ "$INPUT_SELF_CONTAINED" = "true" ]; then
SELF_CONTAINED_OPTION="--self-contained"
else
SELF_CONTAINED_OPTION="--no-self-contained"
fi
option="$SELF_CONTAINED_OPTION -o $INPUT_PUBLISH -c $INPUT_CONFIGURATION"
if [ -n "$INPUT_RUNTIME" ]; then
option="$option -r $INPUT_RUNTIME"
echo "目标运行时: $INPUT_RUNTIME"
fi
if [ -n "$INPUT_OS" ]; then
option="$option --os $INPUT_OS"
echo "目标操作系统: $INPUT_OS"
fi
echo "发布选项: $option"
echo "NuGet包缓存目录: $INPUT_NUGET_DIR"
echo "\n===== 检查 .NET SDK 版本 ====="
dotnet --version
echo "\n===== 还原 NuGet 包 ====="
dotnet restore "$INPUT_PROJECT_NAME" --packages "$INPUT_NUGET_DIR"
echo "\n===== 构建项目 ====="
dotnet build "$INPUT_PROJECT_NAME" --packages "$INPUT_NUGET_DIR"
echo "\n===== 发布项目 ====="
dotnet publish $option "$INPUT_PROJECT_NAME" --packages "$INPUT_NUGET_DIR"
if [ -f "$INPUT_PUBLISH/obfuscar.xml" ]; then
echo "\n===== 检测到 obfuscar.xml开始代码混淆 ====="
echo "安装混淆工具..."
dotnet tool install -g obfuscar.globaltool
echo "执行代码混淆..."
cd $INPUT_PUBLISH
obfuscar.console obfuscar.xml
echo "代码混淆完成"
else
echo "\n未检测到 $INPUT_PUBLISH/obfuscar.xml跳过代码混淆"
fi
echo "\n===== ASP.NET 编译插件执行完成 ====="
EOF
chmod +x entrypoint.sh
- name: 在Docker中编译ASP.NET项目
uses: docker://dotnet/sdk:6.0
with:
entrypoint: ./entrypoint.sh
project_name: ${{ inputs.project_name }}
configuration: ${{ inputs.configuration }}
runtime: ${{ inputs.runtime }}
os: ${{ inputs.os }}
publish: ${{ inputs.publish }}
- name: 清理临时文件
shell: bash
run: |
rm -f entrypoint.sh
echo "临时文件已清理"