name: Build

on:
  push:
    paths-ignore:
    - README.md
    - '**/*.md'
  pull_request:
  schedule:
  - cron: "0 0 * * 0"

jobs:
  build:
    name: ${{ matrix.os }} with Java 17
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
    - name: Checkout master branch
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Set up JDK 17
      uses: actions/setup-java@v4
      with:
        distribution: 'oracle'
        java-version: '17'
    - name: Cache Maven packages
      uses: actions/cache@v4
      with:
        path: ~/.m2
        key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
        restore-keys: ${{ runner.os }}-m2
    - name: Checkout Universal ctags
      uses: actions/checkout@v4
      with:
        repository: universal-ctags/ctags
        path: ctags
    - name: Install pre-requisites (Unix)
      if: runner.os == 'Linux' || runner.os == 'macOS'
      run: ./dev/before_install
    - name: Install Universal ctags (Windows)
      if: runner.os == 'Windows'
      run: choco install universal-ctags
    - name: Before build actions
      shell: bash
      run: ./dev/before
    - name: Maven build
      shell: bash
      env:
        OPENGROK_PULL_REQUEST: ${{ github.head_ref }}
        OPENGROK_REPO_SLUG: ${{ github.repository }}
        OPENGROK_REF: ${{ github.ref }}
        OPENGROK_SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: ./dev/main