1+ #!/usr/bin/env python3
12import os
23import subprocess
34from inspect import getsourcefile
45from os .path import abspath
56
6- import requests
77import toml
88
9+ from utils .validate_version import assert_version_is_not_published
10+
911SCRIPTS_DIR = os .path .dirname (abspath (getsourcefile (lambda : 0 )))
1012REPO_ROOT_DIR = os .path .dirname (SCRIPTS_DIR )
1113CHANGELOG_DIR = os .path .join (REPO_ROOT_DIR , "changelog.d" )
1214
13- def get_crate_versions (crate_name ):
14- # crates.io returns a 403 now for the default requests user-agent
15- headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36' }
16-
17- response = requests .get (f"https://crates.io/api/v1/crates/{ crate_name } " , headers = headers )
18- if response .status_code != 200 :
19- raise Exception (f"Error fetching crate info: { response .status_code } " )
20- data = response .json ()
21- return [version ["num" ] for version in data ["versions" ]]
22-
2315
2416def read_version_from_cargo_toml (filepath ):
2517 with open (filepath , "r" ) as file :
@@ -34,7 +26,8 @@ def publish_vrl(version):
3426
3527 tag_name = f"v{ version } "
3628 tag_message = f"Release { version } "
37- subprocess .run (["git" , "tag" , "-a" , tag_name , "-m" , tag_message ], check = True , cwd = REPO_ROOT_DIR )
29+ subprocess .run (["git" , "tag" , "-a" , tag_name , "-m" , tag_message ], check = True ,
30+ cwd = REPO_ROOT_DIR )
3831 subprocess .run (["git" , "push" , "origin" , tag_name ], check = True , cwd = REPO_ROOT_DIR )
3932 print (f"Tagged version." )
4033 except subprocess .CalledProcessError as e :
@@ -43,21 +36,11 @@ def publish_vrl(version):
4336
4437def assert_no_changelog_fragments ():
4538 entries = os .listdir (CHANGELOG_DIR )
46- error = f"{ CHANGELOG_DIR } should only contain a README.md file. Did you run ./scripts/generate_release_changelog.sh?"
39+ error = f"{ CHANGELOG_DIR } should only contain a README.md file. Did you run .. /scripts/generate_release_changelog.sh?"
4740 assert len (entries ) == 1 , error
4841 assert entries [0 ] == "README.md" , error
4942
5043
51- def assert_version_is_not_published (current_version ):
52- crate_name = "vrl"
53- versions = get_crate_versions (crate_name )
54- print (f"Available versions for { crate_name } : { versions } " )
55-
56- if current_version in versions :
57- print (f"The version { current_version } is already published. Please update the version and try again." )
58- exit (1 )
59-
60-
6144def main ():
6245 assert_no_changelog_fragments ()
6346
0 commit comments