Skip to content

Commit

Permalink
Guarantee build_id is a string. (#1248)
Browse files Browse the repository at this point in the history
Guarantee build_id is a string rather than occasionally an int when
fetched from commit count rather than commit message.

b/295907476

Change-Id: I4b4ab42b8984a8fd38c276329e62c08c0a94bc0e
(cherry picked from commit 12c750e)
  • Loading branch information
briantting authored and anonymous1-me committed Aug 14, 2023
1 parent 11a0f9f commit b2c819c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cobalt/build/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_build_id_from_commit_count(cwd):
output = subprocess.check_output(['git', 'rev-list', '--count', 'HEAD'],
cwd=cwd)
build_id = int(output.strip().decode()) + COMMIT_COUNT_BUILD_ID_OFFSET
return build_id
return str(build_id)


def _get_last_commit_with_format(placeholder, cwd):
Expand Down
10 changes: 6 additions & 4 deletions cobalt/build/get_build_id_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def testGetBuildNumberFromCommitCountSunnyDay(self):
self.make_commit()
build_number = build_info.get_build_id_from_commit_count(
cwd=self.test_dir.name)
self.assertEqual(build_number,
num_commits + build_info.COMMIT_COUNT_BUILD_ID_OFFSET)
self.assertEqual(
int(build_number),
num_commits + build_info.COMMIT_COUNT_BUILD_ID_OFFSET)

def testCommitsOutrankCommitCount(self):
self.make_commit()
Expand All @@ -102,8 +103,9 @@ def testFallbackToCommitCount(self):
for _ in range(num_commits):
self.make_commit()
build_number = get_build_id.main(cwd=self.test_dir.name)
self.assertEqual(build_number,
num_commits + build_info.COMMIT_COUNT_BUILD_ID_OFFSET)
self.assertEqual(
int(build_number),
num_commits + build_info.COMMIT_COUNT_BUILD_ID_OFFSET)


if __name__ == '__main__':
Expand Down

0 comments on commit b2c819c

Please sign in to comment.