name: Build Linux, Android and Web

on:
  push:
    branches:
      - devel
  pull_request:
    branches:
      - devel

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Install Flutter
      uses: subosito/flutter-action@v2
      with:
        channel: 'stable'
        flutter-version: '3.24.1'

    - name: disable analytics
      run: flutter config --no-analytics

    - name: install dev dependencies
      run: |
        sudo apt-get update -y
        sudo apt-get install -y ninja-build libgtk-3-dev clang cmake pkg-config liblzma-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-good gstreamer1.0-plugins-bad libunwind-dev

    - name: Install dependencies
      run: flutter pub get

    - name: Build for Linux
      run: flutter build linux

    - name: Build for Android
      run: flutter build appbundle --debug

    - name: Build for web
      run: flutter build web --no-web-resources-cdn --csp --web-renderer canvaskit

    - name: Gather linux artifacts
      uses: actions/upload-artifact@v4
      with:
        name: flutter-linux-build-latest
        path: build/linux
        if-no-files-found: error

    - name: Gather android artifacts
      uses: actions/upload-artifact@v4
      with:
        name: flutter-android-build-latest
        path: build/app/outputs/bundle
        if-no-files-found: error

    - name: Gather web artifacts
      uses: actions/upload-artifact@v4
      with:
        name: flutter-web-build-latest
        path: build/web
        if-no-files-found: error

    - name: Publish to Cloudflare Pages
      uses: cloudflare/pages-action@v1
      with:
        apiToken: ${{ secrets.CLOUDFLARE_PAGES_DEPLOY }}
        accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
        projectName: ything-radio
        directory: build/web
        # push directly to "production" on cloudflare pages
        branch: main
