Skip to content

✨ Add extension points to override when IPushNugetPackages.Publish can run  #75

Open
@candoumbe

Description

@candoumbe

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

    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

    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<IHaveGitRepository>()?.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) :

bool CanPublishOnDevelop { get; }
bool CanPublishOnMainOrMaster { get; }
bool CanPublishOnFeature { get; }
bool CanPublishOnHotfix { get; }

But this approach seems way too opinionated

Additional context

Metadata

Metadata

Assignees

Labels

area:workflowRelated to git branching strategyci-cdRelated to continous integration/developmentenhancement ✨New feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions