name: "pre-release"

on:
  workflow_dispatch:
  push:
    branches:
      - "dev"

jobs:
  pre-release:

    name: "Automatic pre-release build"
    runs-on: ubuntu-latest

    steps:
    
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16'

      - name: Get EMS-ESP source code and version
        id: build_info
        run: |
          version=`grep -E '^#define EMSESP_APP_VERSION' ./src/version.h | awk -F'"' '{print $2}'`
          echo "::set-output name=version::$version"

      - name: Install PlatformIO
        run: |
          python -m pip install --upgrade pip
          pip install -U platformio
          platformio upgrade
          platformio update

      - name: Build WebUI
        run: |
          cd interface
          npm ci
          npm run build

      - name: Build firmware
        run: |
          platformio run -e ci

      - name: Create a GH Release
        id: "automatic_releases"
        uses: "marvinpinto/action-automatic-releases@latest"
        with:
          repo_token: "${{ secrets.GITHUB_TOKEN }}"
          title: ESP32 Development Build v${{steps.build_info.outputs.version}}
          automatic_release_tag: "latest"
          prerelease: true
          files: |
            CHANGELOG_LATEST.md
            ./build/firmware/*.*
            
