Skip to content

Commit 345f7c2

Browse files
Create dotnet.yml
1 parent 3cf3b3b commit 345f7c2

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build, Test, and Deploy
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
defaults:
10+
run:
11+
shell: pwsh
12+
13+
env:
14+
baseVersion: 1.0.0
15+
16+
jobs:
17+
build-and-test:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v2
23+
with:
24+
dotnet-version: 6.0.x
25+
- name: Restore dependencies
26+
run: dotnet restore
27+
- name: Set Version
28+
run: |
29+
if ("${{ github.ref }}".startsWith("refs/tags/v")) {
30+
$tagVersion = "${{ github.ref }}".substring(11)
31+
echo "buildVersion=$tagVersion.${{ github.run_number }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
32+
echo "nugetVersion=$tagVersion" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
33+
echo "preRelease=false" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
34+
} else {
35+
echo "buildVersion=${{ env.baseVersion }}.${{ github.run_number }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
36+
echo "nugetVersion=${{ env.baseVersion }}-ci${{ github.run_number }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
37+
}
38+
- name: Build
39+
run: dotnet build -p:Version=${{ env.buildVersion }} -p:ContinuousIntegrationBuild=True --no-restore --configuration Release
40+
- name: Test
41+
run: dotnet test --no-build --configuration Release --verbosity normal
42+
- name: Pack
43+
if: ("${{ github.ref }}".startsWith("refs/tags/v"))
44+
run: dotnet pack -p:PackageVersion=${{ env.nugetVersion }} --configuration Release -o ${{env.DOTNET_ROOT}}/TestTools.ConsolePack --no-build
45+
- name: Upload Artifacts
46+
if: ("${{ github.ref }}".startsWith("refs/tags/v"))
47+
uses: actions/upload-artifact@v2
48+
with:
49+
name: NuGet
50+
path: ${{env.DOTNET_ROOT}}/TestTools.ConsolePack
51+
52+
deploy:
53+
if: ("${{ github.ref }}".startsWith("refs/tags/v"))
54+
runs-on: ubuntu-latest
55+
needs: build-and-test
56+
environment:
57+
name: 'Production'
58+
steps:
59+
- name: Download artifact from build job
60+
uses: actions/download-artifact@v2
61+
with:
62+
name: NuGet
63+
- name: Push NuGet
64+
run: |
65+
$tagVersion = "${{ github.ref }}".substring(11)
66+
dotnet nuget push ${{ github.workspace }}/TestTools.ConsolePack/IntelliTect.TestTools.Console.$tagVersion.nupkg --source https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate

0 commit comments

Comments
 (0)