name: grpc-tools Build

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

permissions:
  contents: read #  to fetch code (actions/checkout)

jobs:
  linux_build:
    name: Linux grpc-tools Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: recursive
      - name: Build
        run: |
          docker build -t kokoro-native-image tools/release/native
          docker run -v /var/run/docker.sock:/var/run/docker.sock -v $GITHUB_WORKSPACE:$GITHUB_WORKSPACE kokoro-native-image $GITHUB_WORKSPACE/packages/grpc-tools/build_binaries.sh
      - uses: actions/upload-artifact@v4
        with:
          name: grpc-tools_linux
          path: artifacts/
  macos_build:
    name: Macos grpc-tools Build
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: recursive
      - name: Build
        run: packages/grpc-tools/build_binaries.sh
      - uses: actions/upload-artifact@v4
        with:
          name: grpc-tools_macos
          path: artifacts/
  windows_build:
    name: Windows grpc-tools Build
    runs-on: windows-latest
    strategy:
      matrix:
        arch: [ia32, x64]
    env:
      ARCH: ${{matrix.arch}}
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: recursive
      - name: Build
        run: powershell -File ./packages/grpc-tools/build_binaries.ps1
        shell: cmd
      - uses: actions/upload-artifact@v4
        with:
          name: grpc-tools_windows_${{matrix.arch}}
          path: artifacts/
  combine_artifacts:
    name: Combine grpc-tools artifacts
    runs-on: ubuntu-latest
    needs: [linux_build, macos_build, windows_build]
    steps:
      - uses: actions/download-artifact@v4
      - name: Copy
        run: |
          mkdir artifacts
          cp -r ./**/* artifacts/
      - uses: actions/upload-artifact@v4
        with:
          name: combined-artifacts
          path: artifacts/
