From 4f935e5255da4818ce6133a9b7b5508b319764ba Mon Sep 17 00:00:00 2001 From: Michael Graeb Date: Thu, 1 Sep 2022 09:12:37 -0700 Subject: [PATCH] ensure aws-crt version is consistent everywhere (#313) **ISSUE:** Several files state which version of `aws-crt` to use. When we edit these files by hand, they tend to get out of sync. So we added a script to help, but sometimes people forgot to use the script. **DESCRIPTION OF CHANGES:** Add a CI check to ensure the files are in sync. --- .github/workflows/ci.yml | 12 +++++++++-- README.md | 6 +++--- update-crt.py | 43 +++++++++++++++++++++++++++++----------- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f62c09bf..62b0244f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -117,9 +117,17 @@ jobs: runs-on: ubuntu-20.04 # latest steps: - uses: actions/checkout@v2 - with: - submodules: true - name: Check docs run: | mvn install -Dmaven.test.skip ./make-docs.py + + # ensure that aws-crt version is consistent among different files + consistent-crt-version: + runs-on: ubuntu-20.04 # latest + steps: + - uses: actions/checkout@v2 + - name: Consistent aws-crt version + run: | + ./update-crt.py --check-consistency + diff --git a/README.md b/README.md index 0c68c5347..98f75e2d9 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ mkdir sdk-workspace cd sdk-workspace # Clone the CRT repository # (Use the latest version of the CRT here instead of "v0.18.0") -git clone --branch v0.18.0 --recurse-submodules https://github.com/awslabs/aws-crt-java.git +git clone --branch v0.19.3 --recurse-submodules https://github.com/awslabs/aws-crt-java.git cd aws-crt-java # Compile and install the CRT mvn install -Dmaven.test.skip=true @@ -103,7 +103,7 @@ mkdir sdk-workspace cd sdk-workspace # Clone the CRT repository # (Use the latest version of the CRT here instead of "v0.18.0") -git clone --branch v0.18.0 --recurse-submodules https://github.com/awslabs/aws-crt-java.git +git clone --branch v0.19.3 --recurse-submodules https://github.com/awslabs/aws-crt-java.git # Compile and install the CRT for Android cd aws-crt-java/android ./gradlew connectedCheck # optional, will run the unit tests on any connected devices/emulators @@ -127,7 +127,7 @@ repositories { } dependencies { - implementation 'software.amazon.awssdk.crt:android:0.18.0' + implementation 'software.amazon.awssdk.crt:android:0.19.3' } ``` diff --git a/update-crt.py b/update-crt.py index a37559b9b..0527c7172 100755 --- a/update-crt.py +++ b/update-crt.py @@ -11,16 +11,22 @@ description="Update files containing hard-coded aws-crt-java version numbers.") parser.add_argument('version', nargs='?', help='version to use (i.e. "0.1.2"). default: automatically detect latest version') +parser.add_argument('--check-consistency', action='store_true', + help='Exit with error if version is inconsistent between files') args = parser.parse_args() def main(): - if args.version is None: - args.version = get_latest_crt_version() - print(f'Latest version: {args.version}') + if args.check_consistency: + # we'll find the version from the first file we scan + args.version = None + else: + if args.version is None: + args.version = get_latest_crt_version() + print(f'Latest version: {args.version}') - if re.fullmatch(VERSION_PATTERN, args.version) is None: - exit(f'Invalid version: "{args.version}". Must look like "0.1.2"') + if re.fullmatch(VERSION_PATTERN, args.version) is None: + exit(f'Invalid version: "{args.version}". Must look like "0.1.2"') os.chdir(os.path.dirname(__file__)) @@ -51,17 +57,30 @@ def update(*, filepath, preceded_by, followed_by): with open(filepath, 'r+') as f: txt_old = f.read() - full_pattern = rf'({preceded_by}){VERSION_PATTERN}({followed_by})' - full_replacement = rf'\g<1>{args.version}\g<2>' + full_pattern = rf'({preceded_by})({VERSION_PATTERN})({followed_by})' + full_replacement = rf'\g<1>{args.version}\g<3>' - if len(re.findall(full_pattern, txt_old)) == 0: + matches = re.findall(full_pattern, txt_old) + if len(matches) == 0: exit(f'Version not found in: {filepath}\n' + f'Preceded by: "{preceded_by}"') - txt_new = re.sub(full_pattern, full_replacement, txt_old) - f.seek(0) - f.write(txt_new) - f.truncate() + if args.check_consistency: + # in --check-consistency mode we remember the version from the first + # file we scan, and then ensure all subsequent files use that version too + for match in matches: + found_version = match[1] + if args.version is None: + print(f'Found version {found_version} in: {filepath}') + args.version = found_version + elif found_version != args.version: + exit(f'Found different version {found_version} in: {filepath}') + else: + # running in normal mode, update the file + txt_new = re.sub(full_pattern, full_replacement, txt_old) + f.seek(0) + f.write(txt_new) + f.truncate() def get_latest_crt_version():