name: linux

on:
  push:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-18.04
    strategy:
      fail-fast: false
      matrix:
        include:
        - lisp: sbcl-bin/2.0.0
          target: x86-64
          image: musl64
          makeopts: musl
        - lisp: sbcl-bin/2.0.0
          target: x86-64
          image: musl64
          makeopts: musl
          variant: -musl
        - lisp: sbcl-bin/2.0.0
          target: x86-64
          image: deb
          makeopts: deb
        - lisp: sbcl-bin/2.0.0
          target: x86-64
          image: pandoc
          makeopts: docs
    environment: SET_VERSION

    steps:
      - uses: actions/checkout@v2

      - name: setenv
        run: |
          echo "$HOME/.roswell/bin" >> $GITHUB_PATH
          echo "ROSWELL_BRANCH=release" >> $GITHUB_ENV
      - name: checkenv
        run: |
          uname -s
          uname -m
      - name: Install Roswell
        env:
          LISP: ${{ matrix.lisp }}
          GITHUB_OAUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          IMAGE: ${{ matrix.image }}
        run: |
          sh scripts/install-for-ci.sh
          ros install snmsts/sn.github
          if [ -n "$IMAGE" ]; then
             docker login docker.pkg.github.com -u snmsts -p $GITHUB_OAUTH_TOKEN;
             make -f scripts/Makefile pull-docker || make -f scripts/Makefile build-docker push-docker
          fi
      - name: build
        env:
          VERSION: ${{ secrets.VERSION }}
          ARCH: ${{ matrix.target }}
          DOCKER: ${{ matrix.docker }}
          SUFFIX: ${{ matrix.suffix }}
          LINKFLAGS: ${{ matrix.linkflags }}
          IMAGE: ${{ matrix.image }}
          MAKEOPTS: ${{ matrix.makeopts }}
          VARIANT: ${{ matrix.variant }}
        run: |
          if [ "$VERSION" = "" ]; then
            make -f scripts/Makefile latest-version docker
          else
            make -f scripts/Makefile docker
          fi
      - name: upload
        env:
          GITHUB_OAUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          VERSION: ${{ secrets.VERSION }}
          ARCH: ${{ matrix.target }}
          SUFFIX: ${{ matrix.suffix }}
        run: |
          if [ "$VERSION" = "" ]; then
            make -f scripts/Makefile latest-version ${{ matrix.makeopts }}-upload
          else
            make -f scripts/Makefile ${{ matrix.makeopts }}-upload
          fi
