Skip to content

Commit

Permalink
Implement //ci:release-validate-deps (#95)
Browse files Browse the repository at this point in the history
The `//ci:release-validate-deps` can be used from the CI job to ensure that we're depending on a release instead of a snapshot dependency.

For example, if we are to release `graknlabs_grakn_core` which depends on a snapshot version of `graknlabs_common` will fail with the following error message:

```
bazel run @graknlabs_build_tools//ci:release-validate-deps graknlabs_graql graknlabs_common

RuntimeError: This commit is not releasable because there are one or more snapshot 
dependencies: ['graknlabs_common']. Check that every dependencies listed in 
dependencies/graknlabs/dependencies.bzl are all release dependencies 
(ie., depends on a tag instead of a commit).
```

If every dependency is a release dependency, it will succeed:
```
bazel run @graknlabs_build_tools//ci:release-validate-deps graknlabs_graql graknlabs_common

This repository is releasable because the dependencies
are all release dependencies: ['graknlabs_common', 'graknlabs_graql']
```
  • Loading branch information
Ganeshwara Herawan Hananda authored Sep 23, 2019
1 parent d909d84 commit 64517da
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ci/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ py_binary(
]
)

py_binary(
name = "release-validate-deps",
srcs = ["release-validate-deps.py"],
main = "release-validate-deps.py",
)

sh_binary(
name = "install-bazel-rbe",
srcs = ["install-bazel-rbe.sh"]
Expand Down
27 changes: 27 additions & 0 deletions ci/release-validate-deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import sys

if __name__ == '__main__':
deps_path = os.path.join('dependencies', 'graknlabs', 'dependencies.bzl')
snapshot_dependencies = []
with open(os.path.join(os.getenv("BUILD_WORKSPACE_DIRECTORY"), deps_path)) as deps_file_object:
deps_content = deps_file_object.read().splitlines()
for arg in sys.argv[1:]:
dependency = list(filter(lambda line: line.endswith('@' + arg), deps_content))
if len(dependency) == 1:
depend_by_tag = dependency[0].strip().startswith('tag')
if not depend_by_tag:
snapshot_dependencies.append(arg)
else:
raise RuntimeError('Invalid sync-marker found for {}. '
'There is supposed to be exactly one sync-marker '
'but {} occurrences found.'.format(arg, len(dependency)))
if len(snapshot_dependencies) == 0:
print('This commit is releasable because the dependencies are '
'all released dependencies: {}'.format(sys.argv[1:]))
else:
raise RuntimeError('This commit is not releasable because '
'there are one or more snapshot dependencies: {}. '
'Check that every dependencies listed in {} are all released dependencies '
'(ie., depends on a tag instead of a commit).'
.format(snapshot_dependencies, deps_path))

0 comments on commit 64517da

Please sign in to comment.