name: Build Linux Packages

on:
  push:
    branches: [ main, 'develop-**', 'dev/**' ]
    paths-ignore:
      - 'resource/locale/template/**'
      - 'docs/**'
      - '**.md'
  pull_request:
    branches: [ 'develop-**', 'dev/**' ]
    paths-ignore:
      - 'resource/locale/template/**'
      - 'docs/**'
      - '**.md'

env:
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: Release
  EXECUTABLE_OUTPUT_PATH: ./

jobs:
  build:
    strategy:
      matrix:
        os: [ 'ubuntu-20.04', 'ubuntu-22.04' ]
    runs-on: ${{ matrix.os }}
    continue-on-error: true
    steps:

      - uses: actions/checkout@v3
        with:
          lfs: 'false'
          submodules: 'recursive'

      - name: Get Short SHA of Commit
        id: vars
        run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
        

      - name: Install Dependence (Ubuntu 20.04)
        run: |
          sudo apt-get update
          sudo apt-get -y install build-essential binutils git autoconf automake gettext texinfo qt5-default
          sudo apt-get -y install gcc g++ ninja-build
          sudo apt-get -y install libarchive-dev libconfig++-dev libboost-all-dev libssl-dev
          sudo apt-get -y install gpg
        if: matrix.os == 'ubuntu-20.04'

      - name: Install Dependence (Ubuntu 22.04)
        run: |
          sudo apt-get update
          sudo apt-get -y install build-essential binutils git autoconf automake gettext texinfo
          sudo apt-get install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools
          sudo apt-get -y install gcc g++ ninja-build
          sudo apt-get -y install libarchive-dev libconfig++-dev libboost-all-dev libssl-dev
          sudo apt-get -y install gpg
        if: matrix.os == 'ubuntu-22.04'

      - name: Build gpg-error (Linux)
        run: |
          cd  ${{github.workspace}}/third_party/libgpg-error
          ./autogen.sh
          ./configure --enable-maintainer-mode --enable-static=yes && make -j2
          sudo make install
          cd ${{github.workspace}}

      - name: Build assuan (Linux)
        run: |
          cd ${{github.workspace}}/third_party/libassuan
          ./autogen.sh
          ./configure --enable-maintainer-mode && make -j2
          sudo make install
          cd ${{github.workspace}}

      - name: Build GpgME (Linux)
        run: |
          cd  ${{github.workspace}}/third_party/gpgme
          ./autogen.sh
          ./configure --enable-maintainer-mode --enable-languages=cpp && make -j2
          sudo make install
          cd ${{github.workspace}}

      - name: Build & Package GpgFrontend (Linux DEB Package)
        # Build your program with the given configuration
        run: |
          cmake -B ${{github.workspace}}/build-deb-${{matrix.os}} -G Ninja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DGPGFRONTEND_GENERATE_LINUX_INSTALL_SOFTWARE=ON -DCMAKE_INSTALL_PREFIX:PATH=${{github.workspace}}
          cmake --build ${{github.workspace}}/build-deb-${{matrix.os}} --config {{$env.BUILD_TYPE}} -- -v
          cd ${{github.workspace}}/build-deb-${{matrix.os}}
          ninja package
          cd ${{github.workspace}}
          
      - name: Upload Artifact(Linux DEB)
        uses: actions/upload-artifact@master
        with:
          name: gpgfrontend-${{matrix.os}}-${{env.BUILD_TYPE}}-${{env.sha_short}}-deb-${{matrix.os}}
          path: ${{github.workspace}}/build-deb-${{matrix.os}}/gpgfrontend*.deb*
