forked from Qovery/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease-commit.rb
executable file
·109 lines (81 loc) · 2.37 KB
/
release-commit.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env ruby
# release-commit.rb
#
# SUMMARY
#
# Commits and tags the pending release
require_relative "setup"
#
# Functions
#
def bump_cargo_version(version)
# Cargo.toml
content = File.read("#{ROOT_DIR}/Cargo.toml")
new_content = bump_version(content, version)
File.write("#{ROOT_DIR}/Cargo.toml", new_content)
# Cargo.lock
content = File.read("#{ROOT_DIR}/Cargo.lock")
new_content = bump_version(content, version)
File.write("#{ROOT_DIR}/Cargo.lock", new_content)
end
def bump_version(content, version)
content.sub(
/name = "vector"\nversion = "([a-z0-9.-]*)"\n/,
"name = \"vector\"\nversion = \"#{version}\"\n"
)
end
def release_exists?(release)
errors = `git rev-parse v#{release.version} 2>&1 >/dev/null`
errors == ""
end
#
# Commit
#
metadata = Metadata.load!(META_ROOT, DOCS_ROOT, GUIDES_ROOT, PAGES_ROOT)
release = metadata.latest_release
if release_exists?(release)
Printer.error!(
<<~EOF
It looks like release v#{release.version} has already been released. A tag for this release already exists.
This command will only release the latest release. If you're trying to release from an older major or minor version, you must do so from that branch.
EOF
)
else
Printer.title("Committing and tagging release")
bump_cargo_version(release.version)
Printer.success("Bumped the version in Cargo.toml & Cargo.lock to #{release.version}")
branch_name = "#{release.version.major}.#{release.version.minor}"
commands =
<<~EOF
git add #{ROOT_DIR} -A
git commit -sam 'chore: Prepare v#{release.version} release'
git tag -a v#{release.version} -m "v#{release.version}"
git branch v#{branch_name} 2>/dev/null || true
EOF
commands.chomp!
status = `git status --short`.chomp!
words =
<<~EOF
We'll be releasing v#{release.version} with the following commands:
#{commands.indent(2)}
Your current `git status` is:
#{status.indent(2)}
Proceed to execute the above commands?
EOF
if Printer.get(words, ["y", "n"]) == "n"
Printer.error!("Ok, I've aborted. Please re-run this command when you're ready.")
end
commands.chomp.split("\n").each do |command|
system(command)
if !$?.success?
Printer.error!(
<<~EOF
Command failed!
#{command}
Produced the following error:
#{$?.inspect}
EOF
)
end
end
end