trifid/nebula-ffi/update.py

43 lines
1.4 KiB
Python
Raw Permalink Normal View History

2023-08-05 02:59:27 +00:00
import os
import re
import subprocess
import shutil
# Super cursed python script to update nebula and rewrite the cargo version so we can have Ultra Up-To-Date nebula versions
# clone the repository to /tmp/nebula-clone-checkout
#if os.path.exists('/tmp/nebula-clone-checkout'):
# shutil.rmtree('/tmp/nebula-clone-checkout')
#subprocess.check_output(['git', 'clone', 'https://github.com/slackhq/nebula', '/tmp/nebula-clone-checkout', '--bare'])
describe = subprocess.check_output(['git', '-C', '/tmp/nebula-clone-checkout', 'describe']).decode('ascii').strip()
print(f'Repository version: {describe}')
on_tag_re = re.compile('v(\\d+.)+(\\d+)')
on_commit_re = re.compile('v(\d+.)+(\d+)-(\d+)-g[a-f0-9]+')
if on_commit_re.match(describe):
print('Repository is on-commit (no tag on this commit)')
split = describe.split('-')
version_splits = len(split) - 2
version = split[:version_splits][0].split('v')[1]
commit = split[-1].split('g')[1]
print('Base version:', version)
print('Commit:', commit)
print(f'Go package specifier: github.com/slackhq/nebula@{commit}')
print(f'Cargo package version: {version}+{commit}')
gopkg = f'github.com/slackhq/nebula@{commit}'
cargo = f'{version}+{commit}'
print('Updating gopkg')
subprocess.check_output(['go', 'get', gopkg])
print('Updating cargo (todo)')
elif on_tag_re.match(describe):
print('Repository is on-tag (this commit is tagged)')