# 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@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
      with:
        egress-policy: audit

    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.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@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
      with:
        egress-policy: audit

    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.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
