-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (113 loc) · 3.82 KB
/
build-and-release.yml
File metadata and controls
134 lines (113 loc) · 3.82 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
131
132
133
134
name: Build and Release NuGet Package
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
GLOBAL_JSON_PATH: './src/global.json'
PROJECT_PATH: './src/dotnet.library.sln'
PACKAGE_OUTPUT_DIRECTORY: './packages'
TEST_OUTPUT_DIRECTORY: './testresults'
permissions:
contents: write
jobs:
build:
permissions:
contents: read
# For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-latest
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v5
with:
global-json-file: ${{ env.GLOBAL_JSON_PATH }}
- name: Restore tools
run: dotnet tool restore
- name: Run Slopwatch
run: dotnet tool run slopwatch analyze --fail-on error
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v1.1.1
with:
versionSpec: '5.x'
- name: Determine Version
uses: gittools/actions/gitversion/execute@v1.1.1
id: gitversion
- name: Display GitVersion outputs
run: |
echo "Release Version: ${{ steps.gitversion.outputs.majorMinorPatch }}"
echo "Nuget Version: ${{ steps.gitversion.outputs.fullSemVer }}"
- name: Restore dependencies
run: dotnet restore ${{ env.PROJECT_PATH }}
- name: Build
run: >
dotnet build
--configuration Release
--no-restore
${{ env.PROJECT_PATH }}
/p:Version=${{ steps.gitversion.outputs.semVer }}
- name: Run tests
run: >
dotnet test
--configuration Release
--no-build
--collect:"XPlat Code Coverage;Format=opencover"
--logger trx
--results-directory ${{ env.TEST_OUTPUT_DIRECTORY }}
--verbosity normal
${{ env.PROJECT_PATH }}
- name: Create NuGet package
run: >
dotnet pack
--configuration Release
--no-build
--output ${{ env.PACKAGE_OUTPUT_DIRECTORY }}
${{ env.PROJECT_PATH }}
/p:PackageVersion=${{ steps.gitversion.outputs.semVer }}
- name: Upload package artifacts
uses: actions/upload-artifact@v6
with:
name: nuget-packages
path: ${{ env.PACKAGE_OUTPUT_DIRECTORY }}/*.nupkg
publish:
permissions:
contents: write
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && false
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Download package artifacts
uses: actions/download-artifact@v7
with:
name: nuget-packages
path: ${{ env.PACKAGE_OUTPUT_DIRECTORY }}
- name: Setup .NET Core
uses: actions/setup-dotnet@v5
with:
global-json-file: ${{ env.GLOBAL_JSON_PATH }}
- name: Publish to NuGet
run: |
dotnet nuget push --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate ${{ env.PACKAGE_OUTPUT_DIRECTORY }}/*.nupkg
- name: Create & Publish Release
uses: softprops/action-gh-release@v2
with:
tag_name: "v${{ needs.build.outputs.semVer }}"
target_commitish: ${{ github.sha }}
name: "v${{ needs.build.outputs.semVer }}"
generate_release_notes: true
draft: false
prerelease: false
make_latest: true
files: ${{ env.PACKAGE_OUTPUT_DIRECTORY }}/*.nupkg