name: On Demand Build
on:
  repository_dispatch:
    types: [build-frontend-command]
jobs:
  build:
    name: Build frontend
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the latest code
        uses: actions/checkout@v2
        with:
          token: ${{ secrets.TWILL_PAT_TOKEN }}
          repository: ${{github.event.client_payload.pull_request.head.repo.full_name}}
          ref: ${{github.event.client_payload.pull_request.head.ref}}
          fetch-depth: 0
      - name: Setup Node.js environment
        uses: actions/setup-node@v2.1.5
        with:
          node-version: "14"
      - name: Install dependencies
        run: npm ci
      - name: Run build
        run: npm run build
      - name: Commit changes
        uses: EndBug/add-and-commit@v7
        with:
          author_name: Quentin Renard
          author_email: quentin@area17.com
          message: "Update distributed assets"
          add: "dist"
          branch: ${{github.event.client_payload.pull_request.head.ref}}
