Files
BiLauncher/cmake/LauncherVersion.cmake
galeon 1817157e4d
tests / package-smoke-linux (push) Skipped
tests / package-smoke-windows (push) Skipped
tests / package-smoke-macos (push) Skipped
tests / windows (pull_request) Skipped
tests / macos (pull_request) Skipped
tests / package-smoke-linux (pull_request) Skipped
tests / package-smoke-windows (pull_request) Skipped
tests / package-smoke-macos (pull_request) Skipped
tests / macos (push) Successful in 1m19s
tests / linux (push) Successful in 5m48s
tests / linux (pull_request) Successful in 5m20s
tests / windows (push) Canceled after 30m5s
release pipeline fixes
Signed-off-by: galeon <dertiellis@gmail.com>
2026-10-24 21:45:45 +03:00

102 lines
4.4 KiB
CMake
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Полная версия лаунчера и канал сборки (dev / rc / release).
#
# В репозитории хранится только число X.Y.Z из project(), одинаковое во всех
# ветках, — поэтому merge dev → rc → master не трогает версию. Канал
# вычисляется при сборке (по убыванию приоритета):
# 1. LAUNCHER_BUILD_VERSION — полная версия от CI: 1.0.1, 1.0.1-rc2;
# 2. тег на HEAD: vX.Y.Z — релиз, vX.Y.Z-rcN — rc;
# 3. ветка (из переменных CI или git): master — релиз, rc/beta — rc;
# 4. всё остальное, в т.ч. сборка без git, — dev.
#
# Работает в двух режимах:
# include() при configure — проверяет входные данные и пишет заголовок;
# cmake -P на каждой сборке — чтобы после git checkout без reconfigure
# канал и хэш коммита не устаревали.
# Входные переменные: LAUNCHER_VERSION_NUMERIC, LAUNCHER_SOURCE_DIR,
# LAUNCHER_VERSION_HEADER, LAUNCHER_BUILD_VERSION (необязательна).
# Результат: LAUNCHER_VERSION, LAUNCHER_CHANNEL и файл LAUNCHER_VERSION_HEADER.
set(_numeric "${LAUNCHER_VERSION_NUMERIC}")
find_package(Git QUIET)
function(_launcher_git out)
set(${out} "" PARENT_SCOPE)
if(NOT GIT_EXECUTABLE)
return()
endif()
execute_process(COMMAND "${GIT_EXECUTABLE}" ${ARGN}
WORKING_DIRECTORY "${LAUNCHER_SOURCE_DIR}"
RESULT_VARIABLE _rc OUTPUT_VARIABLE _out ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(_rc EQUAL 0)
set(${out} "${_out}" PARENT_SCOPE)
endif()
endfunction()
set(_full "")
if(LAUNCHER_BUILD_VERSION)
set(_full "${LAUNCHER_BUILD_VERSION}")
string(REGEX REPLACE "^v" "" _full "${_full}")
string(REGEX REPLACE "-.*$" "" _base "${_full}")
if(NOT _base STREQUAL _numeric)
message(FATAL_ERROR "LAUNCHER_BUILD_VERSION=${LAUNCHER_BUILD_VERSION} не совпадает "
"с project(BiLauncher VERSION ${_numeric})")
endif()
else()
# Тег vX.Y.Z или vX.Y.Z-rcN ровно на HEAD, относящийся к текущей версии
_launcher_git(_tags tag --points-at HEAD)
string(REPLACE "\n" ";" _tags "${_tags}")
string(REPLACE "." "\\." _numeric_re "${_numeric}")
foreach(_tag IN LISTS _tags)
if(_tag MATCHES "^v(${_numeric_re}(-rc[0-9]+)?)$")
# Релизный тег важнее rc-тега на том же коммите
if(NOT _full OR NOT CMAKE_MATCH_2)
set(_full "${CMAKE_MATCH_1}")
endif()
endif()
endforeach()
endif()
if(_full)
if(_full MATCHES "-rc[0-9]*$")
set(LAUNCHER_CHANNEL "rc")
elseif(_full STREQUAL _numeric)
set(LAUNCHER_CHANNEL "release")
else()
set(LAUNCHER_CHANNEL "dev")
endif()
set(LAUNCHER_VERSION "${_full}")
else()
# В CI на detached HEAD имени ветки в git нет — берём его из окружения
set(_branch "$ENV{GITHUB_HEAD_REF}")
if(NOT _branch AND "$ENV{GITHUB_REF_TYPE}" STREQUAL "branch")
set(_branch "$ENV{GITHUB_REF_NAME}")
endif()
if(NOT _branch)
_launcher_git(_branch rev-parse --abbrev-ref HEAD)
endif()
if(_branch STREQUAL "master")
set(LAUNCHER_CHANNEL "release")
set(LAUNCHER_VERSION "${_numeric}")
elseif(_branch STREQUAL "rc" OR _branch STREQUAL "beta")
set(LAUNCHER_CHANNEL "rc")
set(LAUNCHER_VERSION "${_numeric}-rc")
else()
set(LAUNCHER_CHANNEL "dev")
set(LAUNCHER_VERSION "${_numeric}-dev")
_launcher_git(_hash rev-parse --short=7 HEAD)
if(_hash)
# Неотслеживаемые файлы (каталоги сборки и т.п.) не считаем
execute_process(COMMAND "${GIT_EXECUTABLE}" diff --quiet HEAD --
WORKING_DIRECTORY "${LAUNCHER_SOURCE_DIR}" RESULT_VARIABLE _dirty ERROR_QUIET)
if(NOT _dirty EQUAL 0)
set(_hash "${_hash}.dirty")
endif()
string(APPEND LAUNCHER_VERSION "+${_hash}")
endif()
endif()
endif()
configure_file("${CMAKE_CURRENT_LIST_DIR}/launcherversion.h.in" "${LAUNCHER_VERSION_HEADER}" @ONLY)