-
-
Notifications
You must be signed in to change notification settings - Fork 59
139 lines (118 loc) · 5.28 KB
/
NuGetCD.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
name: NuGetCD
on:
push:
branches: [ master ]
paths:
- '**.cs'
- '**.csproj'
workflow_dispatch:
inputs:
force_release:
description: 'Force publishing a new NuGet package version (even if the underlying SF version did not change)'
required: false
default: false
type: boolean
jobs:
prepare:
name: FetchAndTag
runs-on: windows-latest
env:
Test_Project_File: \test\ServiceFabric.Mocks.NetCoreTests\ServiceFabric.Mocks.NetCoreTests.csproj
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# Echo context
- name: Echo context
shell: pwsh
run: |
$branch_name = $env:GITHUB_REF -replace 'refs/heads/', ''
Write-Host "Last merged branch: $branch_name"
# Check for SF updates before creating a new release
- name: Check for SF NuGet Package Version Change
id: check_version
shell: pwsh
run: |
# Specify the package you want to check
$PACKAGE_NAME="Microsoft.ServiceFabric.Actors"
$csprojPath = "./src/ServiceFabric.Mocks/ServiceFabric.Mocks.csproj"
# Get the diff and check for the package reference
$diff = git diff HEAD~1 -- $csprojPath
if ($diff -match "<PackageReference Include=`"$PACKAGE_NAME`"") {
Write-Host "SF Package version has changed."
echo "sf_ver_changed=true" >> $env:GITHUB_OUTPUT
} else {
Write-Host "No changes to SF package version."
echo "sf_ver_changed=false" >> $env:GITHUB_OUTPUT
}
# Run echo
- name: Echo status
if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' || github.event.inputs.force_release == 'true' }}
run: echo "This run will create a new release on GitHub and Nuget"
- name: Echo status
if: ${{ steps.check_version.outputs.sf_ver_changed == 'false' }}
run: echo "This run will NOT create a new release on GitHub and Nuget"
# create version
- name: Bump version and push tag
id: tag_version
uses: loekd/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
dry_run: ${{ steps.check_version.outputs.sf_ver_changed == 'false' && github.event.inputs.force_release == 'false' }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
# Install SF SDK
- name: Install SF
shell: pwsh
run: |
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force -Scope CurrentUser
$ProgressPreference = 'SilentlyContinue'
Invoke-RestMethod -OutFile setup.exe -Method GET -Uri https://download.microsoft.com/download/b/8/a/b8a2fb98-0ec1-41e5-be98-9d8b5abf7856/MicrosoftServiceFabric.10.1.2338.9590.exe
#.\setup.exe /accepteula /force /quiet
Start-Process setup.exe -UseNewEnvironment -ArgumentList '/accepteula /force /quiet' -Wait
# Create SNK
- name: Create SNK
shell: pwsh
run: |
.\ExtractPrivateKey.ps1 "${{ secrets.Pfx_Key }}"
# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test --logger "trx;LogFileName=results.trx" ${Test_Project_File}
#Publish test results
- name: Publish Test Results
uses: loekd/publish-unit-test-result-action/composite@v2
if: always()
with:
trx_files: "**/*.trx"
# Run dotnet release build
- name: Run build
run: dotnet build --configuration RELEASE -p:PackageVersion=${{ steps.tag_version.outputs.new_version }}
# Run dotnet release pack
- name: Run pack
run: dotnet pack --configuration RELEASE -p:PackageVersion=${{ steps.tag_version.outputs.new_version }} -o ${{ github.workspace }}
# create GH release
- name: Create a GitHub release
if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' || github.event.inputs.force_release == 'true' }}
uses: loekd/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
# publish nuget package artifact
- name: Upload Package for Publishing
if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' || github.event.inputs.force_release == 'true' }}
uses: actions/upload-artifact@v4
with:
name: PackedLib
path: ${{ github.workspace }}/ServiceFabric.Mocks.${{ steps.tag_version.outputs.new_version }}.nupkg
# publish GH nuget package artifact
- name: Push Package to GitHub
if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' || github.event.inputs.force_release == 'true' }}
run: dotnet nuget push --api-key ${{secrets.GITHUB_TOKEN}} --source "https://nuget.pkg.github.com/loekd/index.json" ${{ github.workspace }}/ServiceFabric.Mocks.${{ steps.tag_version.outputs.new_version }}.nupkg
# publish packge to nuget
- name: Push Package to GitHub
if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' || github.event.inputs.force_release == 'true' }}
run: dotnet nuget push --api-key ${{secrets.NUGETPUSH}} --source "https://api.nuget.org/v3/index.json" ${{ github.workspace }}/ServiceFabric.Mocks.${{ steps.tag_version.outputs.new_version }}.nupkg