name: chDB-node

on:
  pull_request:
    branches: [ "main" ]
    paths-ignore:
      - '**/.md'
  push:
    branches: [ "main" ]
    paths-ignore:
      - '**/.md'


jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
        node-version: [18.x, 20.x, 22.x]
    steps:
    - name: Use Python 3.11
      uses: actions/setup-python@v2
      with:
        python-version: '3.11'
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        registry-url: 'https://registry.npmjs.org'
    - name: Install dependencies
      run: npm install
    - name: Run tests
      run: npm run test
    - name: Publish to npm
      if: github.ref == 'refs/heads/main' && matrix.node-version == '18.x' && matrix.os == 'ubuntu-latest'
      run: npm publish
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
