mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools: add support for skiping lines in v bump
(#19064)
This commit is contained in:
parent
8e26ca3f5a
commit
cc97b8df1e
@ -9,7 +9,7 @@ import semver
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
tool_name = os.file_name(os.executable())
|
tool_name = os.file_name(os.executable())
|
||||||
tool_version = '0.0.1'
|
tool_version = '0.1.0'
|
||||||
tool_description = '\n Bump the semantic version of the v.mod and/or specified files.
|
tool_description = '\n Bump the semantic version of the v.mod and/or specified files.
|
||||||
|
|
||||||
The first instance of a version number is replaced with the new version.
|
The first instance of a version number is replaced with the new version.
|
||||||
@ -21,6 +21,11 @@ const (
|
|||||||
version: \'0.2.42\'
|
version: \'0.2.42\'
|
||||||
VERSION = "1.23.8"
|
VERSION = "1.23.8"
|
||||||
|
|
||||||
|
If certain lines need to be skipped, use the --skip option. For instance,
|
||||||
|
the following command will skip lines containing "tool-version":
|
||||||
|
|
||||||
|
v bump --patch --skip "tool-version" [files...]
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
Bump the patch version in v.mod if it exists
|
Bump the patch version in v.mod if it exists
|
||||||
v bump --patch
|
v bump --patch
|
||||||
@ -37,6 +42,7 @@ struct Options {
|
|||||||
major bool
|
major bool
|
||||||
minor bool
|
minor bool
|
||||||
patch bool
|
patch bool
|
||||||
|
skip string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReplacementFunction = fn (re regex.RE, input string, start int, end int) string
|
type ReplacementFunction = fn (re regex.RE, input string, start int, end int) string
|
||||||
@ -85,7 +91,8 @@ fn process_file(input_file string, options Options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if replacement is necessary
|
// Check if replacement is necessary
|
||||||
updated_line := if line.to_lower().contains('version') {
|
updated_line := if line.to_lower().contains('version') && !(options.skip != ''
|
||||||
|
&& line.contains(options.skip)) {
|
||||||
replacement_complete = true
|
replacement_complete = true
|
||||||
re.replace_by_fn(line, repl_fn)
|
re.replace_by_fn(line, repl_fn)
|
||||||
} else {
|
} else {
|
||||||
@ -141,6 +148,12 @@ Try ${tool_name} -h for more help...')
|
|||||||
patch: fp.bool('patch', `p`, false, 'Bump the patch version.')
|
patch: fp.bool('patch', `p`, false, 'Bump the patch version.')
|
||||||
minor: fp.bool('minor', `n`, false, 'Bump the minor version.')
|
minor: fp.bool('minor', `n`, false, 'Bump the minor version.')
|
||||||
major: fp.bool('major', `m`, false, 'Bump the major version.')
|
major: fp.bool('major', `m`, false, 'Bump the major version.')
|
||||||
|
skip: fp.string('skip', `s`, '', 'Skip lines matching this substring.').trim_space()
|
||||||
|
}
|
||||||
|
|
||||||
|
remaining := fp.finalize() or {
|
||||||
|
println(fp.usage())
|
||||||
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.show_help {
|
if options.show_help {
|
||||||
@ -150,7 +163,7 @@ Try ${tool_name} -h for more help...')
|
|||||||
|
|
||||||
validate_options(options) or { panic(err) }
|
validate_options(options) or { panic(err) }
|
||||||
|
|
||||||
files := os.args[3..]
|
files := remaining[1..]
|
||||||
|
|
||||||
if files.len == 0 {
|
if files.len == 0 {
|
||||||
if !os.exists('v.mod') {
|
if !os.exists('v.mod') {
|
||||||
|
@ -78,7 +78,7 @@ fn run_individual_test(case BumpTestCase) ! {
|
|||||||
|
|
||||||
os.rm(test_file) or {}
|
os.rm(test_file) or {}
|
||||||
os.write_file(test_file, case.contents)!
|
os.write_file(test_file, case.contents)!
|
||||||
//
|
|
||||||
os.execute_or_exit('${os.quoted_path(vexe)} bump --patch ${os.quoted_path(test_file)}')
|
os.execute_or_exit('${os.quoted_path(vexe)} bump --patch ${os.quoted_path(test_file)}')
|
||||||
patch_lines := os.read_lines(test_file)!
|
patch_lines := os.read_lines(test_file)!
|
||||||
assert patch_lines[case.line] == case.expected_patch
|
assert patch_lines[case.line] == case.expected_patch
|
||||||
@ -90,7 +90,7 @@ fn run_individual_test(case BumpTestCase) ! {
|
|||||||
os.execute_or_exit('${os.quoted_path(vexe)} bump --major ${os.quoted_path(test_file)}')
|
os.execute_or_exit('${os.quoted_path(vexe)} bump --major ${os.quoted_path(test_file)}')
|
||||||
major_lines := os.read_lines(test_file)!
|
major_lines := os.read_lines(test_file)!
|
||||||
assert major_lines[case.line] == case.expected_major
|
assert major_lines[case.line] == case.expected_major
|
||||||
//
|
|
||||||
os.rm(test_file)!
|
os.rm(test_file)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,3 +99,65 @@ fn test_all_bump_cases() {
|
|||||||
run_individual_test(case) or { panic(err) }
|
run_individual_test(case) or { panic(err) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SkipTestCase {
|
||||||
|
file_name string
|
||||||
|
contents string
|
||||||
|
skip string
|
||||||
|
line int
|
||||||
|
expected_patch string
|
||||||
|
expected_minor string
|
||||||
|
expected_major string
|
||||||
|
}
|
||||||
|
|
||||||
|
const skip_test_cases = [
|
||||||
|
SkipTestCase{
|
||||||
|
file_name: 'CITATION.cff'
|
||||||
|
contents: 'abstract: A sample CLI tool made in V that prints geometric shapes to the screen.
|
||||||
|
authors:
|
||||||
|
- alias: hungrybluedev
|
||||||
|
family-names: Haldar
|
||||||
|
given-names: Subhomoy
|
||||||
|
cff-version: 1.2.0
|
||||||
|
date-released: 2023-04-20
|
||||||
|
license: MIT
|
||||||
|
message: Please cite this software using these information.
|
||||||
|
repository-code: https://github.com/hungrybluedev/geo
|
||||||
|
title: geo
|
||||||
|
url: https://github.com/hungrybluedev/geo
|
||||||
|
version: 0.2.4
|
||||||
|
'
|
||||||
|
line: 12
|
||||||
|
skip: 'cff-version'
|
||||||
|
expected_patch: 'version: 0.2.5'
|
||||||
|
expected_minor: 'version: 0.3.0'
|
||||||
|
expected_major: 'version: 1.0.0'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
fn run_skip_test(case SkipTestCase) ! {
|
||||||
|
test_file := os.join_path_single(tfolder, case.file_name)
|
||||||
|
|
||||||
|
os.rm(test_file) or {}
|
||||||
|
os.write_file(test_file, case.contents)!
|
||||||
|
|
||||||
|
os.execute_or_exit('${os.quoted_path(vexe)} bump --patch --skip="${case.skip}" ${os.quoted_path(test_file)}')
|
||||||
|
patch_lines := os.read_lines(test_file)!
|
||||||
|
assert patch_lines[case.line] == case.expected_patch
|
||||||
|
|
||||||
|
os.execute_or_exit('${os.quoted_path(vexe)} bump --minor --skip="${case.skip}" ${os.quoted_path(test_file)}')
|
||||||
|
minor_lines := os.read_lines(test_file)!
|
||||||
|
assert minor_lines[case.line] == case.expected_minor
|
||||||
|
|
||||||
|
os.execute_or_exit('${os.quoted_path(vexe)} bump --major --skip="${case.skip}" ${os.quoted_path(test_file)}')
|
||||||
|
major_lines := os.read_lines(test_file)!
|
||||||
|
assert major_lines[case.line] == case.expected_major
|
||||||
|
|
||||||
|
os.rm(test_file)!
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_all_skip_bump_cases() ! {
|
||||||
|
for case in skip_test_cases {
|
||||||
|
run_skip_test(case) or { panic(err) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -11,7 +11,12 @@ recognized by the heuristic:
|
|||||||
tool_version = '1.2.1'
|
tool_version = '1.2.1'
|
||||||
version: '0.2.42'
|
version: '0.2.42'
|
||||||
VERSION = "1.23.8"
|
VERSION = "1.23.8"
|
||||||
|
|
||||||
|
If certain lines need to be skipped, use the --skip option. For instance,
|
||||||
|
the following command will skip lines containing "tool-version":
|
||||||
|
|
||||||
|
v bump --patch --skip "tool-version" [files...]
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
Bump the patch version in v.mod if it exists
|
Bump the patch version in v.mod if it exists
|
||||||
v bump --patch
|
v bump --patch
|
||||||
@ -22,7 +27,8 @@ Examples:
|
|||||||
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help Show this help text.
|
-h, --help Show this help text.
|
||||||
-m, --major Bump the major version.
|
-m, --major Bump the major version.
|
||||||
-n, --minor Bump the minor version.
|
-n, --minor Bump the minor version.
|
||||||
-p, --patch Bump the patch version.
|
-p, --patch Bump the patch version.
|
||||||
|
-s, --skip <string> Skip lines matching this substring.
|
||||||
|
Loading…
Reference in New Issue
Block a user