name: Dockcross CI

on:
  push:
    branches:
    - '*'
    paths-ignore:
      - '**/README.md'
  pull_request:
    branches:
    - '*'
    paths-ignore:
      - '**/README.md'
  workflow_dispatch:

jobs:
  base:
    name: base
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: build
        run: make base
      - name: test
        run: make base.test
      - name: archive base
        run: |
            mkdir -p cache
            docker save dockcross/base:latest | xz -e9 -T0 > ./cache/base.tar.xz
      - name: save base
        uses: actions/upload-artifact@v2
        with:
          name: cache
          path: ./cache
          retention-days: 1
      - name: deploy
        if: github.ref == 'refs/heads/master'
        run: |
            docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }}
            docker image push dockcross/base --all-tags

  image:
    name: ${{ matrix.arch_name }}
    needs: base
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        arch_name: [android-arm, android-arm64, android-x86, android-x86_64, 
          linux-arm64, linux-arm64-musl, linux-armv5, linux-armv5-musl, 
          linux-armv6, linux-armv6-lts, linux-armv6-musl, 
          linux-armv7, linux-armv7a, linux-armv7l-musl, 
          linux-x64-clang, linux-s390x, linux-x64, linux-x86, 
          linux-mips, linux-ppc64le, web-wasm,
          manylinux2014-x64, manylinux2014-x86, manylinux2014-aarch64, 
          windows-static-x64, windows-static-x64-posix, windows-static-x86, 
          windows-shared-x64, windows-shared-x64-posix, windows-shared-x86, 
          linux-riscv64, linux-riscv32, linux-m68k-uclibc, linux-xtensa-uclibc]
    steps:
      - uses: actions/checkout@v2
      - uses: actions/download-artifact@v2
        with:
          name: cache
          path: ./cache
      - name: load base
        run: xz -d -k < ./cache/base.tar.xz | docker load
      - name: build
        run: make ${{ matrix.arch_name }}
      - name: test
        run: make ${{ matrix.arch_name }}.test
      - name: deploy
        if: github.ref == 'refs/heads/master'
        run: |
            docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }}
            docker image push dockcross/${{ matrix.arch_name }} --all-tags