-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (104 loc) · 3.61 KB
/
release.yml
File metadata and controls
130 lines (104 loc) · 3.61 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Release
on:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration Release --no-restore --verbosity normal
- name: Run tests
run: dotnet test --configuration Release --no-build --verbosity normal
pack-and-publish:
name: Pack and Publish to NuGet
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration Release --no-restore
- name: Get version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Pack Mud.ServiceCodeGenerator
run: dotnet pack Core/Mud.ServiceCodeGenerator/Mud.ServiceCodeGenerator.csproj --configuration Release --no-build --output ./nupkgs -p:PackageVersion=${{ steps.get_version.outputs.VERSION }}
- name: Pack Mud.EntityCodeGenerator
run: dotnet pack Core/Mud.EntityCodeGenerator/Mud.EntityCodeGenerator.csproj --configuration Release --no-build --output ./nupkgs -p:PackageVersion=${{ steps.get_version.outputs.VERSION }}
- name: Publish to NuGet
run: dotnet nuget push ./nupkgs/*.nupkg --api-key ${{ secrets.MUDCODEGENERATOR }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Upload NuGet packages
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ./nupkgs/*.nupkg
create-release:
name: Create GitHub Release
needs: pack-and-publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download NuGet packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: ./nupkgs
- name: Generate changelog
id: changelog
run: |
# 获取上一个 tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
# 如果没有上一个 tag,获取所有提交
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
# 获取两个 tag 之间的提交
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges $PREVIOUS_TAG..HEAD)
fi
# 保存 changelog 到文件
echo "## 变更内容" > CHANGELOG.md
echo "" >> CHANGELOG.md
echo "$COMMITS" >> CHANGELOG.md
# 设置多行输出
{
echo 'CHANGELOG<<EOF'
cat CHANGELOG.md
echo 'EOF'
} >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: ./nupkgs/*.nupkg
body: ${{ steps.changelog.outputs.CHANGELOG }}
draft: false
prerelease: ${{ contains(steps.get_version.outputs.VERSION, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}