version: 2.1
commands:

  cmake:
    description: Configure build
    steps:
      - run:
          name: Configure build
          command: cmake ..
          working_directory: build


  build_source:
    description: Create source tarball
    steps:
      - run:
          name: Create source tarball
          command: ../dist/scripts/maketarball.sh
          working_directory: build


  build_rpm:
    description: Build RPM
    steps:
      - run:
          name: Create RPM build sources directories
          command: mkdir -p ~/rpmbuild/SOURCES /usr/src/packages/SOURCES
      - run:
          name: Copy source tarball 1
          command: cp strawberry-*.tar.xz ~/rpmbuild/SOURCES/
          working_directory: build
      - run:
          name: Copy source tarball 2
          command: cp strawberry-*.tar.xz /usr/src/packages/SOURCES/
          working_directory: build
      - run:
          name: Build RPM
          command: rpmbuild -ba ../dist/unix/strawberry.spec
          working_directory: build


  build_deb:
    description: Build Deb
    steps:
      - run:
          name: make deb
          command: dpkg-buildpackage -b -d -uc -us -nc -j2


  install_opensuse_dependencies:
    description: Install openSUSE dependencies
    steps:
      - run:
          name: Update packages
          command: zypper --non-interactive --gpg-auto-import-keys ref
      - run:
          name: Install openSUSE dependencies
          command: >
            zypper --non-interactive --gpg-auto-import-keys install
            lsb-release
            rpm-build
            git
            tar
            make
            cmake
            gcc
            gcc-c++
            gettext-tools
            glibc-devel
            libboost_headers-devel
            boost-devel
            glib2-devel
            glib2-tools
            dbus-1-devel
            alsa-devel
            libnotify-devel
            libgnutls-devel
            protobuf-devel
            sqlite3-devel
            libpulse-devel
            gstreamer-devel
            gstreamer-plugins-base-devel
            taglib-devel
            vlc-devel
            libQt5Core-devel
            libQt5Gui-devel
            libQt5Widgets-devel
            libQt5Concurrent-devel
            libQt5Network-devel
            libQt5Sql-devel
            libQt5DBus-devel
            libQt5Test-devel
            libqt5-qtx11extras-devel
            libqt5-qtbase-common-devel
            libQt5Sql5-sqlite
            libqt5-linguist-devel
            libcdio-devel
            libgpod-devel
            libmtp-devel
            libchromaprint-devel
            desktop-file-utils
            update-desktop-files
            appstream-glib
            hicolor-icon-theme


  install_fedora_dependencies:
    description: Install Fedora dependencies
    steps:
      - run:
          name: Update packages
          command: yum update --assumeyes
      - run:
          name: Upgrade packages
          command: yum upgrade --assumeyes
      - run:
          name: Install Fedora dependencies
          command: >
            dnf install --assumeyes
            @development-tools
            redhat-lsb-core
            git
            glibc
            gcc-c++
            rpmdevtools
            make
            cmake
            pkgconfig
            glib
            man
            tar
            gettext
            openssh
            boost-devel
            dbus-devel
            protobuf-devel
            protobuf-compiler
            sqlite-devel
            alsa-lib-devel
            pulseaudio-libs-devel
            libnotify-devel
            gnutls-devel
            qt5-qtbase-devel
            qt5-qtx11extras-devel
            qt5-qttools-devel
            gstreamer1-devel
            gstreamer1-plugins-base-devel
            taglib-devel
            libcdio-devel
            libgpod-devel
            libmtp-devel
            libchromaprint-devel
            fftw-devel
            desktop-file-utils
            libappstream-glib
            hicolor-icon-theme


  install_debian_dependencies:
    description: Install Debian dependencies
    steps:
      - run:
          name: Install Debian dependencies
          command: >
            apt-get update && apt-get install -y
            build-essential
            dh-make
            ssh
            git
            make
            cmake
            gcc
            pkg-config
            fakeroot
            gettext
            lsb-release
            libglib2.0-dev
            dpkg-dev
            libdbus-1-dev
            libboost-dev
            libprotobuf-dev
            protobuf-compiler
            libsqlite3-dev
            libgnutls28-dev
            libasound2-dev
            libpulse-dev
            libtag1-dev
            qtbase5-dev
            qtbase5-dev-tools
            qtbase5-private-dev
            libqt5x11extras5-dev
            qttools5-dev
            libgstreamer1.0-dev
            libgstreamer-plugins-base1.0-dev
            gstreamer1.0-alsa
            gstreamer1.0-pulseaudio
            libchromaprint-dev
            libfftw3-dev
            libcdio-dev
            libmtp-dev
            libgpod-dev


  install_ubuntu_dependencies:
    description: Install Ubuntu dependencies
    steps:
      - run:
          name: Setup environment
          command: |
            echo 'export DEBIAN_FRONTEND=noninteractive' >> $BASH_ENV
            source $BASH_ENV
      - run:
          name: Install Ubuntu dependencies
          command: >
            apt-get update && apt-get install -y
            build-essential
            dh-make
            ssh
            git
            make
            cmake
            pkg-config
            gcc
            fakeroot
            wget
            curl
            gettext
            lsb-release
            dpkg-dev
            libglib2.0-dev
            libboost-dev
            libdbus-1-dev
            libprotobuf-dev
            protobuf-compiler
            libsqlite3-dev
            libgnutls28-dev
            libasound2-dev
            libpulse-dev
            libtag1-dev
            qtbase5-dev
            qtbase5-dev-tools
            qtbase5-private-dev
            libqt5x11extras5-dev
            qttools5-dev
            libgstreamer1.0-dev
            libgstreamer-plugins-base1.0-dev
            libgstreamer-plugins-good1.0-dev
            gstreamer1.0-alsa
            gstreamer1.0-pulseaudio
            libchromaprint-dev
            libfftw3-dev
            libcdio-dev
            libmtp-dev
            libgpod-dev


