-
Notifications
You must be signed in to change notification settings - Fork 1
80 lines (72 loc) · 3.29 KB
/
main.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
name: Action to build and publish the project as a nuget package to github package registry
on:
push:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
outputs:
Version: ${{ steps.gitversion.outputs.SemVer }}
CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 #fetch-depth is needed for GitVersion
#Install and calculate the new version with GitVersion
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: 5.x
- name: Determine Version
uses: gittools/actions/gitversion/[email protected]
id: gitversion # step id used as reference for output values
- name: Display GitVersion outputs
run: |
echo "Version: ${{ steps.gitversion.outputs.SemVer }}"
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
#Build/pack the project
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x
- name: Build NuGet package
run: dotnet build AutoTestMate.MsTest.Infrastructure/AutoTestMate.MsTest.Infrastructure.csproj -p:Version='${{ steps.gitversion.outputs.SemVer }}' -c Release
- name: Pack NuGet package
run: dotnet pack AutoTestMate.MsTest.Infrastructure/AutoTestMate.MsTest.Infrastructure.csproj -p:Version='${{ steps.gitversion.outputs.SemVer }}' -c Release
- name: Upload NuGet package to GitHub
uses: actions/upload-artifact@v2
with:
name: nugetPackage
path: AutoTestMate.MsTest.Infrastructure/bin/Release/
release:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master' # only run job if on the master branch
steps:
#Push NuGet package to GitHub packages
- name: Download nuget package artifact
uses: actions/[email protected]
with:
name: nugetPackage
- name: Prep packages
run: dotnet nuget add source --username sportyturks --password ${{ secrets.NUGET_PACKAGE_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/sportyturks/index.json"
- name: Push package to GitHub packages
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change
run: dotnet nuget push nugetPackage/*.nupkg --api-key ${{ secrets.NUGET_PACKAGE_TOKEN }} --source "github"
#Create release
- name: Create Release
if: 1 == 0 #needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.NUGET_PACKAGE_TOKEN }}
with:
tag_name: ${{ needs.build.outputs.Version }}
release_name: Release ${{ needs.build.outputs.Version }}
- name: Create Release
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.build.outputs.Version }}
name: Release ${{ needs.build.outputs.Version }}
artifacts: "nugetPackage/*"
token: ${{ secrets.NUGET_PACKAGE_TOKEN }}