一直很好奇那些在github中非常好的项目是怎么来发布Release的,恰巧最近有空
当然github actions的功能非常多,我也是刚入门的小白,本篇文件仅介绍如何使用actions来实现.net8 cli aot发布后直接publish到Release中
我就想在OpenWrt中非Docker运行.net aot程序就那么难吗!淦
实操 🔗
在github中创建一个存储库,然后同步拉取推送
在项目根目录中创建文件夹 .github/workflows,然后新建一个任意的yaml文件,如下所示
框架依赖时不能带入-p:PublishReadyToRun=true参数,否则会无法执行!
name: Release Compilation
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
runtime: linux-x64
- os: macos-latest
runtime: osx-x64
- os: windows-latest
runtime: win-x64
- os: windows-latest
runtime: win-arm64
- os: macos-latest
runtime: osx-arm64
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- name: Build AOT
run: |
dotnet publish -c Release -r ${{ matrix.runtime }} -p:PublishAot=true -o out/aot/${{ matrix.runtime }}
timeout-minutes: 10
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
- name: Build Self-contained
run: |
dotnet publish -c Release -r ${{ matrix.runtime }} -p:PublishSingleFile=true -p:SelfContained=true -p:PublishReadyToRun=true -o out/self-contained/${{ matrix.runtime }}
timeout-minutes: 10
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
- name: Build Framework-dependent
run: |
dotnet --version
dotnet publish -c Release -r ${{ matrix.runtime }} -p:PublishSingleFile=true -p:SelfContained=false -o out/framework-dependent/${{ matrix.runtime }}
timeout-minutes: 10
- name: Zip the build output
run: |
if ("${{ runner.os }}" -eq "Windows") {
Compress-Archive -Path "out/aot/${{ matrix.runtime }}/*" -DestinationPath "out/aot-${{ matrix.runtime }}.zip"
Compress-Archive -Path "out/self-contained/${{ matrix.runtime }}/*" -DestinationPath "out/selfcontained-${{ matrix.runtime }}.zip"
Compress-Archive -Path "out/framework-dependent/${{ matrix.runtime }}/*" -DestinationPath "out/framework-${{ matrix.runtime }}.zip"
} else {
zip -r "out/aot-${{ matrix.runtime }}.zip" "out/aot/${{ matrix.runtime }}"
zip -r "out/selfcontained-${{ matrix.runtime }}.zip" "out/self-contained/${{ matrix.runtime }}"
zip -r "out/framework-${{ matrix.runtime }}.zip" "out/framework-dependent/${{ matrix.runtime }}"
}
timeout-minutes: 5
shell: pwsh
- name: Upload
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
with:
files: |
out/*.zip
现在,已经配置可以将各个系统自动编译并发布二进制到Release中,分别为3种类型:aot/自包含/clr依赖
等等,到目前这一步还不足让其自动编译,请注意上述yaml文件中的on,必须符合指定的tag格式v*才可以
打开cmd输入如下指令
# 打开当前目录
cd xx
# 创建tag
git tag -a v1.0.0 -m "Release Version 1.0.0"
# 推送tag
git push origin v1.0.0
至此,已成艺术
当然这只是最原始的aot方法,如果非aot编译则可以对全平台支持,以下为.net 8可编译的目标平台
- win-x86
- win-x64
- win-arm
- win-arm64
- osx-x64
- osx-arm64
- linux-x64
- linux-arm
- linux-arm64
不考虑32bit,都2024年了谁还用32bit系统???
Armの硬伤 🔗
arm的aot暂时没法进行,因为.net目前不支持跨平台的交互编译(.net8)
并且.net开发团队对此进行了回复
Since there’s no standardized way to obtain native macOS SDK for use on Windows/Linux, or Windows SDK for use on Linux/macOS, or a Linux SDK for use on Windows/macOS, Native AOT does not support cross-OS compilation. Cross-OS compilation with Native AOT requires some form of emulation, like a virtual machine or Windows WSL.
结合上述回复,可以确定的是在可预见的未来.net应该不会支持跨平台编译了,请选择rust或go
并且github的actions运行时系统也并没有arm系统(不得不说还得是巨硬啊,这配置真豪华
以上种种,导致我暂时放弃了对arm原生aot的构建,在openwrt中还是用docker跑吧…