name: Release App

on:
  push:
    tags:
      - 'v*.*.*'
    paths-ignore:
      - 'README.md'
      - 'docs/**'
      - '.vscode'
  pull_request:
    branches:
      - master
    paths-ignore:
      - 'docs/**'
      - 'README.md'
      - '.vscode'

concurrency:
  group: release-ci-group
  cancel-in-progress: true

jobs:
  MacOS:
    runs-on: macos-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          submodules: 'true'

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18.x
      - name: Install pnpm
        uses: pnpm/action-setup@v2
        with:
          version: latest
      - name: Get pnpm store directory
        id: pnpm-cache
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
      - name: Get npm cache directory
        uses: actions/cache@v3
        id: cache
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-

      - name: Install dependencies
        run: pnpm i -r
      - name: Install OctoBase
        run: pnpm build:prerequisite
        working-directory: client-app

      - name: Make macOS (x64)
        run: pnpm build:app
        working-directory: client-app
        env:
          CI: true
          CI_PULL_REQUEST: ${{ github.event_name == 'pull_request' }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          draft: true
          generate_release_notes: true
          files: client-app/src-tauri/target/release/bundle/dmg/*.dmg
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
