functions/template-helpers/New-DotNetBuildGitHubWorkflow.ps1

# <copyright file="New-DotNetBuildGitHubWorkflow.ps1" company="Endjin Limited">
# Copyright (c) Endjin Limited. All rights reserved.
# </copyright>

<#
.SYNOPSIS
    Generates a GitHub Actions workflow that runs a .NET CI build.
.DESCRIPTION
    Generates a GitHub Actions workflow that consumes the resuable workflow:
    https://github.com/endjin/Endjin.RecommendedPractices.GitHubActions/blob/main/.github/workflows/scripted-build-pipeline.yml
    to run the standard .NET build process available in this module.
.EXAMPLE
    PS C:\> New-DotNetBuildGitHubWorkflow -Path .github/workflows/build.yml
    Generates a build script in the current directory configured to build the specified solution.
.PARAMETER NuGetOrgApiKeySecretName
    The name of the GitHub secret that contains the APIKey used for publishing to nuget.org.
.PARAMETER Path
    The destination path for the generated build script.
.PARAMETER Force
    When true, any existing file.
#>

function New-DotNetBuildGitHubWorkflow
{
    [CmdletBinding()]
    param (
        [Parameter()]
        [string] $OutputPath = ".github/workflows/build.yml",

        [Parameter()]
        [switch] $Force
    )

    $templatePath = "$PSScriptRoot/../../templates/dotnetbuild-gha-workflow.tmpl.yml"

    # If we're using the default value of OutputPath (i.e. we've not specified it when calling this function),
    # then it won't be part of the PSBoundParameters collection, so we need to add it before calling the
    # underlying template helper
    if ("OutputPath" -notin $PSBoundParameters.Keys) {
        $PSBoundParameters.Add("OutputPath", $OutputPath)
    }

    _executeTemplate -TemplatePath $templatePath @PSBoundParameters
}