---
name: "Action release"
description: "Steps to build release"
author: "DerSkythe"

inputs:
  release_type:
    description: 'release_type'
    required: true
  release_version:
    description: 'release_version'
    required: true
  firmware_version:
    description: 'firmware_version'
    required: true
  repo_self:
    description: 'REPO_SELF'
    required: true
  gh_token:
    description: 'github_gh_token'
    required: true
  owner:
    description: 'owner'
    required: true
  current_tag:
    description: 'current_tag'
    required: true
  remote_tag_info:
    description: 'remote_tag_info'
    required: true

# outputs:
#   make-minor-release:
#     description: "make-minor-release"
#     value: ${{ steps.make-minor-release.outputs }}
#   make-major-release:
#     description: "make-minor-release"
#     value: ${{ steps.make-major-release.outputs }}

runs:
  using: "composite"
  steps:
    - name: Minor release
      if: ${{ inputs.release_type == 2 }}
      id: make-minor-release
      uses: softprops/action-gh-release@v1
      with:
        tag_name: 'v${{ inputs.release_version }}'
        name: 'Minor update v${{ inputs.release_version }}'
        token: ${{ inputs.gh_token }}
        draft: true
        generate_release_notes: true
        #target_commitish: ${{ github.SHA }}
        append_body: true
        body: 'Rebuild with new version of firmware.\n\nSee: [CHANGELOG](${{ inputs.firmware_version }}/blob/dev/CHANGELOG.md)\n${{ inputs.remote_tag_info }}'
        repository: '${{ inputs.repo_self }}'

    - name: Major release
      if: ${{ inputs.release_type == 1 }}
      id: make-major-release
      uses: softprops/action-gh-release@v1
      with:
        tag_name: 'v${{ inputs.release_version }}'
        name: Release v${{ inputs.release_version }}
        token: ${{ inputs.gh_token }}
        draft: true
        generate_release_notes: true
        #target_commitish: ${{ github.SHA }}
        append_body: true
        body: 'New version is rolling out!'
        repository: '${{ inputs.repo_self }}'

    - name: Update Firmware variable and create UPDATE release if necessary
      if: ${{ success() }}
      env:
        GITHUB_TOKEN: ${{ inputs.gh_token }}
        OWNER: ${{ inputs.owner }}
      shell: bash
      run: |
          gh variable set FIRMWARE_VERSION -b '${{ inputs.firmware_version }}' -R '${{ inputs.repo_self }}'
          gh variable set RELEASE_VERSION -b '${{ inputs.release_version }}' -R '${{ inputs.repo_self }}'
