name: Build

defaults:
  run:
    shell: bash

env:
  CI: true

on:
  push:
    branches:
      - master
  pull_request:

jobs:
  api:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up environment
        uses: ./.github/actions/setup
      - name: Build API
        run: cd packages/api && yarn build
      - name: Create package tgz
        run: cd packages/api && yarn pack && mv package.tgz actual-api.tgz
      - name: Upload Build
        uses: actions/upload-artifact@v3
        with:
          name: actual-api
          path: packages/api/actual-api.tgz

  crdt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up environment
        uses: ./.github/actions/setup
      - name: Build CRDT
        run: cd packages/crdt && yarn build
      - name: Create package tgz
        run: cd packages/crdt && yarn pack && mv package.tgz actual-crdt.tgz
      - name: Upload Build
        uses: actions/upload-artifact@v3
        with:
          name: actual-crdt
          path: packages/crdt/actual-crdt.tgz

  web:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up environment
        uses: ./.github/actions/setup
      - name: Build Web
        run: ./bin/package-browser
      - name: Upload Build
        uses: actions/upload-artifact@v3
        with:
          name: actual-web
          path: packages/desktop-client/build
      - name: Upload Build Stats
        uses: actions/upload-artifact@v3
        with:
          name: build-stats
          path: packages/desktop-client/build-stats
