Skip to content

Commit c48c609

Browse files
authored
chore(releasing): refactoring, small fixes and README.md (#1282)
* fix(releasing): pr scripts fixes * move under python dir * add readme * add missing commit and requirements.txt
1 parent 250f793 commit c48c609

File tree

6 files changed

+52
-23
lines changed

6 files changed

+52
-23
lines changed

release/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# VRL release steps
2+
3+
1. Create a release PR
4+
5+
```shell
6+
python3 create_release_pull_request.py <version>
7+
```
8+
9+
2. Wait for the PR to be merged
10+
11+
3. Run the publish script
12+
13+
```shell
14+
python3 publish.py
15+
```

scripts/create-release-pull-request.py renamed to release/create_release_pull_request.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
import argparse
23
import os
34
import subprocess
@@ -6,6 +7,8 @@
67

78
import semver
89

10+
from utils.validate_version import assert_version_is_not_published
11+
912
SCRIPTS_DIR = os.path.dirname(abspath(getsourcefile(lambda: 0)))
1013
REPO_ROOT_DIR = os.path.dirname(SCRIPTS_DIR)
1114
CHANGELOG_DIR = os.path.join(REPO_ROOT_DIR, "changelog.d")
@@ -50,6 +53,7 @@ def validate_version(version):
5053
print(f"Invalid version: {version}. Please provide a valid SemVer string.")
5154
exit(1)
5255

56+
assert_version_is_not_published(version)
5357

5458
def generate_changelog():
5559
print("Generating changelog...")
@@ -95,6 +99,7 @@ def main():
9599
create_branch(branch_name, dry_run)
96100
overwrite_version(new_version)
97101
generate_changelog()
102+
subprocess.run(["git", "push"], check=True, cwd=REPO_ROOT_DIR)
98103
create_pull_request(branch_name, new_version, dry_run)
99104

100105
if dry_run:

scripts/publish.py renamed to release/publish.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1+
#!/usr/bin/env python3
12
import os
23
import subprocess
34
from inspect import getsourcefile
45
from os.path import abspath
56

6-
import requests
77
import toml
88

9+
from utils.validate_version import assert_version_is_not_published
10+
911
SCRIPTS_DIR = os.path.dirname(abspath(getsourcefile(lambda: 0)))
1012
REPO_ROOT_DIR = os.path.dirname(SCRIPTS_DIR)
1113
CHANGELOG_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

2416
def 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

4437
def 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-
6144
def main():
6245
assert_no_changelog_fragments()
6346

release/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests
2+
semver

release/utils/__init__.py

Whitespace-only changes.

release/utils/validate_version.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import requests
2+
3+
4+
def get_crate_versions(crate_name):
5+
# crates.io returns a 403 now for the default requests user-agent
6+
headers = {
7+
'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'}
8+
9+
response = requests.get(f"https://crates.io/api/v1/crates/{crate_name}", headers=headers)
10+
if response.status_code != 200:
11+
raise Exception(f"Error fetching crate info: {response.status_code}")
12+
data = response.json()
13+
return [version["num"] for version in data["versions"]]
14+
15+
16+
def assert_version_is_not_published(current_version):
17+
crate_name = "vrl"
18+
versions = get_crate_versions(crate_name)
19+
print(f"Available versions for {crate_name}: {versions}")
20+
21+
if current_version in versions:
22+
print(
23+
f"The version {current_version} is already published. Please update the version and try again.")
24+
exit(1)

0 commit comments

Comments
 (0)