From c1ed75dc989e2f399d110ba8b00d4fa77ea225c6 Mon Sep 17 00:00:00 2001 From: Xenapte <17661805+Xenapte@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:52:11 +0800 Subject: [PATCH] feat: build appimage with ci --- .github/workflows/server.yml | 32 +++++++++++++++++---- BallanceMMOServer/start_ballancemmo_loop.sh | 14 +++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index 9da200fd..31c635f3 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -38,13 +38,14 @@ jobs: # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: | echo -e "\nfile(WRITE version.txt \${BMMO_VER})" >> CMakeLists.txt - cmake -B ${{github.workspace}}/build -S ${{github.workspace}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_SERVER=ON -DBUILD_CLIENT=OFF + cmake -B ${{github.workspace}}/build -S ${{github.workspace}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_SERVER=ON -DBUILD_CLIENT=OFF -DCMAKE_INSTALL_PREFIX=/usr echo "BMMO_VER=$(cat version.txt)" >> "$GITHUB_ENV" echo "SHA_SHORT=$(git rev-parse --short ${{github.sha}})" >> "$GITHUB_ENV" - - name: Build + - name: Build and install # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + working-directory: ${{github.workspace}} + run: DESTDIR=AppDir cmake --build ./build --config ${{env.BUILD_TYPE}} --target install - name: Test working-directory: ${{github.workspace}} @@ -52,11 +53,29 @@ jobs: # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C ${{env.BUILD_TYPE}} + - name: Build AppImage + working-directory: ${{github.workspace}}/build + run: | + curl -o linuxdeploy.AppImage -L https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20240109-1/linuxdeploy-x86_64.AppImage + chmod +x linuxdeploy.AppImage + appdeploy=$(./linuxdeploy.AppImage --appimage-extract | grep AppRun | head -n 1) + echo Got linuxdeploy exec entry at $appdeploy + $appdeploy --appdir AppDir --output appimage --desktop-file ../BallanceMMOServer/appimage/BMMOLaunchSelector.desktop --icon-file ../BallanceMMOServer/appimage/BallanceMMO.svg + + - name: Prepare artifact directory and dry run + working-directory: ${{github.workspace}}/build + run: | + appfile=$(ls BallanceMMOLaunchSelector*.AppImage | awk '{print $1}') + chmod +x $appfile + mkdir artifacts + mv -t artifacts $appfile BallanceMMOServer/start_ballancemmo_loop.sh + artifacts/$appfile --launch Server --dry-run + - name: Release Artifact uses: actions/upload-artifact@v3 with: name: server-linux-${{env.BMMO_VER}}-${{env.SHA_SHORT}} - path: build/BallanceMMOServer + path: build/artifacts build-server-windows: runs-on: windows-latest @@ -108,9 +127,10 @@ jobs: working-directory: ${{github.workspace}} run: ctest -C ${{env.BUILD_TYPE}} + # by setting a different working directory we avoid releasing the config file - name: Dry run - working-directory: ${{github.workspace}}/build/BallanceMMOServer/${{env.BUILD_TYPE}} - run: ${{github.workspace}}/build/BallanceMMOServer/${{env.BUILD_TYPE}}/BallanceMMOServer.exe --dry-run + working-directory: ${{github.workspace}}/build/BallanceMMOServer + run: ${{env.BUILD_TYPE}}/BallanceMMOServer.exe --dry-run - name: Release Artifact uses: actions/upload-artifact@v3 diff --git a/BallanceMMOServer/start_ballancemmo_loop.sh b/BallanceMMOServer/start_ballancemmo_loop.sh index 213e09c1..e3dfd80e 100644 --- a/BallanceMMOServer/start_ballancemmo_loop.sh +++ b/BallanceMMOServer/start_ballancemmo_loop.sh @@ -12,9 +12,19 @@ trap "ctrlc_exit" 2 for (( ; ; )) do log_name=$(date +"log_%Y%m%d%H%M.log") - chmod +x ./BallanceMMOServer + server_binary="./BallanceMMOServer" + extra_options=() + if [ ! -f "$server_binary" ]; then + server_binary=$(ls ./BallanceMMOLaunchSelector*.AppImage | awk '{print $1}') + if [ ! -f "$server_binary" ]; then + echo "Error: server executable not found." >&2 + exit 1 + fi + extra_options=("--launch" "Server") + fi + chmod +x $server_binary SECONDS=0 - ./BallanceMMOServer --log=$log_name "$@" + $server_binary "${extra_options[@]}" --log=$log_name "$@" server_status=$? archive_logs if [ $server_status -eq 0 ] || [ $server_status -eq 1 ] || [ $SECONDS -lt 10 ]