on: push
name: validate
jobs:
  diff:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3.3.0
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
      - run: npm ci && npm i -g esbuild
      - run: make clean
      - run: make -j 8 build
      - run: ./scripts/diff-lint

  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3.3.0
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
      - run: npm ci && npm i -g esbuild
      - run: make clean
      - run: make -j 8 build
      - run: npm run lint
        env:
          ESLINT_FORMAT_OPTIONS:
            '--format json-with-metadata --output-file reports/style/eslint.json'
          TSC_OPTIONS: '| tee reports/style/tsc.log'
      - uses: check-run-reporter/action@v2.11.1
        if: ${{ always() }}
        with:
          token: ${{ secrets.CHECK_RUN_REPORTER_TOKEN }}
          label: ESLint
          report: 'reports/style/eslint.json'
      - uses: check-run-reporter/action@v2.11.1
        if: ${{ always() }}
        with:
          token: ${{ secrets.CHECK_RUN_REPORTER_TOKEN }}
          label: TSC
          report: 'reports/style/tsc.log'

  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3.3.0
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
      - run: npm ci && npm i -g esbuild
      - run: make clean
      - run: make -j 8 build
      - run: scripts/deploy-examples-to-localstack
      - run: TEST_MODE=localstack npm test
      - uses: check-run-reporter/action@v2.11.1
        if: ${{ always() }}
        with:
          token: ${{ secrets.CHECK_RUN_REPORTER_TOKEN }}
          label: Unit Tests
          report: 'reports/junit/**/*.xml'

  release:
    needs:
      - diff
      - lint
      - test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3.3.0
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
      - run: npm ci && npm i -g esbuild
      - run: make clean
      - run: make -j 8 build
      - run: npx semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
