name: publish
on:
  push:
    branches:
      - master
jobs:
  publish:
    name: npm publish
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 16
      - name: Install pnpm
        run: npm install -g pnpm
      - name: Install dependencies
        run: pnpm install
      - name: Run tests
        run: pnpm run test
      - name: Build plugin
        run: pnpm run build --recursive
      - name: Configure git credentials
        uses: OleksiyRudenko/gha-git-credentials@v2-latest
        with:
          global: true
          name: '${{ secrets.GH_USER }}'
          email: '${{ secrets.GH_EMAIL }}'
          actor: '${{ secrets.GH_FULL_NAME }}'
          token: '${{ secrets.GITHUB_TOKEN }}'
      - name: Update origin push URI
        run: |
          git remote set-url origin "https://${{ secrets.GH_TOKEN_LERNA }}@github.com/${{ secrets.GH_USER }}/${{ secrets.GH_REPOSITORY }}.git" > /dev/null 2>&1
          git checkout master
      - name: Semantic Release
        uses: cycjimmy/semantic-release-action@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
      - name: Publish new version to npm
        uses: JS-DevTools/npm-publish@v1
        with:
          token: ${{ secrets.NPM_AUTH_TOKEN }}
          package: ./packages/gmap-vue/package.json
