From 0132cad725441ab8bb1f3ae35a6f96969897954a Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Fri, 13 May 2022 10:46:36 +0200 Subject: [PATCH] Specify version with set-version.py. --- .github/workflows/linux.yml | 5 ++ .github/workflows/macos.yml | 5 ++ .github/workflows/windows.yml | 5 ++ android/app/build.gradle | 7 +- helper/version_info.txt | 4 +- lib/about_page.dart | 4 +- lib/version.dart | 5 ++ pubspec.yaml | 5 +- set-version.py | 131 ++++++++++++++++++++++++++++++++++ windows/runner/Runner.rc | 4 +- 10 files changed, 163 insertions(+), 12 deletions(-) create mode 100755 lib/version.dart create mode 100755 set-version.py diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 79e75776..7fdf95cb 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -18,6 +18,11 @@ jobs: with: python-version: '3.9' + - name: Check app versions + run: | + python set-version.py + git diff --exit-code + - name: Install dependencies run: | sudo apt-get update diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index cc601c20..dfb13b24 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -15,6 +15,11 @@ jobs: with: python-version: '3.9' + - name: Check app versions + run: | + python set-version.py + git diff --exit-code + - name: Install dependencies run: | brew update diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 0f09bac5..e95b10c1 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -15,6 +15,11 @@ jobs: with: python-version: '3.9' + - name: Check app versions + run: | + python set-version.py + git diff --exit-code + - name: Install dependencies run: | choco install swig diff --git a/android/app/build.gradle b/android/app/build.gradle index 36d00efd..44deedb9 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -23,9 +23,6 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -def authenticatorVersionCode = 59900 -def authenticatorVersionName = '6.0.0-alpha.2' - apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlinx-serialization' @@ -52,8 +49,8 @@ android { applicationId "com.yubico.yubioath" minSdkVersion project.minSdkVersion targetSdkVersion project.targetSdkVersion - versionCode authenticatorVersionCode - versionName authenticatorVersionName + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName } diff --git a/helper/version_info.txt b/helper/version_info.txt index 17a548a6..d4dd2b3d 100755 --- a/helper/version_info.txt +++ b/helper/version_info.txt @@ -6,8 +6,8 @@ VSVersionInfo( ffi=FixedFileInfo( # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) # Set not needed items to zero 0. - filevers=(4, 1, 0, 0), - prodvers=(4, 1, 0, 0), + filevers=(6, 0, 0, 0), + prodvers=(6, 0, 0, 0), # Contains a bitmask that specifies the valid bits 'flags'r mask=0x3f, # Contains a bitmask that specifies the Boolean attributes of the file. diff --git a/lib/about_page.dart b/lib/about_page.dart index 2c2ecc0a..30d3f8ca 100755 --- a/lib/about_page.dart +++ b/lib/about_page.dart @@ -7,6 +7,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:logging/logging.dart'; import 'package:yubico_authenticator/app/state.dart'; +import 'version.dart'; import 'app/logging.dart'; import 'app/message.dart'; import 'core/state.dart'; @@ -26,8 +27,7 @@ class AboutPage extends ConsumerWidget { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - // TODO: Store the version number elsewhere - const Text('Yubico Authenticator: 6.0.0-alpha.2'), + const Text('Yubico Authenticator: $version'), if (isDesktop) Text('ykman version: ${ref.watch(rpcStateProvider).version}'), Text('Dart version: ${Platform.version}'), diff --git a/lib/version.dart b/lib/version.dart new file mode 100755 index 00000000..a3508600 --- /dev/null +++ b/lib/version.dart @@ -0,0 +1,5 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// This file is generated by running ./set-version.py + +const String version = '6.0.0-dev1'; +const int build = 59900; diff --git a/pubspec.yaml b/pubspec.yaml index 8afdd1ef..4a6cb245 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,10 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 + +# This field is updated by running ./set-version.py +# DO NOT MANUALLY EDIT THIS! +version: 6.0.0+59900 environment: sdk: ">=2.17.0 <3.0.0" diff --git a/set-version.py b/set-version.py new file mode 100755 index 00000000..9cc1e31e --- /dev/null +++ b/set-version.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 +import re +import sys + +""" +This script updates version numbers in various files. +""" + +version_pattern = r"(\d+)\.(\d+)\.(\d+)(-[^\s+]+)?" +lib_version_pattern = rf"const\s+String\s+version\s+=\s+'({version_pattern})';" +lib_build_pattern = rf"const\s+int\s+build\s+=\s+(\d+);" + + +def update_file(fname, func): + with open(fname) as f: + orig = f.read() + + buf = func(orig) + + if buf != orig: + with open(fname, "w") as f: + f.write(buf) + print("Updated", fname) + +def read_lib_version(): + with open("lib/version.dart") as f: + buf = f.read() + + m = re.search( + lib_version_pattern, + buf, + re.MULTILINE, + ) + version = m.group(1) + m = re.search( + lib_build_pattern, + buf, + re.MULTILINE, + ) + build = int(m.group(1)) + return version, build + + +def update_lib(buf): + buf = re.sub( + lib_version_pattern, + f"const String version = '{version}';", + buf, + ) + + buf = re.sub( + lib_build_pattern, + f"const int build = {build};", + buf, + ) + + return buf + +# Handle invocation +args = sys.argv[1:] +if not args: + version, build = read_lib_version() + print(f"Using version: {version}, build: {build}...") +elif len(args) == 2: + version = args[0] + if not re.fullmatch(version_pattern, version): + print("Version is not a valid semver string!") + sys.exit(1) + build = int(args[1]) + print(f"Setting new version: {version}, build: {build}...") + update_file("lib/version.dart", update_lib) +else: + print("Usage: set-version.py ") + sys.exit(1) + +# x.y.z without trailing part +short_version = re.search("(\d+\.\d+\.\d+)", version).group() + +# pubspec.yaml +def update_pubspec(buf): + return re.sub( + r'version:\s+\d+\.\d+\.\d+\+\d+', + f'version: {short_version}+{build}', + buf, + ) + +# Windows Runner.rc +def update_runner_rc(buf): + buf = re.sub( + rf'#define VERSION_AS_STRING "{version_pattern}"', + f'#define VERSION_AS_STRING "{version}"', + buf, + ) + + version_as_number = short_version.replace(".", ",") + buf = re.sub( + r"#define VERSION_AS_NUMBER \d+,\d+,\d+", + f"#define VERSION_AS_NUMBER {version_as_number}", + buf, + ) + return buf + +# Helper version_info +def update_helper_version(buf): + version_tuple = repr(tuple(int(d) for d in short_version.split(".")) + (0,)) + buf = re.sub( + rf'filevers=\(\d+, \d+, \d+, \d+\)', + f'filevers={version_tuple}', + buf, + ) + buf = re.sub( + rf'prodvers=\(\d+, \d+, \d+, \d+\)', + f'prodvers={version_tuple}', + buf, + ) + buf = re.sub( + rf"'FileVersion', '{version_pattern}'", + f"'FileVersion', '{version}'", + buf, + ) + buf = re.sub( + rf"'ProductVersion', '{version_pattern}'", + f"'ProductVersion', '{version}'", + buf, + ) + return buf + + +update_file("pubspec.yaml", update_pubspec) +update_file("windows/runner/Runner.rc", update_runner_rc) +update_file("helper/version_info.txt", update_helper_version) \ No newline at end of file diff --git a/windows/runner/Runner.rc b/windows/runner/Runner.rc index a4daba66..c2130dce 100644 --- a/windows/runner/Runner.rc +++ b/windows/runner/Runner.rc @@ -63,13 +63,13 @@ IDI_APP_ICON ICON "resources\\app_icon.ico" #ifdef FLUTTER_BUILD_NUMBER #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER #else -#define VERSION_AS_NUMBER 1,0,0 +#define VERSION_AS_NUMBER 6,0,0 #endif #ifdef FLUTTER_BUILD_NAME #define VERSION_AS_STRING #FLUTTER_BUILD_NAME #else -#define VERSION_AS_STRING "1.0.0" +#define VERSION_AS_STRING "6.0.0-dev1" #endif VS_VERSION_INFO VERSIONINFO