name: 'Publish'

on:
  workflow_dispatch:
    inputs:
      new_version:
        description: 'version type:'
        type: choice
        default: 'minor'
        options:
          - patch
          - minor
          - major
        required: true

run-name: Publish create-vk-mini-app ${{ inputs.new_version }}

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}

      - name: Setting up the repository environment
        uses: ./.github/actions/setup

      - name: Bump version
        id: updated_versions_info
        uses: ./.github/actions/bump-version
        with:
          version: ${{ github.event.inputs.new_version }}

      - name: Validation
        uses: ./.github/actions/validation

      - name: Update npm
        run: npm install -g npm@latest
        shell: bash

      - name: Publish to npm
        run: npm publish --access public
        shell: bash

      - name: Commit and tag
        run: |
          git add -A
          git commit -m "bump(create-vk-mini-app): from ${{ steps.updated_versions_info.outputs.prev_version }} to ${{ steps.updated_versions_info.outputs.next_version }}"
          git tag create-vk-mini-app@${{ steps.updated_versions_info.outputs.next_version }}
        shell: bash

      - name: Pushing changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
          branch: ${{ github.ref }}
          tags: true
