Skip to content

Commit 48e9ca2

Browse files
committed
ci: add automated NuGet publishing
1 parent b57b0f9 commit 48e9ca2

File tree

3 files changed

+134
-5
lines changed

3 files changed

+134
-5
lines changed

.github/workflows/publish.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Publish NuGet Package
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
packages: write
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: 10.0.x
25+
26+
- name: Resolve package version
27+
id: version
28+
shell: bash
29+
run: |
30+
if [[ "${{ github.event_name }}" == "release" ]]; then
31+
TAG_NAME="${{ github.event.release.tag_name }}"
32+
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
33+
TAG_NAME="${{ github.ref_name }}"
34+
else
35+
echo "workflow_dispatch must be run from a tag ref such as v1.0.4." >&2
36+
exit 1
37+
fi
38+
39+
PACKAGE_VERSION="${TAG_NAME#v}"
40+
41+
if [[ -z "${PACKAGE_VERSION}" ]]; then
42+
echo "Package version could not be resolved from the release tag." >&2
43+
exit 1
44+
fi
45+
46+
echo "tag_name=${TAG_NAME}" >> "${GITHUB_OUTPUT}"
47+
echo "package_version=${PACKAGE_VERSION}" >> "${GITHUB_OUTPUT}"
48+
49+
- name: Restore
50+
run: dotnet restore YCode.CLI/YCode.CLI.csproj
51+
52+
- name: Pack
53+
run: >
54+
dotnet pack YCode.CLI/YCode.CLI.csproj
55+
--configuration Release
56+
--no-restore
57+
-p:ContinuousIntegrationBuild=true
58+
-p:PackageVersion=${{ steps.version.outputs.package_version }}
59+
--output ${{ github.workspace }}/artifacts
60+
61+
- name: Publish to NuGet.org
62+
shell: bash
63+
run: |
64+
shopt -s nullglob
65+
packages=("${{ github.workspace }}/artifacts/"*.nupkg)
66+
67+
if (( ${#packages[@]} == 0 )); then
68+
echo "No .nupkg files were generated." >&2
69+
exit 1
70+
fi
71+
72+
dotnet nuget push "${packages[@]}" \
73+
--api-key "${{ secrets.NUGET_API_KEY }}" \
74+
--source "https://api.nuget.org/v3/index.json" \
75+
--skip-duplicate
76+
77+
- name: Configure GitHub Packages source
78+
run: >
79+
dotnet nuget add source
80+
--username "${{ github.repository_owner }}"
81+
--password "${{ secrets.GITHUB_TOKEN }}"
82+
--store-password-in-clear-text
83+
--name github
84+
"https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
85+
86+
- name: Publish to GitHub Packages
87+
shell: bash
88+
run: |
89+
shopt -s nullglob
90+
packages=("${{ github.workspace }}/artifacts/"*.nupkg)
91+
92+
dotnet nuget push "${packages[@]}" \
93+
--source github \
94+
--api-key "${{ secrets.GITHUB_TOKEN }}" \
95+
--skip-duplicate
96+
97+
- name: Upload package to GitHub Release
98+
env:
99+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
shell: bash
101+
run: |
102+
shopt -s nullglob
103+
packages=("${{ github.workspace }}/artifacts/"*.nupkg)
104+
105+
gh release upload "${{ steps.version.outputs.tag_name }}" "${packages[@]}" --clobber

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
# 运行(本地调试)
1818
dotnet run --project YCode.CLI\YCode.CLI.csproj
19+
20+
# 作为全局工具安装(NuGet 发布后)
21+
dotnet tool install --global YCode.CLI
1922
```
2023

2124
## 配置
@@ -69,13 +72,24 @@ flowchart TD
6972
- **扩展功能**:基于项目实现更多代理类型或技能
7073
- **改进文档**:帮助完善使用说明和示例
7174

75+
## 发布流程
76+
仓库已配置 GitHub Actions 自动发布:
77+
78+
- 在 GitHub 创建一个 `Release`,tag 使用 `v1.0.4` 这类语义化版本格式
79+
- Workflow 会自动执行 `dotnet pack`
80+
- 生成的 `.nupkg` 会推送到 `nuget.org`
81+
- 同一个包也会推送到 GitHub Packages
82+
- 包文件会作为资产上传到对应的 GitHub Release
83+
84+
Workflow 默认读取仓库里的 `NUGET_API_KEY` secret。
85+
7286
## 参考资源
7387
- [Microsoft Agents AI 文档](https://learn.microsoft.com/en-us/dotnet/agents/)
7488
- [MCP 协议规范](https://spec.modelcontextprotocol.io/)
7589
- [Kode 项目](https://github.com/shareAI-lab/Kode) (Python实现的参考)
7690

7791
## Star History
78-
[![Star History Chart](https://api.star-history.com/svg?repos=lyq-lin/YCode.CLI&type=Date)](https://star-history.com/#lyq-lin/YCode.CLI&Date)
92+
[![Star History Chart](https://api.star-history.com/svg?repos=ycode-lin/YCode.CLI&type=Date)](https://star-history.com/#ycode-lin/YCode.CLI&Date)
7993

8094
## 许可证
8195
MIT License

YCode.CLI/YCode.CLI.csproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@
55
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
<IsPackable>true</IsPackable>
89

910
<!-- 全局工具必备配置 -->
1011
<PackAsTool>true</PackAsTool>
1112
<ToolCommandName>ycode</ToolCommandName>
12-
<!-- 全局使用的命令名 -->
13-
<PackageOutputPath>./nupkg</PackageOutputPath>
14-
<!-- 可选:NuGet包输出目录 -->
13+
<PackageId>YCode.CLI</PackageId>
14+
<Version>1.0.4</Version>
15+
<Authors>lyq-lin</Authors>
16+
<Description>YCode is an AI-powered coding agent that operates inside your repository. It provides intelligent code assistance, file operations, and multi-step task management.</Description>
17+
<PackageTags>ai;coding-agent;cli;dotnet-tool;developer-tools</PackageTags>
18+
<PackageReadmeFile>README.md</PackageReadmeFile>
19+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
20+
<PackageProjectUrl>https://github.com/ycode-lin/YCode.CLI</PackageProjectUrl>
21+
<RepositoryUrl>https://github.com/ycode-lin/YCode.CLI</RepositoryUrl>
22+
<RepositoryType>git</RepositoryType>
23+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
24+
<PackageOutputPath>$(MSBuildThisFileDirectory)nupkg</PackageOutputPath>
1525
</PropertyGroup>
1626

1727
<ItemGroup>
@@ -24,7 +34,7 @@
2434
</ItemGroup>
2535

2636
<ItemGroup>
27-
<Folder Include="nupkg\" />
37+
<None Include="../README.md" Pack="true" PackagePath="\" />
2838
</ItemGroup>
2939

3040
</Project>

0 commit comments

Comments
 (0)