name: Linux build

on:
  push:
    branches:
      - '**'
    tags-ignore:
      - latest

jobs:
  linux-build:
    name: Linux build
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - run: sudo apt-get update
      - run: sudo apt-get install pkg-config libsdl2-dev libfreetype6-dev zlib1g-dev libpng-dev devscripts

      - run: make -j 3
      - run: make -j 3 unit_test
      - run: make -j 3 e2e_test

      - run: make -j 3 clean
      - run: make -j 3 debug CFLAGS=-Wno-literal-suffix
      # Disabled for now on Linux: there are too many lint errors at the moment ...
      #- run: make -j 3 clang-tidy
      # Disabled for now as this is failing for unknown reasons.
      #- run: make -j 3 deb_pkg VERSION=99.99.0 REVISION=1

      - run: make -j 3 clean
      - run: make -j 3 APP_PATH=/tmp/cap32 DESTDIR=/tmp/cap32 install
      - run: test/integrated/test_make_install.sh /tmp/cap32

      # Linux build is responsible for pushing the latest tag.
      # MacOS & Windows build will create the release and upload artifacts to it
      # when they'll be called to build the tag itself.
      #
      # We have to use a dedicated access token because events raised by workflows
      # using GITHUB_TOKEN do not trigger other workflows:
      # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#about-workflow-events
      # To create the token, see:
      # https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
      # And then to create the secret containing it, see:
      # https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository
      #
      ## Unfortunately we have to delete the release as otherwise draft releases pile-up.
      ## I really don't like it because this means the latest release disappears on each push on master.
      #- if: github.ref_name == 'master'
      #  uses: dev-drprasad/delete-tag-and-release@v1.1
      #  with:
      #    delete_release: true
      #    tag_name: "latest"
      #  env:
      #    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      ## This one requires the tag to be deleted before creating it
      #- uses: tvdias/github-tagger@v0.0.1
      #  if: github.ref_name == 'master'
      #  with:
      #    tag: latest
      #    repo-token: ${{ secrets.LATEST_TOKEN }}
      - uses: richardsimko/update-tag@v1
        if: github.ref_name == 'master'
        with:
          tag_name: latest
        env:
          GITHUB_TOKEN: ${{ secrets.LATEST_TOKEN }}
