candoumbe / candoumbe/Pipelines
✨ Add extension points to override when `IPushNugetPackages.Publish` can run
- Dominant language
- C#
- Stars
- 10
- Forks
- 1
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 9
Description
**Is your feature request related to a problem? Please describe.**
When to publish packages should be overridable by client projects
**Describe the solution you'd like**
A single property that can be overriden by a client project
For example : a method `bool CanPublish(string branchName)` which result would then be used by `IPushNugetPackages.Publish`
to decide if the target can run or not
The current default implementation would change from
```csharp
public Target Publish => _ => _
.Description($"Published packages (*.nupkg and *.snupkg) to the destination server set using either {nameof(PublishConfigurations)} settings or the configuration {nameof(ConfigName)} configuration ")
.Consumes(Pack, ArtifactsDirectory / "*.nupkg", ArtifactsDirectory / "*.snupkg")
.DependsOn(Pack)
.OnlyWhenDynamic(() => (!string.IsNullOrWhiteSpace(ConfigName) && PublishConfigurations.Once(config => config.Name == ConfigName))
|| PublishConfigurations.AtLeastOnce(config => config.CanBeUsed()))
.WhenNotNull(this as IHaveGitRepository,
(_, repository) => _.Requires(() => GitHasCleanWorkingCopy())
.OnlyWhenDynamic(() => IsLocalBuild
|| repository.GitRepository.IsOnMainOrMasterBranch()
|| repository.GitRepository.IsOnReleaseBranch()
|| repository.GitRepository.IsOnHotfixBranch()))
.Requires(() => Configuration.Equals(Configuration.Release))
.Executes(() => { .... });
```
to
```csharp
public Target Publish => _ => _
.Description($"Published packages (*.nupkg and *.snupkg) to the destination server set using either {nameof(PublishConfigurations)} settings or the configuration {nameof(ConfigName)} configuration ")
.Consumes(Pack, ArtifactsDirectory / "*.nupkg", ArtifactsDirectory / "*.snupkg")
.DependsOn(Pack)
.OnlyWhenDynamic(() => CanPublish(this.Get()?.GitRepository?.Branch))
.Executes(() => { .... });
CanPublish(string branchName) => PublishConfigurations.AtLeastOnce(config => config.CanBeUsed()))
.WhenNotNull(this as IHaveGitRepository,
(_, repository) => _.Requires(() => GitHasCleanWorkingCopy())
.OnlyWhenDynamic(() => IsLocalBuild
|| repository.GitRepository.IsOnMainOrMasterBranch()
|| repository.GitRepository.IsOnReleaseBranch()
|| repository.GitRepository.IsOnHotfixBranch())
```
**Describe alternatives you've considered**
Creating several properties (one for each possible branch) :
```csharp
bool CanPublishOnDevelop { get; }
bool CanPublishOnMainOrMaster { get; }
bool CanPublishOnFeature { get; }
bool CanPublishOnHotfix { get; }
```
But this approach seems way too opinionated
**Additional context**
Contributor guide
Assessment
This issue has not been assessed yet.