name: build

on:
  push:
    branches:
      - 'main'
      - 'rr/**' # "rr" stands for "remote run"
  pull_request:
    branches: [ "main" ]
  schedule:
    - cron: '0 0 * * *' # every day at 00:00

jobs:

  build-debug:
    strategy:
      # fail-fast: false # Disable fail-fast in matrix
      matrix:
        # https://docs.github.com/en/actions/reference/runners/github-hosted-runners#standard-github-hosted-runners-for-public-repositories
        # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md
        # https://github.com/actions/runner-images/blob/main/images/macos/macos-15-arm64-Readme.md
        # https://github.com/actions/runner-images/blob/main/images/macos/macos-26-arm64-Readme.md
        #
        # Xcode versions:
        # - https://en.wikipedia.org/wiki/Xcode
        # - https://xcodereleases.com/?scope=release
        os: [macos-14, macos-15, macos-26]
    name: build-debug
    runs-on: ${{ matrix.os }}
    steps:
      - run: env # Debug
      - uses: actions/checkout@v6
      - run: ./.github/gh-actions-runner-xcode-select.sh
      - run: brew install swiftly bash
      - run: swiftly init --skip-install --assume-yes --verbose && swiftly install
      - run: swiftly run swift --version
      - run: ./build-debug.sh
      - run: ./test.sh

  # We build release artifacts only on the latest macOS versions because:
  # 1. It cuts the build time twice on GH Actions
  # 2. The latest Xcode version is not available on old macOS, and old Xcode versions bundle too old Swift version
  build-release:
    strategy:
      # fail-fast: false # Disable fail-fast in matrix
      matrix:
        os: [macos-15, macos-26]
    name: build-release
    runs-on: ${{ matrix.os }}
    steps:
      - run: env # Debug
      - uses: actions/checkout@v6
      - run: ./.github/gh-actions-runner-xcode-select.sh
      - run: brew install bash fish xcbeautify swiftly
      - run: swiftly init --skip-install --assume-yes --verbose && swiftly install
      - run: swiftly run swift --version
      - name: './build-release.sh'
        run: |
          # "-" means "Sign to run locally". There is no aerospace-codesign-certificate on GH Actions
          ./build-release.sh --codesign-identity -
          brew trust nikitabobko/tap
          ./install-from-sources.sh --dont-rebuild
      - name: cat ./.release/xcodebuild.log
        if: ${{ always() }}
        run: 'if test -f ./.release/xcodebuild.log; then cat ./.release/xcodebuild.log; fi'
