name: Containers CI

on:
  push:
    paths-ignore:
      - "**.md"
  pull_request:
    paths-ignore:
      - "**.md"

concurrency:
  group: build-containers-${{ github.event.pull_request.number || github.sha }}
  cancel-in-progress: true

jobs:

  alpine-docker-musl-gcc:
    runs-on: ubuntu-20.04
    if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v'
    timeout-minutes: 181
    container:
      # Alpine docker pre-built container
      image: thevlang/vlang:alpine-build
      env:
        V_CI_MUSL: 1
        VFLAGS: -cc gcc
      volumes:
        - ${{github.workspace}}:/opt/vlang

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Show Environment
        run: |
          echo "PWD:"
          pwd
          echo "ENVIRONMENT:"
          env
          echo "C Compiler:"
          gcc --version

## TODO: fix the container thevlang/vlang:alpine-build, instead of using apk add here:
      - name: Add dependencies
        run: |
          apk add libexecinfo-static
          apk add libexecinfo-dev
          apk add libc6-compat

      - name: Build V
        run: CC=gcc make

      - name: All code is formatted
        run: ./v test-cleancode

      - name: Run only essential tests
        run: VTEST_JUST_ESSENTIAL=1 ./v test-self

  ubuntu-docker-musl:
    runs-on: ubuntu-20.04
    if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v'
    timeout-minutes: 121
    container:
      image: thevlang/vlang:ubuntu-build
      env:
        V_CI_MUSL: 1
        V_CI_UBUNTU_MUSL: 1
        VFLAGS: -cc musl-gcc -gc none
      volumes:
        - ${{github.workspace}}:/opt/vlang

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Build V
        run: |
          echo $VFLAGS && make -j4 && ./v -cg -o v cmd/v
      - name: Verify `v test` works
        run: |
          echo $VFLAGS
          ./v cmd/tools/test_if_v_test_system_works.v
          ./cmd/tools/test_if_v_test_system_works

      - name: All code is formatted
        run: ./v test-cleancode

      - name: Test V fixed tests
        run: ./v test-self
