Skip to content

ensure aws-crt version is consistent everywhere #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -127,7 +127,7 @@ repositories {
}

dependencies {
implementation 'software.amazon.awssdk.crt:android:0.18.0'
implementation 'software.amazon.awssdk.crt:android:0.19.3'
}
```

Expand Down
43 changes: 31 additions & 12 deletions update-crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand Down Expand Up @@ -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():
Expand Down