Specify version with set-version.py.

This commit is contained in:
Dain Nilsson 2022-05-13 10:46:36 +02:00
parent e86c50fb64
commit 0132cad725
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
10 changed files with 163 additions and 12 deletions

View File

@ -18,6 +18,11 @@ jobs:
with: with:
python-version: '3.9' python-version: '3.9'
- name: Check app versions
run: |
python set-version.py
git diff --exit-code
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt-get update sudo apt-get update

View File

@ -15,6 +15,11 @@ jobs:
with: with:
python-version: '3.9' python-version: '3.9'
- name: Check app versions
run: |
python set-version.py
git diff --exit-code
- name: Install dependencies - name: Install dependencies
run: | run: |
brew update brew update

View File

@ -15,6 +15,11 @@ jobs:
with: with:
python-version: '3.9' python-version: '3.9'
- name: Check app versions
run: |
python set-version.py
git diff --exit-code
- name: Install dependencies - name: Install dependencies
run: | run: |
choco install swig choco install swig

View File

@ -23,9 +23,6 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0' flutterVersionName = '1.0'
} }
def authenticatorVersionCode = 59900
def authenticatorVersionName = '6.0.0-alpha.2'
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization' apply plugin: 'kotlinx-serialization'
@ -52,8 +49,8 @@ android {
applicationId "com.yubico.yubioath" applicationId "com.yubico.yubioath"
minSdkVersion project.minSdkVersion minSdkVersion project.minSdkVersion
targetSdkVersion project.targetSdkVersion targetSdkVersion project.targetSdkVersion
versionCode authenticatorVersionCode versionCode flutterVersionCode.toInteger()
versionName authenticatorVersionName versionName flutterVersionName
} }

View File

@ -6,8 +6,8 @@ VSVersionInfo(
ffi=FixedFileInfo( ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0. # Set not needed items to zero 0.
filevers=(4, 1, 0, 0), filevers=(6, 0, 0, 0),
prodvers=(4, 1, 0, 0), prodvers=(6, 0, 0, 0),
# Contains a bitmask that specifies the valid bits 'flags'r # Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f, mask=0x3f,
# Contains a bitmask that specifies the Boolean attributes of the file. # Contains a bitmask that specifies the Boolean attributes of the file.

View File

@ -7,6 +7,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:yubico_authenticator/app/state.dart'; import 'package:yubico_authenticator/app/state.dart';
import 'version.dart';
import 'app/logging.dart'; import 'app/logging.dart';
import 'app/message.dart'; import 'app/message.dart';
import 'core/state.dart'; import 'core/state.dart';
@ -26,8 +27,7 @@ class AboutPage extends ConsumerWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// TODO: Store the version number elsewhere const Text('Yubico Authenticator: $version'),
const Text('Yubico Authenticator: 6.0.0-alpha.2'),
if (isDesktop) if (isDesktop)
Text('ykman version: ${ref.watch(rpcStateProvider).version}'), Text('ykman version: ${ref.watch(rpcStateProvider).version}'),
Text('Dart version: ${Platform.version}'), Text('Dart version: ${Platform.version}'),

5
lib/version.dart Executable file
View File

@ -0,0 +1,5 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// This file is generated by running ./set-version.py <version> <build>
const String version = '6.0.0-dev1';
const int build = 59900;

View File

@ -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. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # 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 <version>
# DO NOT MANUALLY EDIT THIS!
version: 6.0.0+59900
environment: environment:
sdk: ">=2.17.0 <3.0.0" sdk: ">=2.17.0 <3.0.0"

131
set-version.py Executable file
View File

@ -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 <version> <build>")
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)

View File

@ -63,13 +63,13 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
#ifdef FLUTTER_BUILD_NUMBER #ifdef FLUTTER_BUILD_NUMBER
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
#else #else
#define VERSION_AS_NUMBER 1,0,0 #define VERSION_AS_NUMBER 6,0,0
#endif #endif
#ifdef FLUTTER_BUILD_NAME #ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME #define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#else #else
#define VERSION_AS_STRING "1.0.0" #define VERSION_AS_STRING "6.0.0-dev1"
#endif #endif
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO