name: CI
on: [push]
jobs:
  lint:
    runs-on: ubuntu-latest
    name: Lint
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Use Node 20
        uses: actions/setup-node@v3
        with:
          node-version: 20.x

      - uses: pnpm/action-setup@v4
        with:
          version: 9.7.0
          run_install: true

      - run: pnpm run lint

  check-ts:
    runs-on: ubuntu-latest
    name: Check Types
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Use Node 20
        uses: actions/setup-node@v3
        with:
          node-version: 20.x

      - uses: pnpm/action-setup@v4
        with:
          version: 9.7.0
          run_install: true

      - run: pnpm run check

  check-format:
    runs-on: ubuntu-latest
    name: Check Formatting
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Use Node 20
        uses: actions/setup-node@v3
        with:
          node-version: 20.x

      - uses: pnpm/action-setup@v4
        with:
          version: 9.7.0
          run_install: true

      - run: pnpm run format:check

  test:
    runs-on: ubuntu-latest
    name: Test
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Use Node 20
        uses: actions/setup-node@v3
        with:
          node-version: 20.x

      - uses: pnpm/action-setup@v4
        with:
          version: 9.7.0
          run_install: true

      - run: pnpm run test -- --ci --coverage --maxWorkers=2

  build:
    name: Build and Publish
    runs-on: ubuntu-latest
    needs: [check-ts, test]
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Use Node 20
        uses: actions/setup-node@v3
        with:
          node-version: 20.x

      - uses: pnpm/action-setup@v4
        with:
          version: 9.7.0
          run_install: true

      - name: Build
        working-directory: packages/design-system
        run: pnpm run build

      - uses: JS-DevTools/npm-publish@v3
        with:
          token: ${{ secrets.NPM_TOKEN }}
          access: public
          package: packages/design-system/package.json
        if: startsWith(github.ref, 'refs/tags/')

      - uses: JS-DevTools/npm-publish@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          registry: https://npm.pkg.github.com
          access: public
          package: packages/design-system/package.json
        if: startsWith(github.ref, 'refs/tags/')