diff --git a/.github/workflows/build-gen_emu_config-linux.yml b/.github/workflows/build-gen_emu_config-linux.yml index c75a999c..95c0dafd 100644 --- a/.github/workflows/build-gen_emu_config-linux.yml +++ b/.github/workflows/build-gen_emu_config-linux.yml @@ -3,14 +3,23 @@ name: Generate emu config script (Linux) on: push: branches: [ - "ci-build-gen-linux", + "ci-build-gen-linux*", "ci-build-all" ] + tags: + - release* pull_request: branches: [ "dev" ] + workflow_dispatch: + # nothing permissions: - contents: read + contents: write + +env: + ARTIFACT_NAME: "generate_emu_config-linux-${{ github.sha }}" + ARTIFACT_ROOT_PATH: "scripts/bin/linux" + PACKAGE_ROOT_PATH: "scripts/bin/package" jobs: build: @@ -30,12 +39,23 @@ jobs: working-directory: ${{ github.workspace }}/scripts run: sudo chmod 77 rebuild_linux.sh && sudo ./rebuild_linux.sh - - name: Upload build + - name: Package build + shell: bash + working-directory: ${{ github.workspace }}/scripts + run: sudo chmod 77 package_linux.sh && sudo ./package_linux.sh + + - name: Upload build package uses: actions/upload-artifact@v4 with: - name: "generate_emu_config-linux-${{ github.sha }}" - path: 'scripts/bin/linux/' + name: "${{ env.ARTIFACT_NAME }}" + path: "${{ env.PACKAGE_ROOT_PATH }}/linux/" if-no-files-found: 'error' compression-level: 9 retention-days: 1 + + - name: Release + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: "${{ env.PACKAGE_ROOT_PATH }}/**/*" \ No newline at end of file diff --git a/.github/workflows/build-gen_emu_config-win.yml b/.github/workflows/build-gen_emu_config-win.yml index 8bfb11bd..0a4cc429 100644 --- a/.github/workflows/build-gen_emu_config-win.yml +++ b/.github/workflows/build-gen_emu_config-win.yml @@ -3,14 +3,27 @@ name: Generate emu config script (Windows) on: push: branches: [ - "ci-build-gen-win", + "ci-build-gen-win*", "ci-build-all" ] + tags: + - release* pull_request: branches: [ "dev" ] + workflow_dispatch: + # nothing permissions: - contents: read + contents: write + +env: + ARTIFACT_NAME: "generate_emu_config-win-${{ github.sha }}" + ARTIFACT_ROOT_PATH: "scripts/bin/win" + PACKAGE_ROOT_PATH: "scripts/bin/package" + + # Expected format {owner}/{repo}. + DEPS_REPO: 'otavepto/gbe_fork' + THIRD_PARTY_BASE_DIR: 'third-party' jobs: build: @@ -25,6 +38,13 @@ jobs: - name: Checkout branch uses: actions/checkout@v4 + - name: Clone third-party deps (deps/win) + uses: actions/checkout@v4 + with: + repository: "${{env.DEPS_REPO}}" + ref: 'third-party/deps/win' + path: "${{env.THIRD_PARTY_BASE_DIR}}/deps/win" + - name: Install dependencies shell: cmd working-directory: ${{ github.workspace }}/scripts @@ -35,12 +55,23 @@ jobs: working-directory: ${{ github.workspace }}/scripts run: rebuild_win.bat - - name: Upload build + - name: Package build + shell: cmd + working-directory: ${{ github.workspace }}/scripts + run: package_win.bat + + - name: Upload build package uses: actions/upload-artifact@v4 with: - name: "generate_emu_config-win-${{ github.sha }}" - path: 'scripts/bin/win/' + name: "${{ env.ARTIFACT_NAME }}" + path: "${{ env.PACKAGE_ROOT_PATH }}/win/" if-no-files-found: 'error' compression-level: 9 retention-days: 1 + + - name: Release + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: "${{ env.PACKAGE_ROOT_PATH }}/**/*" \ No newline at end of file diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index c8f9d801..ca727551 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -3,22 +3,29 @@ name: Emu build (Linux) on: push: branches: [ - "ci-build-emu-linux", + "ci-build-emu-linux*", "ci-build-all" ] + tags: + - release* pull_request: branches: [ "dev" ] + workflow_dispatch: + # nothing permissions: - contents: read + contents: write env: # Expected format {owner}/{repo}. DEPS_REPO: 'otavepto/gbe_fork' THIRD_PARTY_BASE_DIR: 'third-party' + DEPS_CACHE_KEY: emu-deps-linux DEPS_CACHE_DIR: build-linux-deps - + + PACKAGE_ROOT_PATH: "build-linux/package" + jobs: dependencies: runs-on: ubuntu-22.04 @@ -97,12 +104,18 @@ jobs: working-directory: ${{ github.workspace }} run: "sudo chmod 777 build_linux.sh && ./build_linux.sh release" - - name: Upload build (release) + - name: Package build (release) + if: success() + shell: bash + working-directory: ${{ github.workspace }} + run: sudo chmod 77 package_linux.sh && sudo ./package_linux.sh release + + - name: Upload build pacakge (release) if: success() uses: actions/upload-artifact@v4 with: name: "build-linux-release-${{ github.sha }}" - path: 'build-linux/release/' + path: "${{ env.PACKAGE_ROOT_PATH }}/release/" if-no-files-found: 'error' compression-level: 9 retention-days: 1 @@ -114,13 +127,25 @@ jobs: working-directory: ${{ github.workspace }} run: "sudo chmod 777 build_linux.sh && ./build_linux.sh debug" - - name: Upload build (debug) + - name: Package build (debug) + if: success() + shell: bash + working-directory: ${{ github.workspace }} + run: sudo chmod 77 package_linux.sh && sudo ./package_linux.sh debug + + - name: Upload build pacakge (debug) if: success() uses: actions/upload-artifact@v4 with: name: "build-linux-debug-${{ github.sha }}" - path: 'build-linux/debug/' + path: "${{ env.PACKAGE_ROOT_PATH }}/debug/" if-no-files-found: 'error' compression-level: 9 retention-days: 1 + + - name: Release + if: success() && startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: "${{ env.PACKAGE_ROOT_PATH }}/**/*" \ No newline at end of file diff --git a/.github/workflows/build-win.yml b/.github/workflows/build-win.yml index fc01d436..8de954e9 100644 --- a/.github/workflows/build-win.yml +++ b/.github/workflows/build-win.yml @@ -3,14 +3,18 @@ name: Emu build (Windows) on: push: branches: [ - "ci-build-emu-win", + "ci-build-emu-win*", "ci-build-all" ] + tags: + - release* pull_request: branches: [ "dev" ] + workflow_dispatch: + # nothing permissions: - contents: read + contents: write env: # Expected format {owner}/{repo}. @@ -18,6 +22,8 @@ env: THIRD_PARTY_BASE_DIR: 'third-party' DEPS_CACHE_KEY: emu-deps-win DEPS_CACHE_DIR: build-win-deps + + PACKAGE_ROOT_PATH: "build-win/package" jobs: dependencies: @@ -96,6 +102,13 @@ jobs: path: "${{env.THIRD_PARTY_BASE_DIR}}/common/win" lfs: true + - name: Clone third-party deps (deps/win) + uses: actions/checkout@v4 + with: + repository: "${{env.DEPS_REPO}}" + ref: 'third-party/deps/win' + path: "${{env.THIRD_PARTY_BASE_DIR}}/deps/win" + ### build + upload release - name: Build release mode continue-on-error: true @@ -103,12 +116,18 @@ jobs: working-directory: ${{ github.workspace }} run: build_win.bat release - - name: Upload build (release) + - name: Package build (release) + if: success() + shell: cmd + working-directory: ${{ github.workspace }} + run: package_win.bat release + + - name: Upload build pacakge (release) if: success() uses: actions/upload-artifact@v4 with: name: "build-win-release-${{ github.sha }}" - path: 'build-win/release/' + path: "${{ env.PACKAGE_ROOT_PATH }}/release/" if-no-files-found: 'error' compression-level: 9 retention-days: 1 @@ -120,13 +139,25 @@ jobs: working-directory: ${{ github.workspace }} run: build_win.bat debug - - name: Upload build (debug) + - name: Package build (debug) + if: success() + shell: cmd + working-directory: ${{ github.workspace }} + run: package_win.bat debug + + - name: Upload build pacakge (debug) if: success() uses: actions/upload-artifact@v4 with: name: "build-win-debug-${{ github.sha }}" - path: 'build-win/debug/' + path: "${{ env.PACKAGE_ROOT_PATH }}/debug/" if-no-files-found: 'error' compression-level: 9 retention-days: 1 + + - name: Release + if: success() && startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: "${{ env.PACKAGE_ROOT_PATH }}/**/*" \ No newline at end of file diff --git a/build_win_clean.bat b/build_win_clean.bat index 12d8ff77..3c72e690 100644 --- a/build_win_clean.bat +++ b/build_win_clean.bat @@ -1,21 +1,21 @@ -@echo off - -setlocal -pushd "%~dp0" - -if /i "%~1"=="clean" ( - rmdir /s /q "build-win" >nul 2>&1 -) - -del /f /q *.exp >nul 2>&1 -del /f /q *.lib >nul 2>&1 -del /f /q *.a >nul 2>&1 -del /f /q *.obj >nul 2>&1 -del /f /q *.pdb >nul 2>&1 -del /f /q *.ilk >nul 2>&1 -del /f /q dll\net.pb.cc >nul 2>&1 -del /f /q dll\net.pb.h >nul 2>&1 -rmdir /s /q "build-win-temp" >nul 2>&1 - -endlocal -popd +@echo off + +setlocal +pushd "%~dp0" + +if /i "%~1"=="clean" ( + rmdir /s /q "build-win" >nul 2>&1 +) + +del /f /q *.exp >nul 2>&1 +del /f /q *.lib >nul 2>&1 +del /f /q *.a >nul 2>&1 +del /f /q *.obj >nul 2>&1 +del /f /q *.pdb >nul 2>&1 +del /f /q *.ilk >nul 2>&1 +del /f /q dll\net.pb.cc >nul 2>&1 +del /f /q dll\net.pb.h >nul 2>&1 +rmdir /s /q "build-win-temp" >nul 2>&1 + +endlocal +popd diff --git a/package_linux.sh b/package_linux.sh new file mode 100644 index 00000000..bbeac9a2 --- /dev/null +++ b/package_linux.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + + +if [ "$(id -u)" -ne 0 ]; then + echo "Please run as root" >&2 + exit 1 +fi + +build_base_dir="build-linux" +out_dir="build-linux/package" +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +[[ "$1" = '' ]] && { + echo "[X] missing build folder"; + exit 1; +} + +[[ -d "$script_dir/$build_base_dir/$1" ]] || { + echo "[X] build folder wasn't found"; + exit 1; +} + +apt update || exit 1 +apt install tar -y || exit 1 + +mkdir -p "$script_dir/$out_dir/$1" + +archive_file="$script_dir/$out_dir/$1/emu-linux-$1.tar.gz" +[[ -f "$archive_file" ]] && rm -f "$archive_file" +tar -C "$script_dir/$build_base_dir" -c -j -vf "$archive_file" "$1" diff --git a/package_win.bat b/package_win.bat new file mode 100644 index 00000000..5c6949f6 --- /dev/null +++ b/package_win.bat @@ -0,0 +1,48 @@ +@echo off + +setlocal +pushd "%~dp0" + +set /a last_code=0 + +set "build_base_dir=build-win" +set "out_dir=build-win\package" + +set /a MEM_PERCENT=90 +set /a DICT_SIZE_MB=384 +set /a THREAD_COUNT=13 +set "packager=third-party\deps\win\7za-win\7za.exe" + +if not exist "%packager%" ( + 1>&2 echo [X] packager app wasn't found + set /a last_code=1 + goto :script_end +) + +if "%~1"=="" ( + 1>&2 echo [X] missing build folder + set /a last_code=1 + goto :script_end +) + +if not exist "%build_base_dir%\%~1" ( + 1>&2 echo [X] build folder wasn't found + set /a last_code=1 + goto :script_end +) + +mkdir "%out_dir%\%~1" + +set "archive_file=%out_dir%\%~1\emu-win-%~1.7z" +if exist "%archive_file%" ( + del /f /q "%archive_file%" +) + +"%packager%" a "%archive_file%" ".\%build_base_dir%\%~1" -t7z -slp -ssw -mx -myx -mmemuse=p%MEM_PERCENT% -ms=on -mqs=off -mf=on -mhc+ -mhe- -m0=LZMA2:d=%DICT_SIZE_MB%m -mmt=%THREAD_COUNT% -mmtf+ -mtm- -mtc- -mta- -mtr+ + + +:script_end +popd +endlocal & ( + exit /b %last_code% +) diff --git a/scripts/package_linux.sh b/scripts/package_linux.sh new file mode 100644 index 00000000..904e3906 --- /dev/null +++ b/scripts/package_linux.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + + +if [ "$(id -u)" -ne 0 ]; then + echo "Please run as root" >&2 + exit 1 +fi + +build_dir="bin/linux" +tool_name="generate_emu_config" +out_dir="bin/package/linux" +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +[[ -d "$script_dir/$build_dir" ]] || { + echo "[X] build folder wasn't found" >&2 + exit 1 +} + +apt update || exit 1 +apt install tar -y || exit 1 + +mkdir -p "$script_dir/$out_dir" + +archive_file="$script_dir/$out_dir/$tool_name-linux.tar.gz" +[[ -f "$archive_file" ]] && rm -f "$archive_file" +tar -C "$script_dir/$build_dir" -c -j -vf "$archive_file" "$tool_name" diff --git a/scripts/package_win.bat b/scripts/package_win.bat new file mode 100644 index 00000000..a3b8f595 --- /dev/null +++ b/scripts/package_win.bat @@ -0,0 +1,43 @@ +@echo off + +setlocal +pushd "%~dp0" + +set /a last_code=0 + +set "build_dir=bin\win" +set "tool_name=generate_emu_config" +set "out_dir=bin\package\win" + +set /a MEM_PERCENT=90 +set /a DICT_SIZE_MB=384 +set /a THREAD_COUNT=13 +set "packager=..\third-party\deps\win\7za-win\7za.exe" + +if not exist "%packager%" ( + 1>&2 echo "[X] packager app wasn't found" + set /a last_code=1 + goto :script_end +) + +if not exist "%build_dir%" ( + 1>&2 echo "[X] build folder wasn't found" + set /a last_code=1 + goto :script_end +) + +mkdir "%out_dir%" + +set "archive_file=%out_dir%\%tool_name%-win.7z" +if exist "%archive_file%" ( + del /f /q "%archive_file%" +) + +"%packager%" a "%archive_file%" ".\%build_dir%\%tool_name%" -t7z -slp -ssw -mx -myx -mmemuse=p%MEM_PERCENT% -ms=on -mqs=off -mf=on -mhc+ -mhe- -m0=LZMA2:d=%DICT_SIZE_MB%m -mmt=%THREAD_COUNT% -mmtf+ -mtm- -mtc- -mta- -mtr+ + + +:script_end +popd +endlocal & ( + exit /b %last_code% +)