diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6b1eb296b47..29e19cfe282 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -637,6 +637,100 @@ jobs: discussionCategory: announcements prerelease: ${{ needs.setup_release.outputs.pre_release }} + build_mac_brew: + needs: [check_changelog, setup_release] + strategy: + fail-fast: false # false to test all, true to fail entire job if any fail + matrix: + include: + # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories + # while GitHub has larger macOS runners, they are not available for our repos :( + - os_version: "12" + release: true + - os_version: "13" + - os_version: "14" + name: Homebrew (macOS-${{ matrix.os_version }}) + runs-on: macos-${{ matrix.os_version }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Dependencies Homebrew + run: | + # install dependencies using homebrew + brew install cmake + + - name: Configure formula + run: | + # variables for formula + branch=${GITHUB_HEAD_REF} + + # check the branch variable + if [ -z "$branch" ] + then + echo "This is a PUSH event" + commit=${{ github.sha }} + clone_url=${{ github.event.repository.clone_url }} + source_tarball=${{ github.event.repository.html_url }}/archive/${commit}.tar.gz + branch="${{ github.ref_name }}" + else + echo "This is a PR event" + commit=${{ github.event.pull_request.head.sha }} + clone_url=${{ github.event.pull_request.head.repo.clone_url }} + source_tarball=${{ github.event.pull_request.head.repo.html_url }}/archive/${commit}.tar.gz + branch="${{ github.event.pull_request.head.ref }}" + fi + echo "Commit: ${commit}" + echo "Clone URL: ${clone_url}" + + mkdir build + cd build + cmake \ + -DGITHUB_COMMIT="${commit}" \ + -DGITHUB_CLONE_URL="${clone_url}" \ + -DGITHUB_BRANCH="${branch}" \ + -DSUNSHINE_CONFIGURE_HOMEBREW=ON \ + -DSUNSHINE_CONFIGURE_ONLY=ON \ + .. + cd .. + + # copy formula to artifacts + mkdir -p artifacts + cp -f ./build/sunshine.rb ./artifacts/ + + # move formula to build/Formula + mkdir -p build/Formula + mv ./build/sunshine.rb ./build/Formula/sunshine.rb + + # testing + cat ./artifacts/sunshine.rb + + - name: Install formula + run: | + brew install ./build/Formula/sunshine.rb + + - name: Upload Artifacts + if: ${{ matrix.release }} + uses: actions/upload-artifact@v4 + with: + name: sunshine-homebrew + path: artifacts/ + + - name: Create/Update GitHub Release + if: ${{ needs.setup_release.outputs.create_release == 'true' && matrix.release }} + uses: ncipollo/release-action@v1 + with: + name: ${{ needs.setup_release.outputs.release_name }} + tag: ${{ needs.setup_release.outputs.release_tag }} + commit: ${{ needs.setup_release.outputs.release_commit }} + artifacts: "*artifacts/*" + token: ${{ secrets.GH_BOT_TOKEN }} + allowUpdates: true + body: ${{ needs.setup_release.outputs.release_body }} + discussionCategory: announcements + prerelease: ${{ needs.setup_release.outputs.pre_release }} + build_mac_port: needs: [check_changelog, setup_release] strategy: diff --git a/cmake/prep/options.cmake b/cmake/prep/options.cmake index 9104320d31d..4c7459c616f 100644 --- a/cmake/prep/options.cmake +++ b/cmake/prep/options.cmake @@ -13,6 +13,8 @@ option(CUDA_INHERIT_COMPILE_OPTIONS your IDE throws errors about unknown flags after running cmake." ON) if(APPLE) + option(SUNSHINE_CONFIGURE_HOMEBREW + "Configure macOS Homebrew formula. Recommended to use with SUNSHINE_CONFIGURE_ONLY" OFF) option(SUNSHINE_CONFIGURE_PORTFILE "Configure macOS Portfile. Recommended to use with SUNSHINE_CONFIGURE_ONLY" OFF) option(SUNSHINE_PACKAGE_MACOS diff --git a/cmake/prep/special_package_configuration.cmake b/cmake/prep/special_package_configuration.cmake index a5a780f5563..695b6e443c2 100644 --- a/cmake/prep/special_package_configuration.cmake +++ b/cmake/prep/special_package_configuration.cmake @@ -2,6 +2,9 @@ if (APPLE) if(${SUNSHINE_CONFIGURE_PORTFILE}) configure_file(packaging/macos/Portfile Portfile @ONLY) endif() + if(${SUNSHINE_CONFIGURE_HOMEBREW}) + configure_file(packaging/macos/sunshine.rb sunshine.rb @ONLY) + endif() elseif (UNIX) include(GNUInstallDirs) # this needs to be included prior to configuring the desktop files diff --git a/packaging/macos/sunshine.rb b/packaging/macos/sunshine.rb new file mode 100644 index 00000000000..bc7c68b67f1 --- /dev/null +++ b/packaging/macos/sunshine.rb @@ -0,0 +1,51 @@ +require "language/node" + +class @PROJECT_NAME@ < Formula + desc "@PROJECT_DESCRIPTION@" + homepage "@PROJECT_HOMEPAGE_URL@" + url "@GITHUB_CLONE_URL@", + tag: "@GITHUB_BRANCH@" + version "@PROJECT_VERSION@" + license all_of: ["GPL-3.0-only"] + head "@GITHUB_CLONE_URL@" + + depends_on "boost" => :build + depends_on "cmake" => :build + depends_on "pkg-config" => :build + depends_on "curl" + depends_on "miniupnpc" + depends_on "node" + depends_on "openssl" + depends_on "opus" + + def install + # initialize submodules + system "git", "submodule", "update", "--remote", "--init", "--recursive", "--depth", "1" + + # todo: fix vite build + system "sed", "-i", "''", "s/SUNSHINE_SOURCE_ASSETS_DIR=${SUNSHINE_SOURCE_ASSETS_DIR} SUNSHINE_ASSETS_DIR=${CMAKE_BINARY_DIR}//", "cmake/targets/common.cmake" + + args = %W[ + -DBUIld_WERROR=ON + -DOPENSSL_ROOT_DIR=#{Formula["openssl"].opt_prefix} + -DSUNSHINE_ASSETS_DIR=sunshine/assets + ] + system "cmake", "-S", ".", "-B", "build", *std_cmake_args, *args + + cd "build" do + system "make", "-j" + system "make", "install" + end + end + + service do + run [opt_bin/"sunshine", "~/.config/sunshine/sunshine.conf"] + end + + test do + # test that the binary runs at all + shell_output("#{bin}/sunshine --version").strip + + # todo: add unit tests + end +end