# This workflow will run the examples provided in the examples folder
name: examples

on:
  push:
    branches: [ master, release-0.8.x ]
  pull_request:
    branches: [ master, release-0.8.x ]

permissions:
  contents: read

jobs:
  nodejs:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version:
        - 14
        - 16
        - 18
        - 20
        - 22

    steps:
    - name: Harden Runner
      uses: step-security/harden-runner@05e31511f85b41b11d1cf0ef85d0992719546e2c # v2.21.0
      with:
        egress-policy: audit

    - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm install
      working-directory: examples/nodejs
    - run: npm run test
      working-directory: examples/nodejs
  typescript-node-es6:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        ts-version:
        - 3
        - 4
        - "5.0" # requires node version 12.20
        - 5 # typescript >=5.1 requires node version >=14.17
        node-version:
        - 14
        - 16
        - 18
        - 20
        - 22

    steps:
    - name: Harden Runner
      uses: step-security/harden-runner@05e31511f85b41b11d1cf0ef85d0992719546e2c # v2.21.0
      with:
        egress-policy: audit

    - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
      with:
        node-version: ${{ matrix.node-version }}
    - run: ./pretest.sh ${{ matrix.ts-version }}
      working-directory: examples/typescript-node-es6
    - run: node dist/index.js
      working-directory: examples/typescript-node-es6
