Repository navigation
70 lines (60 loc) · 2.53 KB
/
Copy pathpublish-package.yml
File metadata and controls
70 lines (60 loc) · 2.53 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
name: Publish to NuGet (Trusted Publishing)
# ⚠️ 仓库改名提醒:本仓库已从 CodeHub-develop/CodeHub-OreUI 迁移到
# Hub-code-develop/CodeHub-OreUI。GitHub OIDC 签发的 token 里 repository
# subject 会自动跟随新名,因此本 workflow 无需改动;但 nuget.org 上的
# Trusted Publisher(受信任发布)策略仍绑定旧仓库名,会导致 push 新 tag 时
# `NuGet login` 报 401 "No matching trust policy"。
# 修复方式(需在 nuget.org 网页操作,本仓库无法改):
# 包的 Manage → Trusted Publishers 里把策略的 Repository 改为
# `Hub-code-develop/CodeHub-OreUI`(NuGet 用户名须等于 secret NUGET_USER)。
# 改完后可对已有 tag 直接 `gh run rerun <run-id> --repo Hub-code-develop/CodeHub-OreUI`,
# 无需重新打 tag。
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Package version, e.g. 1.0.0 (ignored when pushed on a v* tag)'
required: true
default: '1.0.0'
# Top-level read-only by default; the publish job grants itself OIDC.
permissions:
contents: read
jobs:
publish:
name: Pack & Publish
runs-on: ubuntu-latest
permissions:
id-token: write # Required: lets GitHub issue an OIDC token for NuGet trusted publishing
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Resolve version
id: version
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
else
# Strip the leading 'v' from a tag like v1.0.0
echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
fi
- name: Restore
run: dotnet restore src/OreUI/OreUI.csproj
- name: Pack
run: dotnet pack src/OreUI/OreUI.csproj -c Release -p:Version=${{ steps.version.outputs.version }} -o ./artifacts
- name: NuGet login (OIDC -> short-lived API key)
uses: NuGet/login@v1
id: login
with:
# NuGet.org username (NOT your email). Store it as the NUGET_USER secret.
user: ${{ secrets.NUGET_USER }}
- name: Push to NuGet.org
run: dotnet nuget push "./artifacts/*.nupkg" --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate