name: "Commit and Push Changes"
description: "Configure Git, commit changes, push to branch, and tag release"

inputs:
  new_tag:
    description: "The tag to create and push"
    required: true

runs:
  using: "composite"
  steps:
    - name: Configure Git
      shell: bash
      run: |
        git config user.name "${{ github.actor }}"
        git config user.email "${{ github.actor }}@users.noreply.${{ github.server_url }}"

    - name: Add and Commit changes
      shell: bash
      run: |
        git config advice.addIgnoredFile false

        for p in docs/ media/gameplay media/thumbnail media/panel media/icons export README.md how-to-use.md src; do
          if [ -e "$p" ]; then
            git add -A "$p"
          fi
        done

        git commit -m "[ci skip] push back from pipeline" -q || echo "No changes to commit"

    - name: Push changes and create tag
      shell: bash
      run: |
        if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
          git push origin HEAD:main || echo "No changes to push"
          git tag "${{ inputs.new_tag }}"
          git push origin "${{ inputs.new_tag }}"
        else
          git push origin HEAD:"${GITHUB_REF_NAME}" || echo "No changes to push"
        fi
