get-go-version.py 1019 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. import json
  3. import os
  4. import pathlib
  5. from packaging.version import parse
  6. SCRIPT_PATH = pathlib.Path(__file__).parents[0]
  7. REPO_ROOT = SCRIPT_PATH.parents[1]
  8. GO_SRC = REPO_ROOT / 'src' / 'go'
  9. GITHUB_OUTPUT = pathlib.Path(os.environ['GITHUB_OUTPUT'])
  10. version = parse('1.0.0')
  11. modules = []
  12. for modfile in GO_SRC.glob('**/go.mod'):
  13. moddata = modfile.read_text()
  14. for line in moddata.splitlines():
  15. if line.startswith('go '):
  16. version = max(version, parse(line.split()[1]))
  17. break
  18. for main in modfile.parent.glob('**/main.go'):
  19. mainpath = main.relative_to(modfile.parent).parent
  20. if 'examples' in mainpath.parts:
  21. continue
  22. modules.append({
  23. 'module': str(modfile.parent),
  24. 'version': str(version),
  25. 'build_target': f'github.com/netdata/netdata/go/plugins/{ str(mainpath) }/',
  26. })
  27. with GITHUB_OUTPUT.open('a') as f:
  28. f.write(f'matrix={ json.dumps({"include": modules}) }\n')