name: CI Action AWS KVS WebRTC JS SDK

on:
  push:
    branches:
      - master
      - develop
  pull_request:
    branches:
      - master
      - develop

jobs:
  nodejs-ubuntu-build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [ 18, 19, 20, 21, 22, 23 ]
      fail-fast: false
    steps:
      - name: Checkout repository
        uses: actions/checkout@master
      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
      - name: Install dependencies
        run: npm install
      - name: Run release
        run: npm run release

  dependabot-auto-merge-after-ci-passes:
    needs: nodejs-ubuntu-build
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
      contents: write
    if: >-
      github.actor == 'dependabot[bot]' &&
      github.event_name == 'pull_request' &&
      github.event.pull_request.base.ref == 'develop'
    env:
      PR_URL: ${{ github.event.pull_request.html_url }}
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Approve Dependabot PR
        run: gh pr review --approve "$PR_URL"
      - name: Auto-merge Dependabot PR
        run: gh pr merge --squash --auto "$PR_URL"
