branches: 
  - name: 'main'
  - name: 'alpha'
    prerelease: 'alpha'
preset: "angular"
tagFormat: "${version}"
plugins:
  - "@semantic-release/commit-analyzer"
  - "@semantic-release/release-notes-generator"
  - "@semantic-release/changelog"
  - "@semantic-release/git"
  - "@semantic-release/github"
verifyConditions:
  - '@semantic-release/git'
  - "@semantic-release/github"
analyzeCommits:
  - path: "@semantic-release/commit-analyzer"
    releaseRules:
    - type: "feat"
      release: "minor"
    - type: "hotfix"
      release: "patch"
    - type: "fix"
      release: "patch"
    - type: "patch"
      release: "patch"
    - type: "minor"
      release: "minor"
    - type: "breaking"
      release: "major"
    - type: "chore"
      release: "patch"
    - message: "*"
      release: "patch"
generateNotes:
  - path: "@semantic-release/release-notes-generator"
    writerOpts:
      groupBy: "type"
      commitGroupsSort:
        - "hotfix"
        - "feat"
        - "perf"
        - "fix"
      commitsSort: "header"
      mainTemplate: |
        {{> header}}

        {{#if noteGroups}}
        {{#each noteGroups}}

        ### ⚠ {{title}}

        {{#each notes}}
        * {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}}
        {{/each}}
        {{/each}}
        {{/if}}
        {{#each commitGroups}}

        {{#if title}}
        ### {{title}}

        {{/if}}
        {{#each commits}}
        {{> commit root=@root}}
        {{/each}}

        {{/each}}

        {{> footer}}
      headerPartial: |
        ## OpenBK7231T/OpenBeken release {{version}}
        
        ### WARNING! If installing versions tagged -alpha, please be aware these are development builds and may not be stable! Please do not flash all your devices at once! Make sure you can recover them via UART in case of unexpected issue.

        OpenBK7231T/OpenBeken is a Tasmota/Esphome replacement for new Tuya modules featuring MQTT and Home Assistant compatibility. This repository is named <code>OpenBK7231T_App</code>, but now it's a multiplatform app, supporting build for multiple separate chips:

        - BK7231T (WB3S, WB2S, WB2L etc)
        - BK7231N (CB2S, CB2L, WB2L_M1 etc)
        - T34 (based on BK7231N)
        - BL2028N (based on BK7231N)
        - XR809 (XR3 etc)
        - BL602 (DT-BL200, SM-028_V1.3 etc)
        - LF686 (based on BL602)
        - W800 (W800-C400, WinnerMicro WiFi & Bluetooth), W801
        - W600 (TW-01, TW-02, TW-03 etc), W601 (WIS600, ESP-01W etc)
        - LN882H (LN-02, WL2S, WL2H etc)

      footerPartial: |
        {{#if noteGroups}}
        {{#each noteGroups}}

        ### {{title}}

        {{#each notes}}
        * {{text}}
        {{/each}}
        {{/each}}
        {{/if}}

        ### Assets
        Refer to the following table for the usage of the various assests included in this release
        | Platform | Usage      | Filename                                                                                                                           |
        | ---      | ---        | ---                                                                                                                                |
        | BK7231T  | OTA Update | [OpenBK7231T_{{version}}.rbl]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBK7231T_{{version}}.rbl)         |
        | BK7231T  | CCtr Flash | [OpenBK7231T_UG_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBK7231T_UG_{{version}}.bin)   |
        | BK7231T  | UART Flash | [OpenBK7231T_UA_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBK7231T_UA_{{version}}.bin)   |
        | BK7231T  | SPI Flash | [OpenBK7231T_QIO_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBK7231T_QIO_{{version}}.bin) |
        | BK7231N  | OTA Update | [OpenBK7231N_{{version}}.rbl]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBK7231N_{{version}}.rbl)         |
        | BK7231N  | CCtr Flash | [OpenBK7231N_UG_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBK7231N_UG_{{version}}.bin)   |
        | BK7231N  | UART Flash | [OpenBK7231N_QIO_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBK7231N_QIO_{{version}}.bin) |   
        | XR809    |            | [OpenXR809_{{version}}.img]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenXR809_{{version}}.img)             |
        | BL602    | UART Flash | [OpenBL602_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBL602_{{version}}.bin)             |
        | BL602    | OTA Web App | [OpenBL602_{{version}}_OTA.bin.xz.ota]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBL602_{{version}}_OTA.bin.xz.ota)             |
        | W800     | OTA Update | [OpenW800_{{version}}_ota.img]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenW800_{{version}}_ota.img)       |
        | W800     | UART Flash | [OpenW800_{{version}}.fls]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenW800_{{version}}.fls)               |
        | W600     | OTA Update | [OpenW600_{{version}}_gz.img]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenW600_{{version}}_gz.img)         |
        | W600     | UART Flash | [OpenW600_{{version}}.fls]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenW600_{{version}}.fls)               |
        | LN882H   | OTA Update | [OpenLN882H_{{version}}_OTA.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenLN882H_{{version}}_OTA.bin)   |
        | LN882H   | UART Flash | [OpenLN882H_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenLN882H_{{version}}.bin)           |        
        | BK7231M  | UART Flash | [OpenBK7231M_QIO_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBK7231M_QIO_{{version}}.bin) |
        | Win32  | - | [obkSimulator_{{version}}.zip]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/obkSimulator_{{version}}.zip) |

        CCtr Flash = Tuya cloud Cutter flash
        SPI Flash can be flashed through SPI, even if you broke BK bootloader
        BK7231M is basically a BK7231N but with 000000 encryption keys. BK7231EasyGUIFlasher will show the encryption keys and warn you if you are trying to flash BK7231N with 000000 keys.
        BK7231M binary will work also for some BL2808Ns, they are also often just a BK7231N with 000000 etc keys.

        Flashing instructions are available on the project's [README.md]({{host}}/{{owner}}/{{repository}}#readme)
    preset: conventionalcommits
    presetConfig:
      types:
        - type: "feat"
          section: "Features"
        # Tracked bug fix with a hotfix branch
        - type: "hotfix"
          section: "Bug Fixes"
        # Uninmportent fix (CI testing, etc)
        - type: "fix"
          section: "Bug Fixes"
          hidden: false
        - type: "chore"
          section: "Changes"
          hidden: false
        - type: "docs"
          section: "Changes"
          hidden: false
        - type: "doc"
          section: "Changes"
          hidden: false
        - type: "style"
          section: "Changes"
          hidden: false
        - type: "refactor"
          section: "Changes"
          hidden: false
        - type: "perf"
          section: "Changes"
          hidden: false
        - type: "test"
          section: "Changes"
          hidden: false
        - type: ""
          section: "Changes"
          hidden: false          
prepare:
  - path: "@semantic-release/git"
publish:
  - path: "@semantic-release/github"
    addReleases: "bottom"
    assets:
      - path: "output/**/*_UA_*.bin"
      - path: "output/**/*_UG_*.bin"
      - path: "output/**/*_QIO_*.bin"
      - path: "output/**/*.rbl"
      - path: "output/**/*.img"
      - path: "output/**/OpenBL602*"
      - path: "output/**/OpenW600*"
      - path: "output/**/OpenW800*"
      - path: "output/**/OpenLN882H*"
      - path: "output/**/obkSimulator*"

success:
  - "@semantic-release/github"

fail:
  - "@semantic-release/github"
