name: On merge

on:
  push:
    branches:
      - main

jobs:
  release-publish:
    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"

    steps:
      # Providing the SSH PRIVATE of a user part of an admin group
      # is necessary to bypass PR checks
      - uses: actions/checkout@v2
        with:
          ssh-key: ${{ secrets.GH_SSH_PRIVATE_KEY_JAHIACI }}

      - uses: actions/setup-node@v3
        with:
          registry-url: 'https://registry.npmjs.org/'

      # Setting up the SSH agent to be able to commit back to the repository
      # https://github.com/webfactory/ssh-agent
      - uses: webfactory/ssh-agent@v0.5.4
        with:
          ssh-private-key: ${{ secrets.GH_SSH_PRIVATE_KEY_JAHIACI }}

      - name: Install dependencies
        shell: bash
        run: yarn install --frozen-lockfile

      - name: Build
        shell: bash
        run: yarn build

      - name: Release and publish
        env:
          GITHUB_TOKEN: ${{ secrets.GH_API_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPMJS_PUBLISH_TOKEN }}
        shell: bash
        run: |
          git fetch --tags
          yarn release

      - name: Merge changes back into develop branch
        shell: bash
        run: |
          git checkout develop
          git merge main --ff-only 
          git push -u origin develop
