diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index d91a39c..d89252c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -80,4 +80,4 @@ jobs: Build__TestProjects: ${{ matrix.project }} Build__RunLint: "false" Build__RunPack: "false" - run: dotnet run --project build/PipelineCLI/PipelineCLI.csproj --configuration Release \ No newline at end of file + run: dotnet run --project build/PipelineCLI/PipelineCLI.csproj --configuration Release diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 70d8a62..9825177 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,6 +55,7 @@ jobs: - name: Run release pipeline if: steps.version.outputs.should_publish == 'true' env: - Release__ShouldPublish: true + Release__Mode: NuGet + GITHUB_TOKEN: ${{ github.token }} NuGet__ApiKey: ${{ secrets.NUGET__APIKEY }} run: dotnet run --project build/PipelineCLI/PipelineCLI.csproj --configuration Release diff --git a/build/PipelineCLI/Modules/CreateGitHubReleaseModule.cs b/build/PipelineCLI/Modules/CreateGitHubReleaseModule.cs index 14de6dd..6d24f31 100644 --- a/build/PipelineCLI/Modules/CreateGitHubReleaseModule.cs +++ b/build/PipelineCLI/Modules/CreateGitHubReleaseModule.cs @@ -17,16 +17,10 @@ protected override ModuleConfiguration Configure() => ModuleConfiguration .Create() .WithSkipWhen(_ => - releaseSettings.Value.Mode is ReleaseMode.NuGet or ReleaseMode.GitHubRelease - ? SkipDecision.DoNotSkip - : SkipDecision.Skip( - "Release publishing is disabled. Set Release__Mode=GitHubRelease or Release__Mode=NuGet to create a GitHub release." - ) - ) - .WithSkipWhen(_ => - string.IsNullOrWhiteSpace(gitSettings.Value.GetGitHubToken()) + releaseSettings.Value.Mode is not (ReleaseMode.NuGet or ReleaseMode.GitHubRelease) + || string.IsNullOrWhiteSpace(gitSettings.Value.GetGitHubToken()) ? SkipDecision.Skip( - "GitHub access token is not configured. Set GitHub__AccessToken or GITHUB_TOKEN to create a GitHub release." + "GitHub release creation is disabled. Set Release__Mode=NuGet (or GitHubRelease) and GITHUB_TOKEN to create a GitHub release." ) : SkipDecision.DoNotSkip ) diff --git a/build/PipelineCLI/Modules/PackModule.cs b/build/PipelineCLI/Modules/PackModule.cs index 5977701..27119b6 100644 --- a/build/PipelineCLI/Modules/PackModule.cs +++ b/build/PipelineCLI/Modules/PackModule.cs @@ -18,16 +18,11 @@ protected override ModuleConfiguration Configure() => ModuleConfiguration .Create() .WithSkipWhen(_ => - settings.Value.RunPack - ? SkipDecision.DoNotSkip - : SkipDecision.Skip("Packing is disabled. Set Build__RunPack=true to enable it.") - ) - .WithSkipWhen(_ => - releaseSettings.Value.Mode != ReleaseMode.None - ? SkipDecision.DoNotSkip - : SkipDecision.Skip( - "Packing is disabled. Set Release__Mode to something other than None to enable it." + !settings.Value.RunPack || releaseSettings.Value.Mode == ReleaseMode.None + ? SkipDecision.Skip( + "Packing is disabled. Set Build__RunPack=true and Release__Mode to something other than None to enable it." ) + : SkipDecision.DoNotSkip ) .Build(); diff --git a/build/PipelineCLI/Modules/PublishLocalNuGetModule.cs b/build/PipelineCLI/Modules/PublishLocalNuGetModule.cs index 1eddee2..9374bc7 100644 --- a/build/PipelineCLI/Modules/PublishLocalNuGetModule.cs +++ b/build/PipelineCLI/Modules/PublishLocalNuGetModule.cs @@ -20,16 +20,11 @@ protected override ModuleConfiguration Configure() => ModuleConfiguration .Create() .WithSkipWhen(ctx => - ctx.IsRunningLocally() - ? SkipDecision.DoNotSkip - : SkipDecision.Skip("Local NuGet Feed publishing is disabled. This module can only be run locally.") - ) - .WithSkipWhen(_ => - releaseSettings.Value.Mode == ReleaseMode.LocalNuGet - ? SkipDecision.DoNotSkip - : SkipDecision.Skip( - "Local NuGet Feed publishing is disabled. Set Release__Mode=LocalNuGet to enable it." + !ctx.IsRunningLocally() || releaseSettings.Value.Mode != ReleaseMode.LocalNuGet + ? SkipDecision.Skip( + "Local NuGet Feed publishing is disabled. Run the pipeline locally with Release__Mode=LocalNuGet to enable it." ) + : SkipDecision.DoNotSkip ) .Build(); diff --git a/build/PipelineCLI/Modules/PublishNuGetModule.cs b/build/PipelineCLI/Modules/PublishNuGetModule.cs index ae68a4c..9c8f74e 100644 --- a/build/PipelineCLI/Modules/PublishNuGetModule.cs +++ b/build/PipelineCLI/Modules/PublishNuGetModule.cs @@ -20,16 +20,10 @@ protected override ModuleConfiguration Configure() => ModuleConfiguration .Create() .WithSkipWhen(_ => - releaseSettings.Value.Mode == ReleaseMode.NuGet - ? SkipDecision.DoNotSkip - : SkipDecision.Skip( - "Release publishing is disabled. Set Release__Mode=NuGet to publish packages to nuget.org." - ) - ) - .WithSkipWhen(_ => - string.IsNullOrWhiteSpace(nugetSettings.Value.GetNuGetAPIKey()) + releaseSettings.Value.Mode != ReleaseMode.NuGet + || string.IsNullOrWhiteSpace(nugetSettings.Value.GetNuGetAPIKey()) ? SkipDecision.Skip( - "NuGet API key is not set. Set NuGet__APIKey or NUGET_APIKEY to publish packages." + "NuGet publishing is disabled. Set Release__Mode=NuGet and NuGet__ApiKey (or NUGET_APIKEY) to publish packages to nuget.org." ) : SkipDecision.DoNotSkip ) @@ -40,9 +34,16 @@ protected override ModuleConfiguration Configure() => CancellationToken cancellationToken ) { - var packages = Directory - .EnumerateFiles(buildSettings.Value.ArtifactsFolder, "*.nupkg", SearchOption.TopDirectoryOnly) - .ToList(); + var artifactsFolder = buildSettings.Value.ArtifactsFolder; + if (!Directory.Exists(artifactsFolder)) + { + throw new InvalidOperationException( + $"The artifacts folder '{artifactsFolder}' does not exist. " + + "Ensure the pack step ran (Release__Mode must not be None) before publishing." + ); + } + + var packages = Directory.EnumerateFiles(artifactsFolder, "*.nupkg", SearchOption.TopDirectoryOnly).ToList(); if (packages.Count == 0) {