name: yq-merge
description: "Change the language format of a file."
inputs:
  lhs:
    description: "Left-hand side of merge."
    required: true
  rhs:
    description: "Right-hand side of merge."
    required: true
  operator:
    description: "Merge operator. See: https://mikefarah.gitbook.io/yq/operators/multiply-merge"
    required: true
    default: "*+"
  element:
    description: "Element to merge."
    required: true
    default: "."
  tmpDir:
    description: "Temporary directory. Default: _tmp"
    required: true
    default: _tmp
outputs:
  result:
    description: "The converted file."
    value: ${{ steps.merge.outputs.console }}
runs:
  using: "composite"
  steps:
  - name: "Make temporary file of first input."
    id: lhs
    uses: act/common/utils/mktemp@master
    with:
      input: ${{ inputs.lhs }}
      tmpDir: ${{ inputs.tmpDir }}
  - name: "Make temporary file of second input."
    id: rhs
    uses: act/common/utils/mktemp@master
    with:
      input: ${{ inputs.rhs }}
      tmpDir: ${{ inputs.tmpDir }}
  - name: "Merge files."
    id: merge
    uses: act/common/yq/yq@master
    with:
      command: "'${{ inputs.element }} ${{ inputs.operator }} load(\"${{ steps.rhs.outputs.tmp }}\")' '${{ steps.lhs.outputs.tmp }}'"
  - name: "Remove temporary files."
    run: rm -rf "${{ inputs.tmpDir }}"
    shell: bash
