name: CI
on: pull_request
jobs:
  review:
    name: "Review"
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Setup the toolchain
        uses: ./.github/actions/setup-toolchain
      - name: Ensure rnx-kit packages come from our repository
        run: |
          if grep rnx-kit yarn.lock; then
            exit 1
          fi
      - name: Deduplicate packages
        run: |
          npx yarn-deduplicate --list --fail
      - name: Install package dependencies
        uses: ./.github/actions/yarn
      - name: Check for change files
        run: yarn change:check --since origin/${{ github.base_ref }}
      - name: Report formatting problems
        run: |
          yarn format
          git diff --exit-code
      - name: Report dependency problems
        run: |
          yarn rnx-align-deps --write
          git diff --exit-code
      - name: Report @rnx-kit/build workflow inconsistencies
        run: |
          cp incubator/build/workflows/github.yml .github/workflows/rnx-build.yml
          git diff --exit-code
  build:
    name: "Build"
    strategy:
      matrix:
        node-version: [14, 16]
        os: [ubuntu-20.04, windows-2022]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Setup the toolchain
        uses: ./.github/actions/setup-toolchain
        with:
          node-version: ${{ matrix.node-version }}
          go-version: "^1.14.0"
      - name: Install package dependencies
        uses: ./.github/actions/yarn
      - name: Build and test packages
        run: yarn build:ci --base origin/${{ github.base_ref }}
      - name: Ensure READMEs are up-to-date
        if: ${{ matrix.node-version == 14 && matrix.os == 'ubuntu-20.04' }}
        run: |
          yarn update-readme
          git diff --exit-code
      - name: Bundle packages
        run: yarn bundle
      - name: Bundle test app with esbuild
        run: |
          yarn bundle+esbuild
        shell: bash
        working-directory: packages/test-app
      - name: Bundle test app with RAM bundle format
        run: |
          yarn ram-bundle
        shell: bash
        working-directory: packages/test-app
  build-android-expo-app:
    name: "Build Android"
    uses: ./.github/workflows/build-android.yml
    with:
      package: expo-app
  build-android-test-app:
    name: "Build Android"
    uses: ./.github/workflows/build-android.yml
    with:
      package: test-app
  build-ios-expo-app:
    name: "Build iOS"
    uses: ./.github/workflows/build-ios.yml
    with:
      package: expo-app
      workspace-name: expoapp
      scheme-name: expoapp
  build-ios-test-app:
    name: "Build iOS"
    uses: ./.github/workflows/build-ios.yml
    with:
      package: test-app
      workspace-name: SampleCrossApp
      scheme-name: ReactTestApp
  build-website:
    name: "Build the website"
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Setup the toolchain
        uses: ./.github/actions/setup-toolchain
      - name: Install package dependencies (docsite)
        uses: ./.github/actions/yarn
        with:
          working-directory: docsite
      - name: Build website
        run: yarn build
        working-directory: docsite
  label:
    name: "Label"
    if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
    runs-on: ubuntu-20.04
    permissions:
      contents: read
      pull-requests: write
    steps:
      - uses: actions/labeler@v4
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          sync-labels: true
        continue-on-error: true
