-
Notifications
You must be signed in to change notification settings - Fork 32
113 lines (93 loc) · 3.76 KB
/
release.yml
File metadata and controls
113 lines (93 loc) · 3.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
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
name: Release
on:
release:
types: [released]
workflow_dispatch:
inputs:
dry_run:
description: 'Perform a dry run (skip actual NuGet publish)'
required: false
default: true
type: boolean
run-name: ${{ github.event_name == 'release' && format('Release {0}', github.event.release.tag_name) || (github.event.inputs.dry_run == 'false' && 'Release (Manual)' || 'Release (Dry Run)') }}
jobs:
build:
runs-on: windows-latest
permissions:
contents: write # For release asset upload
id-token: write # Required for OIDC token (NuGet Trusted Publishing)
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.x
10.x
- name: Set XrmMockup365 version from RELEASE_NOTES.md
shell: pwsh
run: ./scripts/Set-VersionFromChangelog.ps1 -ChangelogPath ./RELEASE_NOTES.md -CsprojPath ./src/XrmMockup365/XrmMockup365.csproj
- name: Set MetadataGenerator version from CHANGELOG.md
shell: pwsh
run: ./scripts/Set-VersionFromChangelog.ps1 -ChangelogPath ./src/MetadataGen/MetadataGenerator.Tool/CHANGELOG.md -PropsPath ./src/MetadataGen/Directory.Build.props
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Run tests
run: dotnet test --configuration Release --no-build --verbosity normal
- name: Pack XrmMockup365
run: dotnet pack src/XrmMockup365/XrmMockup365.csproj --configuration Release --no-build --output ./nupkg
- name: Pack MetadataGenerator.Tool
run: dotnet pack src/MetadataGen/MetadataGenerator.Tool/MetadataGenerator.Tool.csproj --configuration Release --no-build --output ./nupkg
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: packages
path: ./nupkg
- name: Add packages to release
uses: softprops/action-gh-release@v2
if: github.event_name == 'release'
with:
files: |
./nupkg/*.nupkg
./nupkg/*.snupkg
- name: Login to NuGet (OIDC)
id: nuget-login
uses: nuget/login@v1
with:
user: ${{ secrets.NUGET_USER }}
- name: Publish to NuGet
shell: pwsh
run: |
Write-Host "Looking for nupkg files..."
$nupkgFiles = Get-ChildItem -Path "./nupkg/*.nupkg" -File
if ($nupkgFiles.Count -eq 0) {
Write-Host "No nupkg files found in nupkg"
exit 1
}
Write-Host "Found $($nupkgFiles.Count) nupkg file(s):"
foreach ($file in $nupkgFiles) {
Write-Host " Full path: $($file.FullName)"
Write-Host " Size: $([math]::Round($file.Length / 1KB, 2)) KB"
}
# For automatic triggers (release events), always publish
# For manual triggers, only publish if dry_run is explicitly set to false
$isDryRun = "${{ github.event_name }}" -eq "workflow_dispatch" -and "${{ github.event.inputs.dry_run }}" -ne "false"
$apiKey = "${{ steps.nuget-login.outputs.NUGET_API_KEY }}"
if ($isDryRun) {
Write-Host "Dry run mode - skipping NuGet publish"
if ($apiKey -ne "") {
Write-Host "- Has NuGet API key from login"
} else {
Write-Host "- WARNING: Missing NuGet API key from login"
exit 1
}
} else {
Write-Host "Publishing to NuGet..."
foreach ($file in $nupkgFiles) {
Write-Host "Publishing: $($file.FullName)"
dotnet nuget push "$($file.FullName)" --api-key $apiKey --source "https://api.nuget.org/v3/index.json" --skip-duplicate
}
}