name: Build

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Clone Repository
      run: |
        git clone --recursive --depth=1 https://github.com/sd2psXtd/firmware .

    - name: Install Dependencies
      run: apt update && apt install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib clangd git python3-venv

    - name: Build
      run: |
        cmake -B build -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DDEBUG_USB_UART:BOOL=OFF -DVARIANT:STRING=SD2PSX -DDEBUG_STARTUP_DELAY=0 -G "Unix Makefiles"
        cmake --build ${{ github.workspace }}/build

    - name: Upload Artifacts
      uses: gitea/actions/upload-artifact@v1
      with:
        name: ${{ matrix.filename }}${{ matrix.ext }}
        path: build/${{ matrix.filename }}${{ matrix.ext }}

  create_release:
    needs: [build]
    runs-on: ubuntu-latest
    steps:
    - name: Download All Artifacts
      uses: gitea/actions/download-artifact@v2

    - name: Create Release
      uses: gitea/actions/create-release@v1
      with:
        token: "${{ secrets.GITEA_TOKEN }}"
        prerelease: false
        tag_name: "v6.6.6"
        title: "v6.6.6"
        files: |
          */*.uf2