name: Release
on:
  push:
    branches:
      - main

jobs:
  lint:
    name: Lint Before Release
    if: github.repository_owner == 'FrancescoXX'
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v4
        with:
          node-version: 18.x
      - name: Install dependencies
        run: yarn install --frozen-lockfile
      - name: Lint
        run: yarn lint

  build:
    name: Try to Build Before Release
    if: github.repository_owner == 'FrancescoXX'
    runs-on: ubuntu-latest
    needs: lint

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v4
        with:
          node-version: 18.x
      - name: Install dependencies
        run: yarn install --frozen-lockfile
      - name: Build
        run: yarn build

  release:
    name: Create GitHub Release
    if: github.repository_owner == 'FrancescoXX'
    runs-on: ubuntu-latest
    needs: build

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v4
        with:
          node-version: 18.x
      - name: Install dependencies
        run: yarn install --frozen-lockfile
      - name: Release package
        run: yarn release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
