name: Release

on:
  push:
    branches:
      - master
    tags-ignore:
      - '**'
    paths-ignore:
      - '**/CHANGELOG.md'
      - '**/package.json'
      - 'docs/**'
  pull_request:
  workflow_dispatch:
jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    # Only run on non-PR events or only PRs that aren't from forks
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
    steps:
      - uses: actions/checkout@v2
      - name: Set Node Version
        uses: actions/setup-node@v2
        with:
          node-version: 16
      - name: Install dependencies
        run: npm i

      - name: Bootstrap
        run: npm run bootstrap

      - name: Generate docs
        run: npm run build:docs

      - name: Semantic Release
        uses: cycjimmy/semantic-release-action@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          NODE_OPTIONS: --max-old-space-size=4096
          SEMANTIC_RELEASE_PACKAGE: ${{ github.event.repository.name }} # Always needed
        with:
          extra_plugins: |
            @semantic-release/changelog
            @semantic-release/git
