From 4f91b57aa2d9073196c074e3a61fa01e9395c0a5 Mon Sep 17 00:00:00 2001 From: rankun Date: Sat, 18 Apr 2020 02:04:48 +0800 Subject: [PATCH] feat: version config --- .github/workflows/macos.yml | 4 +++- .github/workflows/ubuntu.yml | 4 +++- .github/workflows/windows.yml | 1 + QtScrcpy/QtScrcpy.pro | 17 ++++++++++------- QtScrcpy/version | 1 + ci/generate-version.py | 20 ++++++++++++++++++++ 6 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 QtScrcpy/version create mode 100644 ci/generate-version.py diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 0ee8c37..a6b8f3d 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -42,7 +42,9 @@ jobs: - name: Build MacOS env: ENV_QT_PATH: ${{ env.qt-install-path }} - run: ci/mac/build_for_mac.sh release + run: | + python ci\generate-version.py + ci/mac/build_for_mac.sh release # 获取ref最后一个/后的内容 - name: Get the version shell: bash diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index cdf06d1..32a1f50 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -45,4 +45,6 @@ jobs: - name: Build Ubuntu env: ENV_QT_PATH: ${{ env.qt-install-path }} - run: ci/linux/build_for_ubuntu.sh release + run: | + python ci\generate-version.py + ci/linux/build_for_ubuntu.sh release diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 7b9c140..448dc1a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -71,6 +71,7 @@ jobs: ENV_VCVARSALL: ${{ env.vcvarsall-path }} ENV_QT_PATH: ${{ env.qt-install-path }} run: | + call python ci\generate-version.py call "ci\win\build_for_win.bat" release ${{ matrix.msvc-arch }} # 获取ref最后一个/后的内容 - name: Get the version diff --git a/QtScrcpy/QtScrcpy.pro b/QtScrcpy/QtScrcpy.pro index 98ebe74..0b7291e 100644 --- a/QtScrcpy/QtScrcpy.pro +++ b/QtScrcpy/QtScrcpy.pro @@ -56,14 +56,17 @@ INCLUDEPATH += \ $$PWD/devicemanage \ $$PWD/fontawesome -# 版本号会在打包脚本中定义,并通过qmake传递进来 -# 如果外部没有定义,则内部定义(debug模式) -!defined(VERSION_MAJOR, var) { - VERSION_MAJOR = 0 - VERSION_MINOR = 0 - VERSION_PATCH = 0 -} +# 如果变量没有定义 +# !defined(TEST_VAR, var) { +# message("test") +# } +# 从文件读取版本号 +CAT_VERSION = $$cat($$PWD/version) +# 拆分出版本号 +VERSION_MAJOR = $$section(CAT_VERSION, ., 0, 0) +VERSION_MINOR = $$section(CAT_VERSION, ., 1, 1) +VERSION_PATCH = $$section(CAT_VERSION, ., 2, 2) message("version:" $${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_PATCH}) # qmake变量的方式定义版本号 diff --git a/QtScrcpy/version b/QtScrcpy/version new file mode 100644 index 0000000..77d6f4c --- /dev/null +++ b/QtScrcpy/version @@ -0,0 +1 @@ +0.0.0 diff --git a/ci/generate-version.py b/ci/generate-version.py new file mode 100644 index 0000000..8cd42cb --- /dev/null +++ b/ci/generate-version.py @@ -0,0 +1,20 @@ +import sys +import os + +if __name__ == '__main__': + p = os.popen('git rev-list --tags --max-count=1') + commit = p.read() + p.close() + + p = os.popen('git describe --tags ' + commit) + tag = p.read() + p.close() + + # print('get tag:', tag) + + version = str(tag[1:]) + version_file = os.path.abspath(os.path.join(os.path.dirname(__file__), "../QtScrcpy/version")) + file=open(version_file, 'w') + file.write(version) + file.close() + sys.exit(0) \ No newline at end of file