Skip to content
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
26 changes: 26 additions & 0 deletions detection_rules/devtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,32 @@ def license_check(ctx, ignore_directory):
ctx.exit(int(failed))


@dev_group.command('test-version-lock')
@click.argument('branches', nargs=-1, required=True)
@click.option('--remote', '-r', default='origin', help='Override the remote from "origin"')
def test_version_lock(branches: tuple, remote: str):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We potentially could run this in all unit tests where a rule file is changed to be really thorough, but I think for now we should leave it as a manual command

"""Simulate the incremental step in the version locking to find version change violations."""
git = utils.make_git('-C', '.')
current_branch = git('rev-parse', '--abbrev-ref', 'HEAD')

try:
click.echo(f'iterating lock process for branches: {branches}')
for branch in branches:
click.echo(branch)
git('checkout', f'{remote}/{branch}')
subprocess.check_call(['python', '-m', 'detection_rules', 'dev', 'build-release', '-u'])

finally:
diff = git('--no-pager', 'diff', get_etc_path('version.lock.json'))
outfile = Path(get_path()).joinpath('lock-diff.txt')
outfile.write_text(diff)
click.echo(f'diff saved to {outfile}')

click.echo('reverting changes in version.lock')
git('checkout', '-f')
git('checkout', current_branch)


@dev_group.command('package-stats')
@click.option('--token', '-t', help='GitHub token to search API authenticated (may exceed threshold without auth)')
@click.option('--threads', default=50, help='Number of threads to download rules from GitHub')
Expand Down
Loading