-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease.vsh
executable file
·147 lines (120 loc) · 3.6 KB
/
release.vsh
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env -S v run
import os
import net.http
import x.json2 as json
import regex
struct GithubRelease {
tag_name string
}
fn get_latest_release() !string {
url := 'https://api.github.com/repos/freeflowuniverse/herolib/releases/latest'
resp := http.get(url)!
release := json.decode[GithubRelease](resp.body) or {
return error('Failed to decode GitHub response: ${err}')
}
return release.tag_name
}
// Show current version
latest_release := get_latest_release() or {
eprintln('Error getting latest release: ${err}')
exit(1)
}
println('Current latest release: ${latest_release}')
// Ask for new version
new_version := os.input('Enter new version (e.g., 1.0.4): ')
// Validate version format
version_re := regex.regex_opt(r'^[0-9]+\.[0-9]+\.[0-9]+$') or {
eprintln('Error creating regex: ${err}')
exit(1)
}
if !version_re.matches_string(new_version) {
eprintln('Error: Version must be in format X.Y.Z (e.g., 1.0.4)')
exit(1)
}
ourdir := dir(@FILE)
os.chdir(ourdir)!
hero_v_path := '${ourdir}/cli/hero.v'
// Read hero.v
content := os.read_file(hero_v_path) or {
eprintln('Error reading ${hero_v_path}: ${err}')
exit(1)
}
// Find version line
mut version_line_idx := -1
mut lines := content.split_into_lines()
for i, line in lines {
if line.contains('version:') {
version_line_idx = i
break
}
}
if version_line_idx == -1 {
eprintln('Error: Could not find version line in ${hero_v_path}')
exit(1)
}
// Get indentation
old_line := lines[version_line_idx]
indent := old_line.all_before('version:')
// Create backup
os.cp(hero_v_path, '${hero_v_path}.backup') or {
eprintln('Error creating backup: ${err}')
exit(1)
}
// Replace version line
lines[version_line_idx] = ' version: \'${new_version}\''
// Write back to file
os.write_file(hero_v_path, lines.join_lines()) or {
eprintln('Error writing to ${hero_v_path}: ${err}')
// Restore backup
os.cp('${hero_v_path}.backup', hero_v_path) or {
eprintln('Error restoring backup: ${err}')
}
exit(1)
}
// Clean up backup
os.rm('${hero_v_path}.backup') or {
eprintln('Warning: Could not remove backup file: ${err}')
}
// Update version in install_hero.sh
install_hero_path := '${ourdir}/install_hero.sh'
install_hero_content := os.read_file(install_hero_path) or {
eprintln('Error reading ${install_hero_path}: ${err}')
exit(1)
}
// Create backup of install_hero.sh
os.cp(install_hero_path, '${install_hero_path}.backup') or {
eprintln('Error creating backup of install_hero.sh: ${err}')
exit(1)
}
// Replace version in install_hero.sh
mut install_hero_lines := install_hero_content.split_into_lines()
for i, line in install_hero_lines {
if line.contains("version='") {
install_hero_lines[i] = "version='${new_version}'"
break
}
}
// Write back to install_hero.sh
os.write_file(install_hero_path, install_hero_lines.join_lines()) or {
eprintln('Error writing to ${install_hero_path}: ${err}')
// Restore backup
os.cp('${install_hero_path}.backup', install_hero_path) or {
eprintln('Error restoring backup of install_hero.sh: ${err}')
}
exit(1)
}
// Clean up backup of install_hero.sh
os.rm('${install_hero_path}.backup') or {
eprintln('Warning: Could not remove backup file of install_hero.sh: ${err}')
}
cmd:='
git remote set-url origin [email protected]:freeflowuniverse/herolib.git
git add ${hero_v_path} ${install_hero_path}
git commit -m "bump version to ${new_version}"
git pull [email protected]:freeflowuniverse/herolib.git main
git tag -a "v${new_version}" -m "Release version ${new_version}"
git push [email protected]:freeflowuniverse/herolib.git "v${new_version}"
'
println(cmd)
os.execute_or_panic('${cmd}')
println('Release v${new_version} created and pushed!')