Skip to content

Commit d2f1e10

Browse files
authored
Merge pull request #1 from willysoft/ci/setup-nuget-release-pipeline
ci: add GitHub Actions workflow for automated releases
2 parents 583c580 + f8b7ad0 commit d2f1e10

File tree

8 files changed

+129
-3
lines changed

8 files changed

+129
-3
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: build-release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
# nuget
7+
nuget-push:
8+
description: "nuget-push: true = upload nuget package. false = not upload"
9+
required: false
10+
type: boolean
11+
default: true
12+
13+
jobs:
14+
test-dotnet:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 10
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-dotnet@v4
20+
# test
21+
- run: dotnet test -c Release
22+
23+
create-release:
24+
needs: [test-dotnet]
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 10
27+
outputs:
28+
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
29+
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
- name: Semantic Release
34+
uses: cycjimmy/semantic-release-action@v4
35+
id: semantic
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
39+
create-nuget-package:
40+
needs: [create-release]
41+
runs-on: ubuntu-latest
42+
timeout-minutes: 10
43+
if: needs.create-release.outputs.new_release_published == 'true'
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: actions/setup-dotnet@v4
47+
# build and pack
48+
- run: dotnet build -c Release -p:Version=${{ needs.create-release.outputs.new_release_version }}
49+
- run: dotnet pack -c Release --no-build -p:Version=${{ needs.create-release.outputs.new_release_version }} -o ./publish
50+
# Store artifacts.
51+
- uses: actions/upload-artifact@v4
52+
with:
53+
name: nuget
54+
path: ./publish/
55+
retention-days: 1
56+
57+
push-nuget-package:
58+
needs: [create-nuget-package]
59+
runs-on: ubuntu-latest
60+
timeout-minutes: 10
61+
if: needs.create-release.outputs.new_release_published == 'true'
62+
env:
63+
NUGET_PATH: |
64+
./*.nupkg
65+
./*.snupkg
66+
steps:
67+
- uses: actions/checkout@v4
68+
- uses: actions/setup-dotnet@v4
69+
70+
# Download(All) Artifacts to current directory
71+
- uses: actions/download-artifact@v4
72+
with:
73+
name: nuget
74+
- name: Show download aritifacts
75+
run: ls -lR
76+
- name: Validate package exists in artifact - NuGet
77+
run: |
78+
while read -r nuget_path; do
79+
if [[ "${nuget_path}" == "" ]]; then continue; fi
80+
# shellcheck disable=SC2086
81+
if ! ls -l ${nuget_path}; then
82+
echo "Specified nuget package not found. path: $nuget_path"
83+
if [[ "${nuget_path}" == *.nupkg ]]; then
84+
echo ".nupkg must be included in the artifact."
85+
exit 1
86+
fi
87+
fi
88+
done <<< "${NUGET_PATH}"
89+
90+
# Upload to NuGet
91+
- name: Upload to NuGet
92+
if: ${{ inputs.nuget-push }}
93+
run: |
94+
while read -r nuget_path; do
95+
if [[ "$nuget_path" == "" ]]; then continue; fi
96+
# shellcheck disable=SC2086
97+
if ! ls -l ${nuget_path} >/dev/null 2>&1;then
98+
echo "skipping nuget push, $nuget_path not found."
99+
continue
100+
fi
101+
102+
dotnet nuget push "${nuget_path}" --skip-duplicate -s https://api.nuget.org/v3/index.json -k "${NUGET_KEY}"
103+
done <<< "${NUGET_PATH}"
104+
env:
105+
NUGET_KEY: ${{ secrets.PS_NUGET_KEY }}

.releaserc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"plugins": [
3+
"@semantic-release/commit-analyzer",
4+
"@semantic-release/release-notes-generator",
5+
[
6+
"@semantic-release/github"
7+
]
8+
],
9+
"branches": [
10+
"main"
11+
]
12+
}

sample/AutoQueryApiDemo/AutoQueryApiDemo.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7+
<IsPackable>false</IsPackable>
78
</PropertyGroup>
89

910
<ItemGroup>

sample/AutoQueryDemo/AutoQueryDemo.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
<IsPackable>false</IsPackable>
89
</PropertyGroup>
910

1011
<ItemGroup>

src/AutoQuery.AspNetCore/AutoQuery.AspNetCore.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@
3636
<ItemGroup>
3737
<InternalsVisibleTo Include="AutoQuery.AspNetCore.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100bd24aa80c429bd4917c9458ea0a1ecb348b858c35422054e85391ed1f4c51c118662187ff2ceb0d32ba66769c91f1bbd38f4f06958dde60efbbd6c4e84cfdbf5dd1ab7c3ae567cc506a10635fee409390465d1a987248295314a896da6ba65bc5ea3247a766b096b1ddfcc68f28bbeccb1c095f0d7f4ae007f3415201a597197" />
3838
</ItemGroup>
39-
39+
40+
<ItemGroup>
41+
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
42+
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
43+
</ItemGroup>
44+
4045
</Project>

src/AutoQuery.AspNetCore/AutoQueryServiceExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static class AutoQueryServiceExtensions
1616
/// 向服務集合中添加查詢建構器服務。
1717
/// </summary>
1818
/// <param name="services">服務集合。</param>
19+
/// <param name="assembly">要應用配置的程序集。</param>
1920
/// <returns>更新後的服務集合。</returns>
2021
public static IServiceCollection AddAutoQuery(this IServiceCollection services, Assembly assembly)
2122
{

src/AutoQuery.AspNetCore/EnableFieldProjectionAttribute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ private static object FilterResult(object value, HashSet<string> selectedFields,
9999
/// <param name="value">要過濾的物件。</param>
100100
/// <param name="selectedFields">選擇的字段集合。</param>
101101
/// <param name="serializerOptions">JSON 序列化選項。</param>
102+
/// <param name="firstLevelOnly">是否僅過濾第一層屬性。</param>
102103
/// <returns>過濾後的字典。</returns>
103104
private static Dictionary<string, object?> FilterObject(object value, HashSet<string> selectedFields, JsonSerializerOptions serializerOptions, bool firstLevelOnly = false)
104105
{

test/AutoQuery.Tests/QueryProcessorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ public class TestQueryOptions : IQueryOptions
121121

122122
public class TestData
123123
{
124-
public string Name { get; set; }
124+
public string Name { get; set; } = null!;
125125
public int Age { get; set; }
126-
public string Address { get; set; }
126+
public string Address { get; set; } = null!;
127127
}
128128

129129
public class UserQueryConfiguration : IFilterQueryConfiguration<TestQueryOptions, TestData>

0 commit comments

Comments
 (0)