jobs:

  build_source:
    docker:
      - image: opensuse/leap:15.2
    steps:
      - install_opensuse_dependencies
      - checkout
      - cmake
      - build_source


  build_opensuse_lp151:
    docker:
      - image: opensuse/leap:15.1
    environment:
      RPM_BUILD_NCPUS: "2"
    steps:
      - install_opensuse_dependencies
      - checkout
      - cmake
      - build_source
      - build_rpm

  build_opensuse_lp152:
    docker:
      - image: opensuse/leap:15.2
    environment:
      RPM_BUILD_NCPUS: "2"
    steps:
      - install_opensuse_dependencies
      - checkout
      - cmake
      - build_source
      - build_rpm


  build_fedora_32:
    docker:
      - image: fedora:32
    environment:
      RPM_BUILD_NCPUS: "2"
    steps:
      - install_fedora_dependencies
      - checkout
      - cmake
      - build_source
      - build_rpm

  build_fedora_33:
    docker:
      - image: fedora:33
    environment:
      RPM_BUILD_NCPUS: "2"
    steps:
      - install_fedora_dependencies
      - checkout
      - cmake
      - build_source
      - build_rpm


  build_debian_buster:
    docker:
      - image: debian:buster
    steps:
      - install_debian_dependencies
      - checkout
      - cmake
      - build_deb

  build_debian_bullseye:
    docker:
      - image: debian:bullseye
    steps:
      - install_debian_dependencies
      - checkout
      - cmake
      - build_deb


  build_ubuntu_bionic:
    docker:
      - image: ubuntu:bionic
    steps:
      - install_ubuntu_dependencies
      - checkout
      - cmake
      - build_deb

  build_ubuntu_focal:
    docker:
      - image: ubuntu:focal
    steps:
      - install_ubuntu_dependencies
      - checkout
      - cmake
      - build_deb

  build_ubuntu_groovy:
    docker:
      - image: ubuntu:groovy
    steps:
      - install_ubuntu_dependencies
      - checkout
      - cmake
      - build_deb

workflows:
  version: 2
  build_all:
    jobs:

      - build_source:
          filters:
            tags:
              only: /.*/


      - build_opensuse_lp151:
          filters:
            tags:
              only: /.*/
      - build_opensuse_lp152:
          filters:
            tags:
              only: /.*/


      - build_fedora_32:
          filters:
            tags:
              only: /.*/
      - build_fedora_33:
          filters:
            tags:
              only: /.*/


      - build_debian_buster:
          filters:
            tags:
              only: /.*/
      - build_debian_bullseye:
          filters:
            tags:
              only: /.*/


      - build_ubuntu_bionic:
          filters:
            tags:
              only: /.*/
      - build_ubuntu_focal:
          filters:
            tags:
              only: /.*/
      - build_ubuntu_groovy:
          filters:
            tags:
              only: /.*/
