name: Release packages

on:
  push:
    branches:
      - master
      - beta
      - alpha

defaults:
  run:
    shell: sh

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Wait on tests
        uses: lewagon/wait-on-check-action@v1.1.2
        with:
          ref: ${{ github.ref }}
          check-name: "Run tests"
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          wait-interval: 10

      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: "16"
          cache: "yarn"

      - name: Install packages
        run: yarn install

      - name: Build
        run: yarn build

      - name: Publish
        run: yarn release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
