Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0289c84

Browse files
committed
add multi .net sdk
1 parent baa5754 commit 0289c84

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- @azure Rule - Use Azure Best Practices: When generating code for Azure, running terminal commands for Azure, or performing operations related to Azure, invoke your `get_azure_best_practices` tool if available.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: myCSharp .NET setup and build workflow
2+
3+
# this workflow creates and publishes a NuGet package when a release is created
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
configuration:
9+
required: false
10+
type: string
11+
default: 'Release'
12+
description: 'The build configuration. Eg debug/release'
13+
dotnet-sdks:
14+
required: true
15+
type: string
16+
description: 'JSON array of .NET SDK versions to set up, e.g. ["6.0", "7.0", "8.0"]'
17+
secrets:
18+
NUGET_API_KEY:
19+
required: true
20+
21+
env:
22+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
33+
34+
- name: Setup Multiple .NET SDKs
35+
uses: actions/setup-dotnet@v4
36+
with:
37+
dotnet-version: ${{ fromJSON(inputs.dotnet-sdks) }}
38+
39+
- name: Restore dependencies
40+
run: dotnet restore
41+
42+
- name: Setup Git Versioning
43+
uses: dotnet/nbgv@master
44+
id: nbgv
45+
46+
- name: Show Version Info
47+
run: |
48+
echo 'SemVer2: ${{ steps.nbgv.outputs.SemVer2 }}'
49+
50+
- name: Build with dotnet
51+
run: dotnet build
52+
--no-restore --configuration ${{ inputs.configuration }}
53+
/p:Version=${{ steps.nbgv.outputs.AssemblyVersion }}
54+
55+
- name: Test with dotnet
56+
run: dotnet test
57+
--no-build --configuration ${{ inputs.configuration }}
58+
--logger "trx;LogFileName=test-results.trx" --results-directory ./artifacts/test-results
59+
continue-on-error: true
60+
61+
- name: Pack NuGet
62+
run: dotnet pack
63+
--configuration ${{ inputs.configuration }}
64+
--output ./artifacts/nuget-packages
65+
/p:ContinuousIntegrationBuild=true
66+
/p:Version=${{ steps.nbgv.outputs.NuGetPackageVersion }}
67+
68+
- name: Upload Artifacts
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: artifacts
72+
path: ./artifacts/**/*
73+
74+
# the deploy job runs only when the build job is successful and the event is a release
75+
deploy:
76+
if: github.event_name == 'release'
77+
name: Publish Package
78+
needs: build
79+
runs-on: ubuntu-latest
80+
steps:
81+
- name: Checkout code
82+
uses: actions/checkout@v4
83+
with:
84+
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
85+
86+
- name: Download build artifacts
87+
uses: actions/download-artifact@v4
88+
89+
- name: Upload release asset
90+
run: gh release upload ${{ github.event.release.tag_name }} ${{ github.workspace }}/artifacts/nuget-packages/*.*nupkg
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
94+
- name: Setup .NET SDK
95+
if: always()
96+
uses: actions/setup-dotnet@v4
97+
with:
98+
dotnet-version: ${{ fromJSON(inputs.dotnet-sdks) }}
99+
100+
- name: Publish package
101+
if: always()
102+
run: dotnet nuget push ${{github.workspace}}/artifacts/nuget-packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate

0 commit comments

Comments
 (0)