name: npm

on:
  push:
    tags:
      - "v*"

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
        with:
          submodules: true
          token: ${{ secrets.GITHUB }}
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - name: yarn
        run: yarn
      - name: yarn test
        run: yarn test
      - name: Get the version
        id: get_version
        run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
      - name: Bump version
        run: npm version --git-tag-version=false ${{ steps.get_version.outputs.VERSION }}
      - name: Update package.json
        run: |
          git config --global user.name 'credify-devops'
          git config --global user.email 'dev-admin@credify.one'
          git remote set-url origin https://x-access-token:${{ secrets.GITHUB }}@github.com/$GITHUB_REPOSITORY
          git commit -am "Bump version in package.json" --no-verify
          git fetch
          git branch temp-branch
          git checkout main
          git merge temp-branch
          git push origin main
          git push
      - name: Build library
        run: yarn build
      - name: Publish SDK
        uses: JS-DevTools/npm-publish@v1
        with:
          token: ${{ secrets.NPM_TOKEN }}
