name: lint, build, test, release

on: push

jobs:
  lint:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install
        run: sudo apt-get update && sudo apt-get install -y build-essential ctags ccache clang-tidy-11 clang-format-11
      - name: Generate linting instructions
        run: sh run sync
      - name: Lint
        run: sh run lint

  build-test-release:
    needs: [lint]
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install
        run: sudo apt-get update && sudo apt-get install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo ccache curl nasm grub-common qemu qemu-kvm mtools ctags inkscape
      - name: Get cross compiler
        id: cache-cross
        uses: actions/cache@v1
        with:
          path: cross
          key: cross-compiler
      - name: Build cross compiler
        if: steps.cache-cross.outputs.cache-hit != 'true'
        run: sh run cross -y
      - name: Build
        run: MELVIX_CONFIG=release sh run build -y
      - name: Upload as artifact
        uses: actions/upload-artifact@v2
        with:
          name: disk-img
          path: build/disk.img
      - name: Test with release mode
        run: MELVIX_CONFIG=release sh run test -y
      - name: Test with debug mode
        run: MELVIX_CONFIG=debug sh run test -y