|
1 | 1 | open System |
| 2 | +open System.Xml |
2 | 3 | open Fake.Core |
3 | 4 | open Fake.DotNet |
4 | 5 | open Fake.Tools |
@@ -190,6 +191,60 @@ module DocsTool = |
190 | 191 | let result = Fornax.watch (fun p -> { p with WorkingDirectory = Some docsDir }) |
191 | 192 | result |> ignore |
192 | 193 |
|
| 194 | +module NuGetConfig = |
| 195 | + /// <summary> |
| 196 | + /// Add GitHub package source to NuGet configuration |
| 197 | + /// </summary> |
| 198 | + let addGitHubSource () = |
| 199 | + let result = |
| 200 | + DotNet.exec id "nuget" "add source --name \"github.com\" \"https://nuget.pkg.github.com/fsprojects/index.json\"" |
| 201 | + |
| 202 | + if not result.OK then |
| 203 | + Trace.logf "Warning: Failed to add GitHub source: %A" result.Errors |
| 204 | + |
| 205 | + /// <summary> |
| 206 | + /// Ensure NuGet package source mapping configuration |
| 207 | + /// </summary> |
| 208 | + let ensurePackageSourceMapping () = |
| 209 | + let homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) |
| 210 | + let nugetConfigPath = homeDir </> ".nuget" </> "NuGet" </> "NuGet.Config" |
| 211 | + |
| 212 | + try |
| 213 | + if IO.File.Exists nugetConfigPath then |
| 214 | + let doc = XmlDocument() |
| 215 | + doc.Load(nugetConfigPath) |
| 216 | + |
| 217 | + let configNode = doc.SelectSingleNode("//configuration") |
| 218 | + if configNode <> null then |
| 219 | + // Remove existing packageSourceMapping if it exists |
| 220 | + let existingMapping = configNode.SelectSingleNode("packageSourceMapping") |
| 221 | + if existingMapping <> null then |
| 222 | + configNode.RemoveChild(existingMapping) |> ignore |
| 223 | + |
| 224 | + // Create new packageSourceMapping element |
| 225 | + let packageSourceMapping = doc.CreateElement("packageSourceMapping") |
| 226 | + |
| 227 | + // Create nuget.org source mapping |
| 228 | + let nugetSource = doc.CreateElement("packageSource") |
| 229 | + nugetSource.SetAttribute("key", "nuget.org") |
| 230 | + |
| 231 | + let nugetPattern = doc.CreateElement("package") |
| 232 | + nugetPattern.SetAttribute("pattern", "*") |
| 233 | + |
| 234 | + nugetSource.AppendChild(nugetPattern) |> ignore |
| 235 | + packageSourceMapping.AppendChild(nugetSource) |> ignore |
| 236 | + configNode.AppendChild(packageSourceMapping) |> ignore |
| 237 | + |
| 238 | + doc.Save(nugetConfigPath) |
| 239 | + Trace.log "Successfully updated NuGet package source mapping" |
| 240 | + else |
| 241 | + Trace.logf "Warning: Could not find configuration node in %s" nugetConfigPath |
| 242 | + else |
| 243 | + Trace.logf "Warning: NuGet config file not found at %s" nugetConfigPath |
| 244 | + with |
| 245 | + | ex -> |
| 246 | + Trace.logf "Warning: Failed to update NuGet package source mapping: %s" ex.Message |
| 247 | + |
193 | 248 | let allReleaseChecks () = failOnWrongBranch () |
194 | 249 | //Changelog.failOnEmptyChangelog latestEntry |
195 | 250 |
|
@@ -567,6 +622,11 @@ let watchDocs ctx = |
567 | 622 | let configuration = configuration (ctx.Context.AllExecutingTargets) |
568 | 623 | DocsTool.watch (string configuration) |
569 | 624 |
|
| 625 | +let configureNuGetForGitHub _ = |
| 626 | + Trace.log "Configuring NuGet for GitHub package publishing..." |
| 627 | + NuGetConfig.addGitHubSource () |
| 628 | + NuGetConfig.ensurePackageSourceMapping () |
| 629 | + |
570 | 630 | let selfCheck _ = |
571 | 631 | let srcDir = rootDirectory </> "src" |
572 | 632 | let consoleProj = srcDir </> "FSharpLint.Console" |
@@ -607,6 +667,7 @@ let initTargets (ctx : Context.FakeExecutionContext) = |
607 | 667 | Target.create "Clean" clean |
608 | 668 | Target.create "DotnetRestore" dotnetRestore |
609 | 669 | Target.create "DotnetToolRestore" dotnetToolRestore |
| 670 | + Target.create "ConfigureNuGetForGitHub" configureNuGetForGitHub |
610 | 671 | Target.create "UpdateChangelog" updateChangelog |
611 | 672 | Target.createBuildFailure "RevertChangelog" revertChangelog // Do NOT put this in the dependency chain |
612 | 673 | Target.createFinal "DeleteChangelogBackupFile" deleteChangelogBackupFile // Do NOT put this in the dependency chain |
@@ -676,6 +737,7 @@ let initTargets (ctx : Context.FakeExecutionContext) = |
676 | 737 | "DotnetRestore" |
677 | 738 | =?> ("CheckFormatCode", isCI.Value) |
678 | 739 | =?> ("GenerateAssemblyInfo", isPublishToGitHub) |
| 740 | + =?> ("ConfigureNuGetForGitHub", isPublishToGitHub && isCI.Value && githubToken.IsSome) |
679 | 741 | ==> "DotnetBuild" |
680 | 742 | ==> "DotnetTest" |
681 | 743 | ==> "DotnetPack" |
|
0 commit comments