Skip to content

Commit 4f935e5

Browse files
authored
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.
1 parent 9066ec2 commit 4f935e5

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ jobs:
117117
runs-on: ubuntu-20.04 # latest
118118
steps:
119119
- uses: actions/checkout@v2
120-
with:
121-
submodules: true
122120
- name: Check docs
123121
run: |
124122
mvn install -Dmaven.test.skip
125123
./make-docs.py
124+
125+
# ensure that aws-crt version is consistent among different files
126+
consistent-crt-version:
127+
runs-on: ubuntu-20.04 # latest
128+
steps:
129+
- uses: actions/checkout@v2
130+
- name: Consistent aws-crt version
131+
run: |
132+
./update-crt.py --check-consistency
133+

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ mkdir sdk-workspace
8181
cd sdk-workspace
8282
# Clone the CRT repository
8383
# (Use the latest version of the CRT here instead of "v0.18.0")
84-
git clone --branch v0.18.0 --recurse-submodules https://github.com/awslabs/aws-crt-java.git
84+
git clone --branch v0.19.3 --recurse-submodules https://github.com/awslabs/aws-crt-java.git
8585
cd aws-crt-java
8686
# Compile and install the CRT
8787
mvn install -Dmaven.test.skip=true
@@ -103,7 +103,7 @@ mkdir sdk-workspace
103103
cd sdk-workspace
104104
# Clone the CRT repository
105105
# (Use the latest version of the CRT here instead of "v0.18.0")
106-
git clone --branch v0.18.0 --recurse-submodules https://github.com/awslabs/aws-crt-java.git
106+
git clone --branch v0.19.3 --recurse-submodules https://github.com/awslabs/aws-crt-java.git
107107
# Compile and install the CRT for Android
108108
cd aws-crt-java/android
109109
./gradlew connectedCheck # optional, will run the unit tests on any connected devices/emulators
@@ -127,7 +127,7 @@ repositories {
127127
}
128128
129129
dependencies {
130-
implementation 'software.amazon.awssdk.crt:android:0.18.0'
130+
implementation 'software.amazon.awssdk.crt:android:0.19.3'
131131
}
132132
```
133133

update-crt.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@
1111
description="Update files containing hard-coded aws-crt-java version numbers.")
1212
parser.add_argument('version', nargs='?',
1313
help='version to use (i.e. "0.1.2"). default: automatically detect latest version')
14+
parser.add_argument('--check-consistency', action='store_true',
15+
help='Exit with error if version is inconsistent between files')
1416
args = parser.parse_args()
1517

1618

1719
def main():
18-
if args.version is None:
19-
args.version = get_latest_crt_version()
20-
print(f'Latest version: {args.version}')
20+
if args.check_consistency:
21+
# we'll find the version from the first file we scan
22+
args.version = None
23+
else:
24+
if args.version is None:
25+
args.version = get_latest_crt_version()
26+
print(f'Latest version: {args.version}')
2127

22-
if re.fullmatch(VERSION_PATTERN, args.version) is None:
23-
exit(f'Invalid version: "{args.version}". Must look like "0.1.2"')
28+
if re.fullmatch(VERSION_PATTERN, args.version) is None:
29+
exit(f'Invalid version: "{args.version}". Must look like "0.1.2"')
2430

2531
os.chdir(os.path.dirname(__file__))
2632

@@ -51,17 +57,30 @@ def update(*, filepath, preceded_by, followed_by):
5157
with open(filepath, 'r+') as f:
5258
txt_old = f.read()
5359

54-
full_pattern = rf'({preceded_by}){VERSION_PATTERN}({followed_by})'
55-
full_replacement = rf'\g<1>{args.version}\g<2>'
60+
full_pattern = rf'({preceded_by})({VERSION_PATTERN})({followed_by})'
61+
full_replacement = rf'\g<1>{args.version}\g<3>'
5662

57-
if len(re.findall(full_pattern, txt_old)) == 0:
63+
matches = re.findall(full_pattern, txt_old)
64+
if len(matches) == 0:
5865
exit(f'Version not found in: {filepath}\n' +
5966
f'Preceded by: "{preceded_by}"')
6067

61-
txt_new = re.sub(full_pattern, full_replacement, txt_old)
62-
f.seek(0)
63-
f.write(txt_new)
64-
f.truncate()
68+
if args.check_consistency:
69+
# in --check-consistency mode we remember the version from the first
70+
# file we scan, and then ensure all subsequent files use that version too
71+
for match in matches:
72+
found_version = match[1]
73+
if args.version is None:
74+
print(f'Found version {found_version} in: {filepath}')
75+
args.version = found_version
76+
elif found_version != args.version:
77+
exit(f'Found different version {found_version} in: {filepath}')
78+
else:
79+
# running in normal mode, update the file
80+
txt_new = re.sub(full_pattern, full_replacement, txt_old)
81+
f.seek(0)
82+
f.write(txt_new)
83+
f.truncate()
6584

6685

6786
def get_latest_crt_version():

0 commit comments

Comments
 (0)