name: Test

on:
  push:
    branches: [ master ]
    paths-ignore:
      - 'README.md'
      - 'README_zh.md'
      - 'config.json'
  pull_request:
  workflow_dispatch:

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        submodules: recursive

    - name: Setup Node.js 14
      uses: actions/setup-node@v3
      with:
        node-version: 14.x
    
    - name: Setup JDK 17
      uses: actions/setup-java@v3
      with:
          java-version: 17
          distribution: 'temurin'

    - name: Configure git credentials
      uses: OleksiyRudenko/gha-git-credentials@v2.1.1
      with:
        global: true
        token: ${{ secrets.GITHUB_TOKEN }}

    - name: Check Version and Build
      env:
        GH_REPO: ${{ github.repository }}
        TEST: true
      run: |
        npm install
        npm start
      
    - name: List files and print output.json
      run: |
        ls -l
        cat ./output.json
    
    - name: Load output file to env
      uses: antifree/json-to-variables@v1.0.1
      with:
        filename: output.json

    - name: Upload artifact
      uses: actions/upload-artifact@v3
      with:
        path: ${{ env.json_FileName }}
