Repository navigation
90 lines (79 loc) · 3.08 KB
/
Copy pathpublish.yml
File metadata and controls
90 lines (79 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Publish
# 用 NuGet Trusted Publishing(OIDC)发布,不依赖长期 API Key。
# 首次使用前需在 nuget.org → Trusted Publishing 建立一条指向本仓库的 Policy:
# Repository Owner: Hub-code-develop
# Repository: InfinityUI
# Workflow File: publish.yml ← 只写文件名
# Environment: nuget
on:
# 主入口:在 GitHub 网页上「Publish release」即完成发版。
# GitHub 会自动建 tag、自动按 PR/commit 生成 release notes,版本号从 tag 取。
release:
types: [published]
# 兜底:Actions 里手动跑,可指定版本号(留空用 csproj 的 Version)。
workflow_dispatch:
inputs:
version:
description: "包版本(留空则用 csproj 里的 Version)"
required: false
type: string
permissions:
contents: read
id-token: write # Trusted Publishing 必需:换取 nuget.org 的短期 token
# 发版不并发、不被取消:中途取消会在 nuget.org 留下不完整状态
concurrency:
group: publish
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
# 这个 environment 名必须与 nuget.org Policy 里填的一致
environment: nuget
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
- name: Pack
shell: bash
run: |
set -euo pipefail
VERSION="${{ inputs.version }}"
# Release 触发时取 release 的 tag(GitHub 网页发版走这条)
if [ -z "$VERSION" ] && [ -n "${{ github.event.release.tag_name }}" ]; then
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
fi
# 老路径:直接 push tag
if [ -z "$VERSION" ] && [[ "${GITHUB_REF_NAME}" == v* ]]; then
VERSION="${GITHUB_REF_NAME#v}"
fi
if [ -n "$VERSION" ]; then
dotnet pack InfinityUI.csproj -c Release -o artifacts -p:Version="$VERSION"
else
dotnet pack InfinityUI.csproj -c Release -o artifacts
fi
ls -la artifacts
- name: 修正包归属(必须与 policy 的 Policy Owner 一致,否则 push 403)
run: python3 scripts/set_owner.py artifacts/*.nupkg CodeHub
- name: NuGet login (OIDC → 临时 API Key)
id: login
uses: NuGet/login@v1
with:
# nuget.org 用户名(Profile 里的 account name),配在仓库 Secrets 里
user: ${{ secrets.NUGET_USER }}
- name: Push to nuget.org
shell: bash
run: |
set -euo pipefail
dotnet nuget push artifacts/*.nupkg \
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
# 符号包
dotnet nuget push artifacts/*.snupkg \
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate || true