Gitea CI / Check code and tests (push) Successful in 7m38s
Gitea CI / Build Android APK (push) Successful in 6m20s
Gitea CI / Audit and package Windows x64 (push) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (push) Canceled after 0s
Gitea CI / Gitea CI passed (push) Canceled after 0s
Gitea CI / Build Windows x64 app (push) Canceled after 14m42s
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""Verify the runner's Flutter version against the exact project .fvmrc pin."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
from common.process import cli, run
|
|
|
|
VERSION = re.compile(r'\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?')
|
|
|
|
|
|
def verify_version(config):
|
|
try:
|
|
required = json.loads(config.read_text(encoding='utf-8'))['flutter']
|
|
except (OSError, ValueError, KeyError, TypeError):
|
|
raise RuntimeError('.fvmrc must pin an exact Flutter framework version.') from None
|
|
if not isinstance(required, str) or not VERSION.fullmatch(required):
|
|
raise RuntimeError('.fvmrc must pin an exact Flutter framework version.')
|
|
flutter = shutil.which('flutter')
|
|
if not flutter:
|
|
raise RuntimeError('Cannot read Flutter version; Flutter is missing on PATH.')
|
|
try:
|
|
result = run([flutter, '--version', '--machine'], cwd=config.parent,
|
|
capture_output=True, text=True, encoding='utf-8', timeout=60)
|
|
installed = json.loads(result.stdout)['frameworkVersion']
|
|
except (OSError, subprocess.SubprocessError, ValueError, KeyError, TypeError):
|
|
raise RuntimeError('Cannot read Flutter version.') from None
|
|
if not isinstance(installed, str) or not VERSION.fullmatch(installed):
|
|
raise RuntimeError('Cannot read Flutter framework version.')
|
|
if installed != required:
|
|
raise RuntimeError(f'Flutter {required} required by .fvmrc; found {installed}.')
|
|
return required
|
|
|
|
|
|
def main():
|
|
argparse.ArgumentParser(description=__doc__).parse_args()
|
|
version = verify_version(Path.cwd() / '.fvmrc')
|
|
print(f'Flutter {version} matches .fvmrc.')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(cli(main))
|