-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (123 loc) · 3.74 KB
/
ci-cd.yml
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
131
132
133
134
135
136
137
138
139
140
141
142
143
name: CI/CD Workflow
on:
push:
branches:
- main
tags:
- '*'
pull_request:
env:
PROJECTS_TO_BUILD: |
src/WHyLL/WHyLL.csproj
src/WHyLL.AspNet/WHyLL.AspNet.csproj
src/WHyLL.Http/WHyLL.Http.csproj
tests/Test.WHyLL/Test.WHyLL.csproj
tests/Test.WHyLL.AspNet/Test.WHyLL.AspNet.csproj
tests/Test.WHyLL.Http/Test.WHyLL.Http.csproj
jobs:
build-and-test:
name: Build and Test
runs-on: windows-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.x'
- name: Restore Dependencies
run: |
for project in $PROJECTS_TO_BUILD; do
echo "Restoring dependencies for $project"
dotnet restore "$project"
done
shell: bash
- name: Build Projects
run: |
for project in $PROJECTS_TO_BUILD; do
echo "Building $project"
dotnet build "$project" --no-restore --configuration Release
done
shell: bash
- name: Run Tests
run: |
for project in $PROJECTS_TO_BUILD; do
if [[ $project == *"TEST"* ]]; then
echo "Running tests for $project"
dotnet test "$project" --no-build --verbosity normal --configuration Release
fi
done
shell: bash
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Current Tag
shell: bash
run: |
CURRENT_TAG=$(git describe --tags --abbrev=0)
echo "CURRENT_TAG=$CURRENT_TAG" >> $GITHUB_ENV
- name: Debug Current Tag
shell: bash
run: |
echo "Current Tag: $CURRENT_TAG"
- name: Restore Dependencies
run: |
for project in $PROJECTS_TO_BUILD; do
echo "Restoring dependencies for $project"
dotnet restore "$project"
done
shell: bash
- name: Pack NuGet Package
run: |
for project in $PROJECTS_TO_BUILD; do
if [[ $project != *"TEST"* ]]; then
echo "Packing $(basename "$project" .csproj) from $project with version $CURRENT_TAG"
dotnet pack "$project" --configuration Release --output "./artifacts" -p:PackageVersion=$CURRENT_TAG
fi
done
shell: bash
env:
CURRENT_TAG: ${{ env.CURRENT_TAG }}
- name: Log Files Before Upload
shell: pwsh
run: |
echo "Files ready for upload:"
Get-ChildItem -Path .\artifacts\ -File
- name: Upload NuGet Package
uses: actions/upload-artifact@v3
with:
name: nuget-package
path: ./artifacts/*.nupkg
publish:
name: Publish to NuGet
runs-on: windows-latest
needs: build-and-test
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Download NuGet Package
uses: actions/download-artifact@v3
with:
name: nuget-package
path: ./
- name: Log Downloaded Artifacts
shell: pwsh
run: |
echo "Downloaded artifacts:"
Get-ChildItem -Path .\ -File
- name: Publish to NuGet
shell: bash
run: |
for nupkg in ./*.nupkg; do
if [ -f "$nupkg" ]; then
echo "Found nupkg file: $nupkg"
echo "Publishing $nupkg"
dotnet nuget push "$nupkg" \
-k ${{ secrets.NUGET_API_KEY }} \
-s https://api.nuget.org/v3/index.json
else
echo "No .nupkg files found in the directory."
fi
done