From c29c917474ddcf76042b3f58465015018c1f3ae7 Mon Sep 17 00:00:00 2001 From: Elia Zammuto Date: Fri, 10 Mar 2023 00:13:57 +0100 Subject: [PATCH] Versioning improvements (#768) Co-authored-by: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> --- .dockerignore | 6 +- .github/workflows/CI.yml | 24 +++++-- CMakeLists.txt | 64 ++++++++++++++++- docker/archlinux.dockerfile | 6 ++ docker/debian-bullseye.dockerfile | 10 +++ docker/fedora-36.dockerfile | 10 +++ docker/fedora-37.dockerfile | 10 +++ docker/ubuntu-20.04.dockerfile | 10 +++ docker/ubuntu-22.04.dockerfile | 10 +++ src/confighttp.cpp | 2 + src/main.cpp | 2 +- version.h.in => src/version.h.in | 2 +- src_assets/common/assets/web/config.html | 16 +++-- src_assets/common/assets/web/index.html | 90 ++++++++++++++++++++++++ 14 files changed, 243 insertions(+), 19 deletions(-) rename version.h.in => src/version.h.in (82%) diff --git a/.dockerignore b/.dockerignore index 2de6c8e8..6ada538c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,9 @@ -# ignore git files -.git* - # ignore hidden files .* +# do not ignore .git, needed for versioning +!/.git + # ignore repo directories and files docs/ scripts/ diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ae875749..509cf93f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -46,6 +46,7 @@ jobs: last_version: ${{ steps.verify_changelog.outputs.latest_release_tag_name }} release_body: ${{ steps.verify_changelog.outputs.changelog_parser_description }} + # todo - remove this job once versioning is fully automated by cmake check_versions: name: Check Versions runs-on: ubuntu-latest @@ -362,6 +363,10 @@ jobs: sudo rm /root/cuda.run - name: Build Linux + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + BUILD_VERSION: ${{ needs.check_changelog.outputs.next_version_bare }} + COMMIT: ${{ github.event.pull_request.head.sha || github.sha }} run: | mkdir -p build mkdir -p artifacts @@ -485,6 +490,10 @@ jobs: ln -sf /usr/local/opt/openssl/include/openssl /usr/local/include/openssl - name: Build MacOS + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + BUILD_VERSION: ${{ needs.check_changelog.outputs.next_version_bare }} + COMMIT: ${{ github.event.pull_request.head.sha || github.sha }} run: | npm install @@ -590,7 +599,8 @@ jobs: mkdir build cd build - cmake -DGITHUB_COMMIT=${commit} \ + cmake \ + -DGITHUB_COMMIT=${commit} \ -DGITHUB_CLONE_URL=${clone_url} \ -DSUNSHINE_CONFIGURE_PORTFILE=ON \ -DSUNSHINE_CONFIGURE_ONLY=ON \ @@ -641,6 +651,8 @@ jobs: echo "subportlist=${subportlist}" >> $GITHUB_OUTPUT - name: Run port lint for all subports + env: + subportlist: ${{ steps.subportlist.outputs.subportlist }} run: | set -eu fail=0 @@ -662,10 +674,10 @@ jobs: echo "::endgroup::" done exit "$fail" - env: - subportlist: ${{ steps.subportlist.outputs.subportlist }} - name: Build subports + env: + subportlist: ${{ steps.subportlist.outputs.subportlist }} run: | set -eu fail=0 @@ -714,8 +726,6 @@ jobs: echo "::endgroup::" done exit "$fail" - env: - subportlist: ${{ steps.subportlist.outputs.subportlist }} - name: Package run: | @@ -795,6 +805,10 @@ jobs: - name: Build Windows shell: msys2 {0} + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + BUILD_VERSION: ${{ needs.check_changelog.outputs.next_version_bare }} + COMMIT: ${{ github.event.pull_request.head.sha || github.sha }} run: | mkdir build cd build diff --git a/CMakeLists.txt b/CMakeLists.txt index 156c1e63..730775ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.18) # `CMAKE_CUDA_ARCHITECTURES` requires 3.18 +# todo - set version to 0.0.0 once confident in automated versioning project(Sunshine VERSION 0.18.4 DESCRIPTION "Sunshine is a self-hosted game stream host for Moonlight." HOMEPAGE_URL "https://app.lizardbyte.dev") @@ -10,6 +11,65 @@ and Nvidia GPUs for hardware encoding. Software encoding is also available. You Moonlight client on a variety of devices. A web UI is provided to allow configuration, and client pairing, from \ your favorite web browser. Pair from the local server or any mobile device.") +# 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}") + set(PROJECT_VERSION $ENV{BUILD_VERSION}) + elseif((DEFINED ENV{BRANCH}) AND (DEFINED ENV{COMMIT})) + # If BRANCH is set but not BUILD_VERSION we are building nightly, 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() +# 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_CURRENT_SOURCE_DIR}") + get_filename_component(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) + #Get current Branch + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + #WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_DESCRIBE_BRANCH + RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + # Gather current commit + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + #WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_DESCRIBE_VERSION + RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + # Check if Dirty + execute_process( + COMMAND ${GIT_EXECUTABLE} diff --quiet --exit-code + #WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_IS_DIRTY + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT GIT_DESCRIBE_ERROR_CODE) + MESSAGE("Sunshine Branch: ${GIT_DESCRIBE_BRANCH}") + if(NOT GIT_DESCRIBE_BRANCH STREQUAL "master") + set(PROJECT_VERSION ${PROJECT_VERSION}.${GIT_DESCRIBE_VERSION}) + MESSAGE("Sunshine Version: ${GIT_DESCRIBE_VERSION}") + endif() + if(GIT_IS_DIRTY) + set(PROJECT_VERSION ${PROJECT_VERSION}.dirty) + MESSAGE("Git tree is dirty!") + endif() + else() + MESSAGE(ERROR ": Got git error while fetching tags: ${GIT_DESCRIBE_ERROR_CODE}") + endif() + else() + MESSAGE(WARNING ": Git not found, cannot find git version") + endif() +endif() + option(SUNSHINE_CONFIGURE_APPIMAGE "Configuration specific for AppImage." OFF) option(SUNSHINE_CONFIGURE_AUR "Configure files required for AUR." OFF) option(SUNSHINE_CONFIGURE_FLATPAK_MAN "Configure manifest file required for Flatpak build." OFF) @@ -75,7 +135,7 @@ pkg_check_modules(CURL REQUIRED libcurl) if(WIN32) set(Boost_USE_STATIC_LIBS ON) # cmake-lint: disable=C0103 # workaround to prevent link errors against icudata, icui18n - set(Boost_NO_BOOST_CMAKE ON) # cmake-lint: disable=C0103 + set(Boost_NO_BOOST_CMAKE ON) # cmake-lint: disable=C0103 endif() find_package(Boost COMPONENTS locale log filesystem program_options REQUIRED) @@ -396,7 +456,7 @@ ${CMAKE_BINARY_DIR}/generated-src/${filename}.h") configure_file(sunshine.service.in sunshine.service @ONLY) endif() -configure_file(version.h.in version.h @ONLY) +configure_file(src/version.h.in version.h @ONLY) include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(SUNSHINE_TARGET_FILES diff --git a/docker/archlinux.dockerfile b/docker/archlinux.dockerfile index ab99c5ed..5b2d7a60 100644 --- a/docker/archlinux.dockerfile +++ b/docker/archlinux.dockerfile @@ -22,11 +22,16 @@ RUN useradd -m builder && \ FROM sunshine-base as sunshine-build +ARG BRANCH ARG BUILD_VERSION ARG COMMIT ARG CLONE_URL # note: BUILD_VERSION may be blank +ENV BRANCH=${BRANCH} +ENV BUILD_VERSION=${BUILD_VERSION} +ENV COMMIT=${COMMIT} + SHELL ["/bin/bash", "-o", "pipefail", "-c"] # install dependencies # cuda, libcap, and libdrm are optional dependencies for PKGBUILD @@ -37,6 +42,7 @@ pacman -Syu --noconfirm \ base-devel \ cmake \ cuda \ + git \ libcap \ libdrm \ namcap diff --git a/docker/debian-bullseye.dockerfile b/docker/debian-bullseye.dockerfile index 3b7faed0..1d2d0fcf 100644 --- a/docker/debian-bullseye.dockerfile +++ b/docker/debian-bullseye.dockerfile @@ -14,6 +14,15 @@ FROM sunshine-base as sunshine-build ARG TARGETPLATFORM RUN echo "target_platform: ${TARGETPLATFORM}" +ARG BRANCH +ARG BUILD_VERSION +ARG COMMIT +# note: BUILD_VERSION may be blank + +ENV BRANCH=${BRANCH} +ENV BUILD_VERSION=${BUILD_VERSION} +ENV COMMIT=${COMMIT} + SHELL ["/bin/bash", "-o", "pipefail", "-c"] # install dependencies RUN <<_DEPS @@ -23,6 +32,7 @@ apt-get update -y apt-get install -y --no-install-recommends \ build-essential=12.9* \ cmake=3.18.4* \ + git=1:2.30.2* \ libavdevice-dev=7:4.3.* \ libboost-filesystem-dev=1.74.0* \ libboost-locale-dev=1.74.0* \ diff --git a/docker/fedora-36.dockerfile b/docker/fedora-36.dockerfile index 36a40718..e6d88b1b 100644 --- a/docker/fedora-36.dockerfile +++ b/docker/fedora-36.dockerfile @@ -12,6 +12,15 @@ FROM sunshine-base as sunshine-build ARG TARGETPLATFORM RUN echo "target_platform: ${TARGETPLATFORM}" +ARG BRANCH +ARG BUILD_VERSION +ARG COMMIT +# note: BUILD_VERSION may be blank + +ENV BRANCH=${BRANCH} +ENV BUILD_VERSION=${BUILD_VERSION} +ENV COMMIT=${COMMIT} + SHELL ["/bin/bash", "-o", "pipefail", "-c"] # install dependencies # hadolint ignore=DL3041 @@ -25,6 +34,7 @@ dnf -y install \ cmake-3.22.2* \ gcc-12.0.1* \ gcc-c++-12.0.1* \ + git-2.39.2* \ libcap-devel-2.48* \ libcurl-devel-7.82.0* \ libdrm-devel-2.4.110* \ diff --git a/docker/fedora-37.dockerfile b/docker/fedora-37.dockerfile index a9cf1182..54dfd8dd 100644 --- a/docker/fedora-37.dockerfile +++ b/docker/fedora-37.dockerfile @@ -12,6 +12,15 @@ FROM sunshine-base as sunshine-build ARG TARGETPLATFORM RUN echo "target_platform: ${TARGETPLATFORM}" +ARG BRANCH +ARG BUILD_VERSION +ARG COMMIT +# note: BUILD_VERSION may be blank + +ENV BRANCH=${BRANCH} +ENV BUILD_VERSION=${BUILD_VERSION} +ENV COMMIT=${COMMIT} + SHELL ["/bin/bash", "-o", "pipefail", "-c"] # install dependencies # hadolint ignore=DL3041 @@ -25,6 +34,7 @@ dnf -y install \ cmake-3.24.1* \ gcc-12.2.1* \ gcc-c++-12.2.1* \ + git-2.39.2* \ libcap-devel-2.48* \ libcurl-devel-7.85.0* \ libdrm-devel-2.4.112* \ diff --git a/docker/ubuntu-20.04.dockerfile b/docker/ubuntu-20.04.dockerfile index 5012a025..dbc37ecb 100644 --- a/docker/ubuntu-20.04.dockerfile +++ b/docker/ubuntu-20.04.dockerfile @@ -14,6 +14,15 @@ FROM sunshine-base as sunshine-build ARG TARGETPLATFORM RUN echo "target_platform: ${TARGETPLATFORM}" +ARG BRANCH +ARG BUILD_VERSION +ARG COMMIT +# note: BUILD_VERSION may be blank + +ENV BRANCH=${BRANCH} +ENV BUILD_VERSION=${BUILD_VERSION} +ENV COMMIT=${COMMIT} + SHELL ["/bin/bash", "-o", "pipefail", "-c"] # install dependencies RUN <<_DEPS @@ -24,6 +33,7 @@ apt-get install -y --no-install-recommends \ build-essential=12.8* \ gcc-10=10.3.0* \ g++-10=10.3.0* \ + git=1:2.25.1* \ libavdevice-dev=7:4.2.* \ libboost-filesystem-dev=1.71.0* \ libboost-locale-dev=1.71.0* \ diff --git a/docker/ubuntu-22.04.dockerfile b/docker/ubuntu-22.04.dockerfile index 79aca5eb..ec13e684 100644 --- a/docker/ubuntu-22.04.dockerfile +++ b/docker/ubuntu-22.04.dockerfile @@ -14,6 +14,15 @@ FROM sunshine-base as sunshine-build ARG TARGETPLATFORM RUN echo "target_platform: ${TARGETPLATFORM}" +ARG BRANCH +ARG BUILD_VERSION +ARG COMMIT +# note: BUILD_VERSION may be blank + +ENV BRANCH=${BRANCH} +ENV BUILD_VERSION=${BUILD_VERSION} +ENV COMMIT=${COMMIT} + SHELL ["/bin/bash", "-o", "pipefail", "-c"] # install dependencies RUN <<_DEPS @@ -23,6 +32,7 @@ apt-get update -y apt-get install -y --no-install-recommends \ build-essential=12.9* \ cmake=3.22.1* \ + git=1:2.34.1* \ libavdevice-dev=7:4.4.* \ libboost-filesystem-dev=1.74.0* \ libboost-locale-dev=1.74.0* \ diff --git a/src/confighttp.cpp b/src/confighttp.cpp index 7425e7f5..5f54aebb 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -33,6 +33,7 @@ #include "rtsp.h" #include "utility.h" #include "uuid.h" +#include "version.h" using namespace std::literals; @@ -503,6 +504,7 @@ void getConfig(resp_https_t response, req_https_t request) { outputTree.put("status", "true"); outputTree.put("platform", SUNSHINE_PLATFORM); + outputTree.put("version", PROJECT_VER); outputTree.put("restart_supported", platf::restart_supported()); auto vars = config::parse_config(read_file(config::sunshine.config_file.c_str())); diff --git a/src/main.cpp b/src/main.cpp index 34ccef9d..b02354fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -298,7 +298,7 @@ int main(int argc, char *argv[]) { return fn->second(argv[0], config::sunshine.cmd.argc, config::sunshine.cmd.argv); } - + BOOST_LOG(info) << PROJECT_NAME << " version: " << PROJECT_VER << std::endl; task_pool.start(1); // Create signal handler after logging has been initialized diff --git a/version.h.in b/src/version.h.in similarity index 82% rename from version.h.in rename to src/version.h.in index 5deb996b..2be10bf6 100644 --- a/version.h.in +++ b/src/version.h.in @@ -5,6 +5,6 @@ #define PROJECT_VER "@PROJECT_VERSION@" #define PROJECT_VER_MAJOR "@PROJECT_VERSION_MAJOR@" #define PROJECT_VER_MINOR "@PROJECT_VERSION_MINOR@" -#define PTOJECT_VER_PATCH "@PROJECT_VERSION_PATCH@" +#define PROJECT_VER_PATCH "@PROJECT_VERSION_PATCH@" #endif // INCLUDE_GUARD diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index d5c8daba..2a0efaa7 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -973,25 +973,27 @@ this.restart_supported = (this.config.restart_supported === "true"); var app = document.getElementById("app"); - if (this.platform == "windows") { + if (this.platform === "windows") { this.tabs = this.tabs.filter((el) => { return el.id !== "va-api" && el.id !== "vt"; }); } - if (this.platform == "linux") { + if (this.platform === "linux") { this.tabs = this.tabs.filter((el) => { return el.id !== "amd" && el.id !== "qsv" && el.id !== "vt"; }); } - if (this.platform == "macos") { + if (this.platform === "macos") { this.tabs = this.tabs.filter((el) => { return el.id !== "amd" && el.id !== "nv" && el.id !== "qsv" && el.id !== "va-api"; }); } - delete this.config.status; + // remove values we don't want in the config file delete this.config.platform; delete this.config.restart_supported; + delete this.config.status; + delete this.config.version; //Populate default values if not present in config this.config.key_rightalt_to_key_win = this.config.key_rightalt_to_key_win || "disabled"; @@ -1057,7 +1059,7 @@ method: "POST", body: JSON.stringify(this.config), }).then((r) => { - if (r.status == 200) this.saved = true; + if (r.status === 200) this.saved = true; }); }, apply() { @@ -1067,11 +1069,11 @@ method: "POST", body: JSON.stringify(this.config), }).then((r) => { - if (r.status == 200) { + if (r.status === 200) { fetch("/api/restart", { method: "POST", }).then((r) => { - if (r.status == 200) this.restarted = true; + if (r.status === 200) this.restarted = true; }); } }); diff --git a/src_assets/common/assets/web/index.html b/src_assets/common/assets/web/index.html index a5d86505..b06d7146 100644 --- a/src_assets/common/assets/web/index.html +++ b/src_assets/common/assets/web/index.html @@ -1,6 +1,44 @@

Hello, Sunshine!

Sunshine is a self-hosted game stream host for Moonlight.

+ +
+
+

Version {{version}}

+
+
+ Thank you for helping to make Sunshine a better software! 🌇 +
+
+ Loading Latest Release... +
+
+
+ You're running the latest version of Sunshine +
+
+
+
+
+
A new Nightly Version is Available!
+ Download +
+
{{nightlyData.head_sha}}
+
{{nightlyData.display_title}}
+
+
+
+
+
+
A new Stable Version is Available!
+ Download +
+

{{githubVersion.name}}

+
{{githubVersion.body}}
+
+
+
+
@@ -35,3 +73,55 @@
+ +