name: 'Build stable release'

permissions:
  contents: write

on:
  workflow_dispatch:
  push:
    tags:
      - 'v*'

jobs:
  tagged-release:
    name: 'Build Stable Release'
    runs-on: ubuntu-latest
    steps:

      - name: Install python 3.13
        uses: actions/setup-python@v5
        with:
          python-version: '3.13'

      - name: Install Node.js 22
        uses: actions/setup-node@v4
        with:
          node-version: 22

      - name: Checkout repository
        uses: actions/checkout@v4
  
      - name: Enable Corepack
        run: corepack enable pnpm

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

      - name: Build the WebUI
        run: |
          cd interface
          pnpm install
          pnpm typesafe-i18n --no-watch
          sed -i "s/= 'pl'/= 'en'/" ./src/i18n/i18n-util.ts
          pnpm build
          pnpm webUI

      - name: Build all PIO target environments
        run: |
          platformio run
        env:
          NO_BUILD_WEBUI: true

      - name: Create GitHub Release
        uses: emsesp/action-automatic-releases@v1.0.0
        with:
          repo_token: '${{ secrets.GITHUB_TOKEN }}'
          prerelease: false
          files: |
            CHANGELOG.md
            ./build/firmware/*.*
