# This workflow will build the native component for different platforms using
# qemu-user & docker

name: Build Linux Binaries

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  native:

    # Switch back to ubuntu-latest after that maps to 20.04
    runs-on: ubuntu-20.04

    strategy:
      matrix:
        arch:
          - "386"
          - amd64
          - arm
          - arm64
          - linux-arm-v5
          # this build does not work and ends up just rebuilding x86_64
          #- s390x
      fail-fast: false

    name: Linux binary ${{ matrix.arch }}

    steps:
      - uses: actions/checkout@v2
      - name: cache dependencies
        uses: actions/cache@v1
        with:
          path: ~/.m2
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-m2
      - uses: satackey/action-docker-layer-caching@v0.0.11
        continue-on-error: true
      - name: Update System
        run: sudo apt-get update -y
      - name: Install qemu
        run: sudo apt-get install -y --no-install-recommends qemu-user-static
      - name: Experimental Docker
        run: sudo cp .github/experimental-docker.json /etc/docker/daemon.json
      - name: Restart Docker
        run: sudo systemctl restart docker.service
      - name: Pull docker image
        run: docker pull --platform $(echo ${{ matrix.arch }} | sed 's|-|/|g') debian:10 || true
      - name: Build inside Docker
        run: docker run --rm -v $GITHUB_WORKSPACE:/work debian:10 /work/.github/build-native-debian.sh
      - name: Archive built library
        uses: actions/upload-artifact@v2
        with:
          name: shared-object-${{ matrix.arch }}
          path: build/jni/*.so
      - name: Archive built jar
        uses: actions/upload-artifact@v2
        with:
          name: jar-${{ matrix.arch }}
          path: archive/*.jar

