-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (83 loc) · 2.59 KB
/
build-and-publish.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
name: Build and Push Package
on:
push:
branches:
- main
- release/*
paths-ignore:
- '**.yml'
- 'CODEOWNERS'
- 'README.md'
- '.gitignore'
pull_request:
branches:
- main
- release/*
paths-ignore:
- 'CODEOWNERS'
- 'README.md'
- '.gitignore'
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Checkout all history for GitVersion to be able to calculate the version
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3
with:
versionSpec: '5.x'
- name: Determine Version
id: gitversion # id to later be referenced
uses: gittools/actions/gitversion/execute@v3
with:
useConfigFile: true
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --configuration Release --no-build
- name: Pack
run: dotnet pack --configuration Release /p:Version=${{ steps.gitversion.outputs.nuGetVersionV2 }}
- name: Upload package
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: '**/*.nupkg'
publish:
name: Publish Package
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name == 'push'
permissions:
packages: write
steps:
- name: Download package
uses: actions/download-artifact@v4
with:
name: nuget-package
path: ./packages
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Authenticate to GitHub Packages
run: dotnet nuget add source --username $GITHUB_REPOSITORY_OWNER --password ${API_KEY} --store-password-in-clear-text --name "github" "https://nuget.pkg.github.com/$GITHUB_REPOSITORY_OWNER/index.json"
env:
API_KEY: ${{ secrets.GITHUB_TOKEN }}
- name: Publish package to GitHub Packages
run: dotnet nuget push "**/*.nupkg" -k ${API_KEY} --source "github"
env:
API_KEY: ${{ secrets.GITHUB_TOKEN }}
- name: Publish package to NuGet
run: dotnet nuget push "**/*.nupkg" -k ${API_KEY} --source "https://api.nuget.org/v3/index.json"
env:
API_KEY: ${{ secrets.NUGET_TOKEN }}