name: Build and test Nim

# テストはPRだけ
on:
  pull_request:
    paths-ignore:
      - '*.md'
      - 'documents/*'

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
  group: "test"
  cancel-in-progress: false

jobs:
  # WIP でジョブがスキップされてもCIが失敗した扱いにならないようにするため
  skip:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Skip job"

  # WIP がコミットメッセージに含まれているとジョブを起動しない
  before:
    runs-on: ubuntu-latest
    if: "! contains(github.event.head_commit.message, 'WIP')"
    steps:
      - run: echo "no WIP"

  test-on-docker-nim:
    runs-on: ubuntu-latest
    needs: before
    strategy:
      fail-fast: false
      matrix:
        nim-version:
          - 2.0.16
          - 2.2.8
    env:
      NIM_VERSION: ${{ matrix.nim-version }}
    steps:
      - uses: actions/checkout@v2
      - name: Build docker image
        run: docker compose -f compose.test.yaml build app
      - name: Start dependencies
        run: docker compose -f compose.test.yaml up -d postgres mysql mariadb surreal
      - name: Test
        run: docker compose -f compose.test.yaml run --rm --no-deps app nimble test


  # アプリケーションの方を使うことにした
  # https://github.com/marketplace/actions/release-drafter
  # create-tag-draft:
  #   runs-on: ubuntu-latest
  #   if: github.ref == 'refs/heads/master'
  #   needs:
  #     - test-on-docker
  #   steps:
  #     - uses: release-drafter/release-drafter@v5.3.1
  #       env:
  #         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
