name: Deploy Staging

on:
  push:
    branches:
      - 'staging*'

jobs:
  build:
    if: "!contains(github.event.head_commit.message, 'skip ci')"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Get the requested branch details
        shell: bash
        run: |
          echo "::set-output name=branch::${GITHUB_REF#refs/heads/}"
        id: myref

      - name: Print deployment environment details
        run: |
          echo "${{ steps.myref.outputs.branch }}"

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 18
      - name: Installing dependencies
        run: yarn install --frozen-lockfile

      - name: Build lib
        run: yarn run compile

      - name: Deploy Web Preview Staging
        uses: peter-evans/repository-dispatch@v1
        with:
          token: ${{secrets.GH_ACTIONS_TOKEN}}
          repository: AdaloHQ/web-preview
          event-type: deploy-staging
          client-payload: '{"sha": "${{ github.sha }}", "branch": "${{steps.myref.outputs.branch}}"}'

      - name: Deploy Web Runtime Staging
        uses: peter-evans/repository-dispatch@v1
        with:
          token: ${{secrets.GH_ACTIONS_TOKEN}}
          repository: AdaloHQ/web-runtime
          event-type: deploy-staging
          client-payload: '{"sha": "${{ github.sha }}", "branch": "${{steps.myref.outputs.branch}}"}'
