name: "Publish GitHub Tag"
description: "Publish GitHub Tag"

inputs:
  github_token:
    description: 'Github token'
    required: true
    type: string
  branch_name:
    description: 'Name of the branch the workflow runs on'
    required: true
    type: string
  dry-run:
    description: dry run flag
    required: true
    type: boolean

runs:
  using: "composite"
  steps:
    - name: publish tag
      shell: bash
      run: |
        if [[  "${{ inputs.branch_name }}" == "master" ]]; then
          VERSION=$(jq -cr '.version' < package.json)
          echo "git tag -a ${VERSION} -m ${VERSION}"

          if [ $(git tag -l "$VERSION") ]; then
            echo "Tag \"$VERSION\" already exists. Skipping."
          else
              if [[ "${{ inputs.dry-run }}" != "true" ]]; then
                git tag -a ${VERSION} -m "${VERSION} [ci skip] "
                git remote rm origin
                GITHUB_REPO=https://${{ inputs.github_token }}:x-oauth-basic@github.com/Alfresco/alfresco-content-app.git
                git remote add origin $GITHUB_REPO
                git push origin --tags
              fi
          fi
        fi
