name: CI

on:
  push:
    branches: [main]
    paths:
      - grammar.js
      - make_grammar.js
      - src/**
      - test/**
      - example/**
      - bindings/**
      - binding.gyp
  pull_request:
    paths:
      - grammar.js
      - make_grammar.js
      - src/**
      - test/**
      - example/**
      - bindings/**
      - binding.gyp

concurrency:
  group: ${{github.workflow}}-${{github.ref}}
  cancel-in-progress: true

jobs:
  test:
    name: Test parser
    runs-on: ${{matrix.os}}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Set up tree-sitter
        uses: tree-sitter/setup-action/cli@v1
      - name: Run parser and binding tests
        uses: tree-sitter/parser-test-action@v2
        with:
          test-node: true
          test-rust: ${{runner.os == 'Linux'}}
      - name: Parse sample files
        uses: tree-sitter/parse-action@v4
        id: parse-files
        with:
          files: |-
            example/**/*.hcl
            example/**/*.tf
      - name: Upload failures artifact
        uses: actions/upload-artifact@v4
        if: "!cancelled() && steps.parse-files.outcome == 'failure'"
        with:
          name: failures-${{runner.os}}
          path: ${{steps.parse-files.outputs.failures}}
