# Based on https://github.com/ml-tooling/universal-build/blob/v0.6.14/workflows/build-pipeline.yml
name: build-pipeline

on:
  workflow_dispatch:
    inputs:
      build_args:
        description: "Arguments passed to build script"
        required: false
      working_directory:
        description: "Working directory from where the build command is run"
        required: false
  push:
  pull_request:

env:
  BUILD_ARGS: ${{ secrets.BUILD_ARGS }}
  WORKING_DIRECTORY: ${{ secrets.WORKING_DIRECTORY }}

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: set-input-build-args
        if: ${{ github.event.inputs != null  &&  github.event.inputs.build_args != null}}
        run: echo "BUILD_ARGS=${{ github.event.inputs.build_args }}" >> $GITHUB_ENV
        # new syntax: run: echo "BUILD_ARGS=${{ github.event.inputs.build_args }}" >> "$GITHUB_ENV"
      - name: set-input-working-directory
        if: ${{ github.event.inputs != null  &&  github.event.inputs.working_directory != null}}
        run: echo "WORKING_DIRECTORY=${{ github.event.inputs.working_directory }}" >> $GITHUB_ENV
        # new syntax: run: echo "WORKING_DIRECTORY=${{ github.event.inputs.working_directory }}" >> "$GITHUB_ENV"
      # Set host ip to env variable to be uside within container actions
      - name: set-host-ip
        run: echo "_HOST_IP=$(hostname -I | cut -d ' ' -f 1)" >> $GITHUB_ENV
      - uses: actions/checkout@v2
      - name: run-build-scripts
        uses: ./.github/actions/build-environment
        with:
          build_args: ${{ env.BUILD_ARGS }}
          working_directory: ${{ env.WORKING_DIRECTORY }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
