name: CI

on: [push, pull_request, workflow_dispatch]

jobs:
  appimage-build:
    runs-on: ubuntu-latest
    container: opensuse/leap:15.6
    steps:
      # need to install Git >= 2.18 before checkout according to GitHub actions
      # we can just install all the dependencies beforehand, though
      - name: Install dependencies
        run: |
          zypper ar -G https://download.opensuse.org/repositories/KDE:/Qt6/openSUSE_Leap_15.6 QT6 && \
          zypper ar -G https://download.opensuse.org/repositories/KDE:/Frameworks/openSUSE_Leap_15.6 KF && \
          zypper install -y \
            cmake \
            make \
            wget \
            git \
            pkgconf \
            "cmake(KF6TextTemplate)" \
            "cmake(KF6Codecs)" \
            "cmake(KF6Contacts)" \
            "cmake(KF6I18n)" \
            "cmake(Qt6Core)" \
            "cmake(Qt6Concurrent)" \
            "cmake(Qt6Gui)" \
            "cmake(Qt6Sql)" \
            "cmake(Qt6Test)" \
            "cmake(Qt6Widgets)" \
            "cmake(Qt6Xml)" \
            "cmake(Qt6Svg)" \
             qt6-sql-sqlite \
             qt6-sql-mysql  \
             qt6-declarative-tools \
             kf6-ktexttemplate \
             breeze6-style \
             libcairo-gobject2 \
             libpango-1_0-0 \
             file \
            && update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-14 1 \
            && update-alternatives --install /usr/bin/g++ gcc /usr/bin/g++-14 50 \
            && update-alternatives --install /usr/bin/c++ gcc /usr/bin/g++-14 50 \
            && update-alternatives --install /usr/bin/cpp cpp /usr/bin/g++-14 50


      - uses: actions/checkout@v4
        with:
          submodules: recursive
          fetch-depth: 0

      - name: Build AppImage
        run: |
          git config --global --add safe.directory /__w/kraft/kraft
          export APPIMAGE_EXTRACT_AND_RUN=1
          wget https://github.com/TheAssassin/appimagecraft/releases/download/continuous/appimagecraft-x86_64.AppImage
          chmod +x appimagecraft-x86_64.AppImage
          ./appimagecraft-x86_64.AppImage

      - name: Archive artifacts
        uses: actions/upload-artifact@v4
        with:
          if-no-files-found: error
          name: AppImage
          path: |
            Kraft*.AppImage*

  upload:
    name: Create release and upload artifacts
    needs:
      - appimage-build
    runs-on: ubuntu-latest
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
      - name: Inspect directory after downloading artifacts
        run: ls -alFR
      - name: Create release and upload artifacts
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
            wget -q https://github.com/TheAssassin/pyuploadtool/releases/download/continuous/pyuploadtool-x86_64.AppImage
            chmod +x pyuploadtool-x86_64.AppImage
            ./pyuploadtool-x86_64.AppImage **/Kraft*.AppImage*
