From 2259141bd2493eb1b88e74469e0784fcef06a3e0 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Thu, 3 Jul 2025 19:07:02 -0400 Subject: [PATCH] build(packaging): version number improvements (#4037) --- .github/workflows/ci-flatpak.yml | 12 ++-- .github/workflows/ci-homebrew.yml | 18 +++--- .github/workflows/ci-linux.yml | 6 +- .github/workflows/ci-windows.yml | 4 +- .github/workflows/ci.yml | 8 ++- cmake/compile_definitions/common.cmake | 3 - cmake/packaging/common.cmake | 5 +- cmake/prep/build_version.cmake | 78 ++++++++++++++++++++++---- docker/archlinux.dockerfile | 14 ++--- packaging/linux/Arch/PKGBUILD | 2 +- packaging/sunshine.rb | 2 +- src/confighttp.cpp | 3 +- src/entry_handler.cpp | 1 - src/main.cpp | 3 +- src/system_tray.cpp | 1 - src/version.h.in | 13 ----- 16 files changed, 104 insertions(+), 69 deletions(-) delete mode 100644 src/version.h.in diff --git a/.github/workflows/ci-flatpak.yml b/.github/workflows/ci-flatpak.yml index 647335f9..df02d98f 100644 --- a/.github/workflows/ci-flatpak.yml +++ b/.github/workflows/ci-flatpak.yml @@ -9,7 +9,7 @@ on: release_commit: required: true type: string - release_tag: + release_version: required: true type: string @@ -104,6 +104,7 @@ jobs: run: | # variables for manifest branch="${{ github.head_ref }}" + build_version=${{ inputs.release_version }} commit=${{ inputs.release_commit }} # check the branch variable @@ -111,7 +112,6 @@ jobs: then echo "This is a PUSH event" branch=${{ github.ref_name }} - build_version=${{ inputs.release_tag }} clone_url=${{ github.event.repository.clone_url }} else echo "This is a PR event" @@ -121,15 +121,17 @@ jobs: echo "Commit: ${commit}" echo "Clone URL: ${clone_url}" + export BRANCH=${branch} + export BUILD_VERSION=${build_version} + export CLONE_URL=${clone_url} + export COMMIT=${commit} + mkdir -p build mkdir -p artifacts cmake -DGITHUB_CLONE_URL=${clone_url} \ -B build \ -S . \ - -DBUILD_VERSION=${build_version} \ - -DGITHUB_BRANCH=${branch} \ - -DGITHUB_COMMIT=${commit} \ -DSUNSHINE_CONFIGURE_FLATPAK_MAN=ON \ -DSUNSHINE_CONFIGURE_ONLY=ON diff --git a/.github/workflows/ci-homebrew.yml b/.github/workflows/ci-homebrew.yml index 96ff3661..c8fdc9a2 100644 --- a/.github/workflows/ci-homebrew.yml +++ b/.github/workflows/ci-homebrew.yml @@ -76,13 +76,13 @@ jobs: run: | # variables for formula branch="${{ github.head_ref }}" + build_version=${{ inputs.release_version }} commit=${{ inputs.release_commit }} # check the branch variable if [ -z "$branch" ] then echo "This is a PUSH event" - build_version=${{ inputs.release_tag }} clone_url=${{ github.event.repository.clone_url }} branch="${{ github.ref_name }}" default_branch="${{ github.event.repository.default_branch }}" @@ -90,35 +90,31 @@ jobs: if [ "${{ matrix.release }}" == "true" ]; then # we will publish the formula with the release tag tag="${{ inputs.release_tag }}" - version="${{ inputs.release_version }}" else tag="${{ github.ref_name }}" - version="0.0.${{ github.run_number }}" fi else echo "This is a PR event" - build_version="0.0.${{ github.event.number }}" clone_url=${{ github.event.pull_request.head.repo.clone_url }} branch="${{ github.event.pull_request.head.ref }}" default_branch="${{ github.event.pull_request.head.repo.default_branch }}" tag="${{ github.event.pull_request.head.ref }}" - version="0.0.${{ github.event.number }}" fi echo "Branch: ${branch}" echo "Clone URL: ${clone_url}" echo "Tag: ${tag}" + export BRANCH=${branch} + export BUILD_VERSION=${build_version} + export CLONE_URL=${clone_url} + export COMMIT=${commit} + export TAG=${tag} + mkdir -p build cmake \ -B build \ -S . \ - -DBUILD_VERSION="${build_version}" \ - -DFORMULA_VERSION="${version}" \ - -DGITHUB_BRANCH="${branch}" \ - -DGITHUB_COMMIT="${commit}" \ - -DGITHUB_CLONE_URL="${clone_url}" \ -DGITHUB_DEFAULT_BRANCH="${default_branch}" \ - -DGITHUB_TAG="${tag}" \ -DSUNSHINE_CONFIGURE_HOMEBREW=ON \ -DSUNSHINE_CONFIGURE_ONLY=ON diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index afd16390..3e917505 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -9,7 +9,7 @@ on: release_commit: required: true type: string - release_tag: + release_version: required: true type: string @@ -87,7 +87,7 @@ jobs: - name: Build Linux env: BRANCH: ${{ github.head_ref || github.ref_name }} - BUILD_VERSION: ${{ inputs.release_tag }} + BUILD_VERSION: ${{ inputs.release_version }} COMMIT: ${{ inputs.release_commit }} run: | chmod +x ./scripts/linux_build.sh @@ -102,7 +102,7 @@ jobs: - name: Set AppImage Version if: matrix.name == 'AppImage' run: | - version=${{ inputs.release_tag }} + version=${{ inputs.release_version }} echo "VERSION=${version}" >> $GITHUB_ENV - name: Package Linux - AppImage diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index 23b8a588..e66f52da 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -9,7 +9,7 @@ on: release_commit: required: true type: string - release_tag: + release_version: required: true type: string secrets: @@ -257,7 +257,7 @@ jobs: shell: msys2 {0} env: BRANCH: ${{ github.head_ref || github.ref_name }} - BUILD_VERSION: ${{ inputs.release_tag }} + BUILD_VERSION: ${{ inputs.release_version }} CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} COMMIT: ${{ inputs.release_commit }} run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a390ca3..535f87b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,7 @@ jobs: publish_release: ${{ needs.release-setup.outputs.publish_release }} release_commit: ${{ needs.release-setup.outputs.release_commit }} release_tag: ${{ needs.release-setup.outputs.release_tag }} + release_version: ${{ needs.release-setup.outputs.release_version }} secrets: DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} @@ -87,10 +88,11 @@ jobs: uses: ./.github/workflows/ci-linux.yml with: release_commit: ${{ needs.release-setup.outputs.release_commit }} - release_tag: ${{ needs.release-setup.outputs.release_tag }} + release_version: ${{ needs.release-setup.outputs.release_version }} build-linux-copr: name: Linux Copr + if: github.event_name != 'push' # releases are handled directly in ci-copr.yml needs: release-setup uses: ./.github/workflows/ci-copr.yml secrets: @@ -104,7 +106,7 @@ jobs: uses: ./.github/workflows/ci-flatpak.yml with: release_commit: ${{ needs.release-setup.outputs.release_commit }} - release_tag: ${{ needs.release-setup.outputs.release_tag }} + release_version: ${{ needs.release-setup.outputs.release_version }} build-windows: name: Windows @@ -112,7 +114,7 @@ jobs: uses: ./.github/workflows/ci-windows.yml with: release_commit: ${{ needs.release-setup.outputs.release_commit }} - release_tag: ${{ needs.release-setup.outputs.release_tag }} + release_version: ${{ needs.release-setup.outputs.release_version }} secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/cmake/compile_definitions/common.cmake b/cmake/compile_definitions/common.cmake index 723a1a7a..f3873305 100644 --- a/cmake/compile_definitions/common.cmake +++ b/cmake/compile_definitions/common.cmake @@ -52,9 +52,6 @@ include_directories(BEFORE SYSTEM "${CMAKE_SOURCE_DIR}/third-party/nv-codec-head file(GLOB NVENC_SOURCES CONFIGURE_DEPENDS "src/nvenc/*.cpp" "src/nvenc/*.h") list(APPEND PLATFORM_TARGET_FILES ${NVENC_SOURCES}) -configure_file("${CMAKE_SOURCE_DIR}/src/version.h.in" version.h @ONLY) -include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}") # required for importing version.h - set(SUNSHINE_TARGET_FILES "${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/Input.h" "${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/Rtsp.h" diff --git a/cmake/packaging/common.cmake b/cmake/packaging/common.cmake index d8343219..a094f003 100644 --- a/cmake/packaging/common.cmake +++ b/cmake/packaging/common.cmake @@ -3,7 +3,10 @@ # common cpack options set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME}) set(CPACK_PACKAGE_VENDOR "LizardByte") -string(REGEX REPLACE "^v" "" CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) # remove the v prefix if it exists +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) set(CPACK_PACKAGE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cpack_artifacts) set(CPACK_PACKAGE_CONTACT "https://app.lizardbyte.dev") set(CPACK_PACKAGE_DESCRIPTION ${CMAKE_PROJECT_DESCRIPTION}) diff --git a/cmake/prep/build_version.cmake b/cmake/prep/build_version.cmake index e0d43380..80df777a 100644 --- a/cmake/prep/build_version.cmake +++ b/cmake/prep/build_version.cmake @@ -1,18 +1,34 @@ +# Set build variables if env variables are defined +# These are used in configured files such as manifests for different packages +if(DEFINED ENV{BRANCH}) # cmake-lint: disable=W0106 + set(GITHUB_BRANCH $ENV{BRANCH}) +endif() +if(DEFINED ENV{BUILD_VERSION}) # cmake-lint: disable=W0106 + set(BUILD_VERSION $ENV{BUILD_VERSION}) +endif() +if(DEFINED ENV{CLONE_URL}) # cmake-lint: disable=W0106 + set(GITHUB_CLONE_URL $ENV{CLONE_URL}) +endif() +if(DEFINED ENV{COMMIT}) # cmake-lint: disable=W0106 + set(GITHUB_COMMIT $ENV{COMMIT}) +endif() +if(DEFINED ENV{TAG}) # cmake-lint: disable=W0106 + set(GITHUB_TAG $ENV{TAG}) +endif() + # Check if env vars are defined before attempting to access them, variables will be defined even if blank -if((DEFINED ENV{BRANCH}) AND (DEFINED ENV{BUILD_VERSION}) AND (DEFINED ENV{COMMIT})) # cmake-lint: disable=W0106 - if(($ENV{BRANCH} STREQUAL "master") AND (NOT $ENV{BUILD_VERSION} STREQUAL "")) - # If BRANCH is "master" and BUILD_VERSION is not empty, then we are building a master branch - MESSAGE("Got from CI master branch and version $ENV{BUILD_VERSION}") +if((DEFINED ENV{BRANCH}) AND (DEFINED ENV{BUILD_VERSION})) # cmake-lint: disable=W0106 + if((DEFINED ENV{BRANCH}) AND (NOT $ENV{BUILD_VERSION} STREQUAL "")) + # If BRANCH is defined and BUILD_VERSION is not empty, then we are building from CI + # If BRANCH is master we are building a push/release build + MESSAGE("Got from CI '$ENV{BRANCH}' branch and version '$ENV{BUILD_VERSION}'") set(PROJECT_VERSION $ENV{BUILD_VERSION}) + string(REGEX REPLACE "^v" "" PROJECT_VERSION ${PROJECT_VERSION}) # remove the v prefix if it exists set(CMAKE_PROJECT_VERSION ${PROJECT_VERSION}) # cpack will use this to set the binary versions - elseif((DEFINED ENV{BRANCH}) AND (DEFINED ENV{COMMIT})) - # If BRANCH is set but not BUILD_VERSION we are building a PR, we gather only the commit hash - MESSAGE("Got from CI $ENV{BRANCH} branch and commit $ENV{COMMIT}") - set(PROJECT_VERSION ${PROJECT_VERSION}.$ENV{COMMIT}) endif() +else() # Generate Sunshine Version based of the git tag # https://github.com/nocnokneo/cmake-git-versioning-example/blob/master/LICENSE -else() find_package(Git) if(GIT_EXECUTABLE) MESSAGE("${CMAKE_SOURCE_DIR}") @@ -60,18 +76,24 @@ set(PROJECT_YEAR "1990") set(PROJECT_MONTH "01") set(PROJECT_DAY "01") -# Extract year, month, and day -if(PROJECT_VERSION MATCHES "^([0-9]{4})[.]([0-9]{3,4})") +# Extract year, month, and day (do this AFTER version parsing) +# Note: Cmake doesn't support "{}" regex syntax +if(PROJECT_VERSION MATCHES "^([0-9][0-9][0-9][0-9])\\.([0-9][0-9][0-9][0-9]?)\\.([0-9]+)$") + message("Extracting year and month/day from PROJECT_VERSION: ${PROJECT_VERSION}") # First capture group is the year set(PROJECT_YEAR "${CMAKE_MATCH_1}") - # Second capture group is month/day + # Second capture group contains month and day set(MONTH_DAY "${CMAKE_MATCH_2}") + + # Extract month (first 1-2 digits) and day (last 2 digits) string(LENGTH "${MONTH_DAY}" MONTH_DAY_LENGTH) if(MONTH_DAY_LENGTH EQUAL 3) + # Format: MDD (e.g., 703 = month 7, day 03) string(SUBSTRING "${MONTH_DAY}" 0 1 PROJECT_MONTH) string(SUBSTRING "${MONTH_DAY}" 1 2 PROJECT_DAY) elseif(MONTH_DAY_LENGTH EQUAL 4) + # Format: MMDD (e.g., 1203 = month 12, day 03) string(SUBSTRING "${MONTH_DAY}" 0 2 PROJECT_MONTH) string(SUBSTRING "${MONTH_DAY}" 2 2 PROJECT_DAY) endif() @@ -85,3 +107,35 @@ if(PROJECT_VERSION MATCHES "^([0-9]{4})[.]([0-9]{3,4})") set(PROJECT_DAY "0${PROJECT_DAY}") endif() endif() + +# Parse PROJECT_VERSION to extract major, minor, and patch components +if(PROJECT_VERSION MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)") + set(PROJECT_VERSION_MAJOR "${CMAKE_MATCH_1}") + set(CMAKE_PROJECT_VERSION_MAJOR "${CMAKE_MATCH_1}") + + set(PROJECT_VERSION_MINOR "${CMAKE_MATCH_2}") + set(CMAKE_PROJECT_VERSION_MINOR "${CMAKE_MATCH_2}") + + set(PROJECT_VERSION_PATCH "${CMAKE_MATCH_3}") + set(CMAKE_PROJECT_VERSION_PATCH "${CMAKE_MATCH_3}") +endif() + +message("PROJECT_NAME: ${PROJECT_NAME}") +message("PROJECT_VERSION: ${PROJECT_VERSION}") +message("PROJECT_VERSION_MAJOR: ${PROJECT_VERSION_MAJOR}") +message("PROJECT_VERSION_MINOR: ${PROJECT_VERSION_MINOR}") +message("PROJECT_VERSION_PATCH: ${PROJECT_VERSION_PATCH}") +message("CMAKE_PROJECT_VERSION: ${CMAKE_PROJECT_VERSION}") +message("CMAKE_PROJECT_VERSION_MAJOR: ${CMAKE_PROJECT_VERSION_MAJOR}") +message("CMAKE_PROJECT_VERSION_MINOR: ${CMAKE_PROJECT_VERSION_MINOR}") +message("CMAKE_PROJECT_VERSION_PATCH: ${CMAKE_PROJECT_VERSION_PATCH}") +message("PROJECT_YEAR: ${PROJECT_YEAR}") +message("PROJECT_MONTH: ${PROJECT_MONTH}") +message("PROJECT_DAY: ${PROJECT_DAY}") + +list(APPEND SUNSHINE_DEFINITIONS PROJECT_NAME="${PROJECT_NAME}") +list(APPEND SUNSHINE_DEFINITIONS PROJECT_VERSION="${PROJECT_VERSION}") +list(APPEND SUNSHINE_DEFINITIONS PROJECT_VERSION_MAJOR="${PROJECT_VERSION_MAJOR}") +list(APPEND SUNSHINE_DEFINITIONS PROJECT_VERSION_MINOR="${PROJECT_VERSION_MINOR}") +list(APPEND SUNSHINE_DEFINITIONS PROJECT_VERSION_PATCH="${PROJECT_VERSION_PATCH}") +list(APPEND SUNSHINE_DEFINITIONS PROJECT_VERSION_COMMIT="${GITHUB_COMMIT}") diff --git a/docker/archlinux.dockerfile b/docker/archlinux.dockerfile index 3a55dbbe..89071f60 100644 --- a/docker/archlinux.dockerfile +++ b/docker/archlinux.dockerfile @@ -28,6 +28,7 @@ ARG CLONE_URL ENV BRANCH=${BRANCH} ENV BUILD_VERSION=${BUILD_VERSION} ENV COMMIT=${COMMIT} +ENV CLONE_URL=${CLONE_URL} SHELL ["/bin/bash", "-o", "pipefail", "-c"] @@ -68,19 +69,16 @@ WORKDIR /build/sunshine/build RUN <<_MAKE #!/bin/bash set -e -if [[ "${BUILD_VERSION}" == '' ]]; then + +sub_version="" +if [[ "${BRANCH}" != "master" ]]; then sub_version=".r${COMMIT}" -else - sub_version="" fi + cmake \ + -DSUNSHINE_CONFIGURE_ONLY=ON \ -DSUNSHINE_CONFIGURE_PKGBUILD=ON \ -DSUNSHINE_SUB_VERSION="${sub_version}" \ - -DGITHUB_CLONE_URL="${CLONE_URL}" \ - -DGITHUB_BRANCH=${BRANCH} \ - -DGITHUB_BUILD_VERSION=${BUILD_VERSION} \ - -DGITHUB_COMMIT="${COMMIT}" \ - -DSUNSHINE_CONFIGURE_ONLY=ON \ /build/sunshine _MAKE diff --git a/packaging/linux/Arch/PKGBUILD b/packaging/linux/Arch/PKGBUILD index d0045cd9..eab48e31 100644 --- a/packaging/linux/Arch/PKGBUILD +++ b/packaging/linux/Arch/PKGBUILD @@ -67,7 +67,7 @@ prepare() { build() { export BRANCH="@GITHUB_BRANCH@" - export BUILD_VERSION="@GITHUB_BUILD_VERSION@" + export BUILD_VERSION="@BUILD_VERSION@" export COMMIT="@GITHUB_COMMIT@" export CC="gcc-${_gcc_version}" diff --git a/packaging/sunshine.rb b/packaging/sunshine.rb index 497b2670..ad7b46ee 100644 --- a/packaging/sunshine.rb +++ b/packaging/sunshine.rb @@ -6,7 +6,7 @@ class @PROJECT_NAME@ < Formula homepage "@PROJECT_HOMEPAGE_URL@" url "@GITHUB_CLONE_URL@", tag: "@GITHUB_TAG@" - version "@FORMULA_VERSION@" + version "@BUILD_VERSION@" license all_of: ["GPL-3.0-only"] head "@GITHUB_CLONE_URL@", branch: "@GITHUB_DEFAULT_BRANCH@" diff --git a/src/confighttp.cpp b/src/confighttp.cpp index 059b6242..09dd671c 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -34,7 +34,6 @@ #include "process.h" #include "utility.h" #include "uuid.h" -#include "version.h" using namespace std::literals; @@ -843,7 +842,7 @@ namespace confighttp { nlohmann::json output_tree; output_tree["status"] = true; output_tree["platform"] = SUNSHINE_PLATFORM; - output_tree["version"] = PROJECT_VER; + output_tree["version"] = PROJECT_VERSION; auto vars = config::parse_config(file_handler::read_file(config::sunshine.config_file.c_str())); diff --git a/src/entry_handler.cpp b/src/entry_handler.cpp index ed978dcd..9ac07649 100644 --- a/src/entry_handler.cpp +++ b/src/entry_handler.cpp @@ -16,7 +16,6 @@ #include "logging.h" #include "network.h" #include "platform/common.h" -#include "version.h" extern "C" { #ifdef _WIN32 diff --git a/src/main.cpp b/src/main.cpp index 7f71f7fb..81739488 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,6 @@ #include "process.h" #include "system_tray.h" #include "upnp.h" -#include "version.h" #include "video.h" extern "C" { @@ -123,7 +122,7 @@ int main(int argc, char *argv[]) { // logging can begin at this point // if anything is logged prior to this point, it will appear in stdout, but not in the log viewer in the UI // the version should be printed to the log before anything else - BOOST_LOG(info) << PROJECT_NAME << " version: " << PROJECT_VER; + BOOST_LOG(info) << PROJECT_NAME << " version: " << PROJECT_VERSION << " commit: " << PROJECT_VERSION_COMMIT; // Log publisher metadata log_publisher_data(); diff --git a/src/system_tray.cpp b/src/system_tray.cpp index 621a809c..f792c741 100644 --- a/src/system_tray.cpp +++ b/src/system_tray.cpp @@ -42,7 +42,6 @@ #include "platform/common.h" #include "process.h" #include "src/entry_handler.h" - #include "version.h" using namespace std::literals; diff --git a/src/version.h.in b/src/version.h.in deleted file mode 100644 index 49d1386b..00000000 --- a/src/version.h.in +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @file src/version.h.in - * @brief Version definitions for Sunshine. - * @note The final `version.h` is generated from this file during the CMake build. - * @todo Use CMake definitions directly, instead of configuring this file. - */ -#pragma once - -#define PROJECT_NAME "@PROJECT_NAME@" -#define PROJECT_VER "@PROJECT_VERSION@" -#define PROJECT_VER_MAJOR "@PROJECT_VERSION_MAJOR@" -#define PROJECT_VER_MINOR "@PROJECT_VERSION_MINOR@" -#define PROJECT_VER_PATCH "@PROJECT_VERSION_PATCH@"