|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [released] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + dry_run: |
| 9 | + description: 'Perform a dry run (skip actual NuGet publish)' |
| 10 | + required: false |
| 11 | + default: true |
| 12 | + type: boolean |
| 13 | + |
| 14 | +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)') }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + runs-on: windows-latest |
| 19 | + permissions: |
| 20 | + contents: write # For release asset upload |
| 21 | + id-token: write # Required for OIDC token (NuGet Trusted Publishing) |
| 22 | + steps: |
| 23 | + - name: Checkout code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Setup .NET |
| 27 | + uses: actions/setup-dotnet@v4 |
| 28 | + with: |
| 29 | + dotnet-version: | |
| 30 | + 8.x |
| 31 | + 10.x |
| 32 | +
|
| 33 | + - name: Set XrmMockup365 version from RELEASE_NOTES.md |
| 34 | + shell: pwsh |
| 35 | + run: ./scripts/Set-VersionFromChangelog.ps1 -ChangelogPath ./RELEASE_NOTES.md -CsprojPath ./src/XrmMockup365/XrmMockup365.csproj |
| 36 | + |
| 37 | + - name: Set MetadataGenerator.Tool version from CHANGELOG.md |
| 38 | + shell: pwsh |
| 39 | + run: ./scripts/Set-VersionFromChangelog.ps1 -ChangelogPath ./src/MetadataGen/MetadataGenerator.Tool/CHANGELOG.md -CsprojPath ./src/MetadataGen/MetadataGenerator.Tool/MetadataGenerator.Tool.csproj |
| 40 | + |
| 41 | + - name: Set MetadataGenerator.Core version from CHANGELOG.md |
| 42 | + shell: pwsh |
| 43 | + run: ./scripts/Set-VersionFromChangelog.ps1 -ChangelogPath ./src/MetadataGen/MetadataGenerator.Tool/CHANGELOG.md -CsprojPath ./src/MetadataGen/MetadataGenerator.Core/MetadataGenerator.Core.csproj |
| 44 | + |
| 45 | + - name: Set MetadataGenerator.Context version from CHANGELOG.md |
| 46 | + shell: pwsh |
| 47 | + run: ./scripts/Set-VersionFromChangelog.ps1 -ChangelogPath ./src/MetadataGen/MetadataGenerator.Tool/CHANGELOG.md -CsprojPath ./src/MetadataGen/MetadataGenerator.Context/MetadataGenerator.Context.csproj |
| 48 | + |
| 49 | + - name: Restore dependencies |
| 50 | + run: dotnet restore |
| 51 | + |
| 52 | + - name: Build |
| 53 | + run: dotnet build --configuration Release --no-restore |
| 54 | + |
| 55 | + - name: Run tests |
| 56 | + run: dotnet test --configuration Release --no-build --verbosity normal |
| 57 | + |
| 58 | + - name: Pack XrmMockup365 |
| 59 | + run: dotnet pack src/XrmMockup365/XrmMockup365.csproj --configuration Release --no-build --output ./nupkg |
| 60 | + |
| 61 | + - name: Pack MetadataGenerator.Tool |
| 62 | + run: dotnet pack src/MetadataGen/MetadataGenerator.Tool/MetadataGenerator.Tool.csproj --configuration Release --no-build --output ./nupkg |
| 63 | + |
| 64 | + - name: Upload artifacts |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: packages |
| 68 | + path: ./nupkg |
| 69 | + |
| 70 | + - name: Add packages to release |
| 71 | + uses: softprops/action-gh-release@v2 |
| 72 | + if: github.event_name == 'release' |
| 73 | + with: |
| 74 | + files: | |
| 75 | + ./nupkg/*.nupkg |
| 76 | + ./nupkg/*.snupkg |
| 77 | +
|
| 78 | + - name: Login to NuGet (OIDC) |
| 79 | + id: nuget-login |
| 80 | + uses: nuget/login@v1 |
| 81 | + with: |
| 82 | + user: ${{ secrets.NUGET_USER }} |
| 83 | + |
| 84 | + - name: Publish to NuGet |
| 85 | + shell: pwsh |
| 86 | + run: | |
| 87 | + Write-Host "Looking for nupkg files..." |
| 88 | + $nupkgFiles = Get-ChildItem -Path "./nupkg/*.nupkg" -File |
| 89 | +
|
| 90 | + if ($nupkgFiles.Count -eq 0) { |
| 91 | + Write-Host "No nupkg files found in nupkg" |
| 92 | + exit 1 |
| 93 | + } |
| 94 | +
|
| 95 | + Write-Host "Found $($nupkgFiles.Count) nupkg file(s):" |
| 96 | + foreach ($file in $nupkgFiles) { |
| 97 | + Write-Host " Full path: $($file.FullName)" |
| 98 | + Write-Host " Size: $([math]::Round($file.Length / 1KB, 2)) KB" |
| 99 | + } |
| 100 | +
|
| 101 | + # For automatic triggers (release events), always publish |
| 102 | + # For manual triggers, only publish if dry_run is explicitly set to false |
| 103 | + $isDryRun = "${{ github.event_name }}" -eq "workflow_dispatch" -and "${{ github.event.inputs.dry_run }}" -ne "false" |
| 104 | +
|
| 105 | + $apiKey = "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" |
| 106 | +
|
| 107 | + if ($isDryRun) { |
| 108 | + Write-Host "Dry run mode - skipping NuGet publish" |
| 109 | + if ($apiKey -ne "") { |
| 110 | + Write-Host "- Has NuGet API key from login" |
| 111 | + } else { |
| 112 | + Write-Host "- WARNING: Missing NuGet API key from login" |
| 113 | + exit 1 |
| 114 | + } |
| 115 | + } else { |
| 116 | + Write-Host "Publishing to NuGet..." |
| 117 | + foreach ($file in $nupkgFiles) { |
| 118 | + Write-Host "Publishing: $($file.FullName)" |
| 119 | + dotnet nuget push "$($file.FullName)" --api-key $apiKey --source "https://api.nuget.org/v3/index.json" --skip-duplicate |
| 120 | + } |
| 121 | + } |
0 commit comments