Skip to content

build: 补 NuGet 元数据与 GitHub Actions 发布工作流 #1

build: 补 NuGet 元数据与 GitHub Actions 发布工作流

build: 补 NuGet 元数据与 GitHub Actions 发布工作流 #1

Workflow file for this run

# 打标签 v* 时:构建 + 打包,通过 OIDC Trusted Publishing 推送到 nuget.org。
#
# 前置(一次性,浏览器操作):
# 1. 在 nuget.org 账户的 Manage packages → Trusted publishers 页面,
# 把本仓库注册为 trusted publisher,关联 OIDC document。
# 2. 在 GitHub 仓库 Settings → Secrets and variables → Actions → Variables
# 添加变量 NUGET_USER = 你的 nuget.org 用户名。
# (参考:https://learn.microsoft.com/en-us/nuget/quickstart/trusted-publishing)
name: publish-nuget
on:
push:
tags:
- "v*"
permissions:
id-token: write
contents: read
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Build
run: dotnet build StreamFrame.slnx -c Release
- name: Pack
run: |
dotnet pack src/StreamFrame/StreamFrame.csproj -c Release --no-build -o artifacts
dotnet pack src/StreamFrame.Protocols.Xml/StreamFrame.Protocols.Xml.csproj -c Release --no-build -o artifacts
- name: NuGet Login (OIDC)
id: login
uses: NuGet/login@v1
with:
user: ${{ vars.NUGET_USER }}
- name: Push to nuget.org
run: |
dotnet nuget push "artifacts/*.nupkg" \
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}" \
--source https://www.nuget.org/api/v2/package \
--skip-duplicate