name: tpl-to-nuspec
description: "Pack a .nupkg given a .nuspec Go template file and a yaml input file. The input yaml file environment variables replaced first."
inputs:
  template:
    description: "Template or local path of the template file to use. Defaults to the template file in the action's directory."
    required: false
  input:
    description: "Input or local path of the yaml input data file."
    required: true
outputs:
  nuspec:
    description: "The generated output .nuspec file."
    value: ${{ steps.xml.outputs.result }}
  packageName:
    description: "The 'name' property of the generated .nuspec file."
    value: ${{ steps.name.outputs.result }}
runs:
  using: "composite"
  steps:
  - name: "Set template variable."
    id: get-template
    run: |
      TEMPLATE=$(cat << EOF
      ${{ inputs.template }}
      EOF
      )
      if [[ -z "$TEMPLATE" ]]; then
        TEMPLATE="${{ github.action_path }}/nuspec.yaml.tpl"
      fi

      echo "template<<EOF" >> "$GITHUB_OUTPUT"
      echo "$TEMPLATE" >> "$GITHUB_OUTPUT"
      echo "EOF" >> "$GITHUB_OUTPUT"
    shell: bash
  - name: "Merge Input"
    id: merge
    uses: act/common/yq/yq-merge@master
    with:
      lhs: ${{ github.action_path }}/defaults.yaml
      rhs: ${{ inputs.input }}
  - name: "Generate Nuspec Yaml from Template"
    id: template
    uses: act/common/tpl/tpl-env@master
    with:
      template: ${{ steps.get-template.outputs.template }}
      decoder: yaml
      input: ${{ steps.merge.outputs.result }}
  - name: "Convert the Nuspec Yaml to XML"
    id: trim
    uses: act/common/yq/yq-trim@master
    with:
      input: ${{ steps.template.outputs.result }}
      recursive: true
  - name: "Convert the Nuspec Yaml to XML"
    id: xml
    uses: act/common/yq/yq-convert@master
    with: 
      input: ${{ steps.trim.outputs.result }}
      from: yaml
      to: xml
  - name: "Get id from input."
    id: name
    uses: act/common/yq/yq-expression@master
    with: 
      input: ${{ steps.merge.outputs.result }}
      expression: .id
  