-
Notifications
You must be signed in to change notification settings - Fork 41
88 lines (72 loc) · 2.76 KB
/
build.yml
File metadata and controls
88 lines (72 loc) · 2.76 KB
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
name: Build and Deploy
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
DOTNET_VERSION: '8.0.x'
CONFIGURATION: Release
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for Source Link
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore
- name: Test
run: dotnet test --configuration ${{ env.CONFIGURATION }} --no-build --verbosity normal --filter "TestCategory=AppVeyor"
- name: Pack NuGet packages
run: dotnet pack src/AdysTech.CredentialManager/AdysTech.CredentialManager.csproj --configuration ${{ env.CONFIGURATION }} --no-build --output ./artifacts
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ./artifacts/*.nupkg
- name: Upload symbol packages
uses: actions/upload-artifact@v4
with:
name: symbol-packages
path: ./artifacts/*.snupkg
- name: Publish to NuGet
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
shell: pwsh
run: |
$packages = Get-ChildItem -Path ./artifacts -Filter *.nupkg
foreach ($package in $packages) {
dotnet nuget push $package.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
- name: Extract version and create tag
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
shell: pwsh
run: |
# Extract version from csproj
[xml]$csproj = Get-Content src/AdysTech.CredentialManager/AdysTech.CredentialManager.csproj
$version = $csproj.Project.PropertyGroup.Version | Select-Object -First 1
$tagName = "v$version"
Write-Host "Package version: $version"
Write-Host "Tag name: $tagName"
# Check if tag already exists
git fetch --tags
$tagExists = git tag -l $tagName
if ($tagExists) {
Write-Host "Tag $tagName already exists, skipping tag creation"
} else {
Write-Host "Creating new tag: $tagName"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a $tagName -m "Release $version"
git push origin $tagName
Write-Host "Tag $tagName created and pushed"
}