name: release2

on:
  workflow_dispatch:
    inputs:
      semver:
        description: "The semver to use"
        required: true
        default: "patch"
      remote:
        description: "The remote git where push the bumped version"
        required: true
        default: "origin"
      branch:
        description: "The branch you want to release"
        required: true
        default: "master"
      npm-otp:
        description: "It will provide the otp code to the npm publish"
        required: true
      # npm-dist-tag:
      #   description: "It will add a npm tag to the module, like beta or next"
      #   required: false
      # major:
      #   description: "It will unlock the release of a major release"
      #   required: false

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
        env:
          GITHUB_OAUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      - run: npm i releasify --no-save
      - run: cp ./monkey.js ./node_modules/releasify/lib/commands/publish.js
      - run: cp ./monkey-npm.js ./node_modules/releasify/lib/npm.js
      # - run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
      - run: npm config set //registry.npmjs.org/:_authToken=${NPM_TOKEN}
        env:
          NPM_TOKEN: ${{secrets.NPM_TOKEN}}
      - run: npm whoami
      - name: "check it should work"
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: echo "TOK=$NPM_TOKEN" | head -c 6
      - name: "release now"
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: |
          ./node_modules/.bin/releasify \
            publish \
            --no-verify \
            --verbose debug \
            --semver ${{github.event.inputs.semver}} \
            --remote ${{github.event.inputs.remote}} \
            --branch ${{github.event.inputs.branch}} \
            --npm-otp ${{github.event.inputs.npmOtp}} \
            --gh-token ${{secrets.GITHUB_TOKEN}}
