sver
Version calculator based on source code.
Description
sver
is small cli command for calculate version based on source code of git repository.
Usage
Calculate version of directory on git repository
Calculate repository root.
$ sver calc .
ef5d3d3db6d5
Calculate sub directory in the repository.
$ sver calc testdata/service1/
3f1bec06015e
Calculate multiple directory and output toml format.
$ sver calc testdata/service1/ testdata/service2/ --output toml
[[versions]]
repository_root = "/home/mitoma/src/github.com/mitoma/sver/"
path = "testdata/service1"
version = "3f1bec06015e"
[[versions]]
repository_root = "/home/mitoma/src/github.com/mitoma/sver/"
path = "testdata/service2"
version = "fd0053eab4b8"
option
name | value |
---|---|
--length | hash length. short=12, long=64 |
--output | output format. version-only, toml, json |
List the source code used for hash calculation.
$ sver list testdata/service2
testdata/lib1/.gitkeep
testdata/lib2/sver.toml
testdata/service1/sver.toml
testdata/service2/sver.toml
...
Validate the configuration files in the repository
$ sver validate
[OK] /sver.toml:[default]
[OK] testdata/cyclic1/sver.toml:[default]
[OK] testdata/cyclic2/sver.toml:[default]
[Fail] testdata/invalid_config1/sver.toml:[default]
invalid_dependency:["unknown/path"]
invalid_exclude:[]
[Fail] testdata/invalid_config2/sver.toml:[default]
invalid_dependency:[]
invalid_exclude:["target"]
[OK] testdata/lib2/sver.toml:[default]
[OK] testdata/service1/sver.toml:[default]
[OK] testdata/service2/sver.toml:[default]
Export dependency files
$ sver list src:prof1
src/sver.toml
src/test1.txt
$ sver export src:prof1
export-dir: /tmp/sver-export-018ae55f-59a7-76e5-b836-619928cd0c8
$ tree /tmp/sver-export-018ae55f-59a7-76e5-b836-619928cd0c8
/tmp/sver-export-018ae55f-59a7-76e5-b836-619928cd0c8
└── src
├── sver.toml
└── test1.txt
(Experimental) List files accessed by a command
Lists which files on the Git repository were referenced by a command when it was executed.
This command is experimental for Linux only.
$ sver inspect -- cargo fmt --all
Cargo.toml
src/cli/args.rs
src/cli/mod.rs
src/cli/outputs.rs
src/filemode.rs
src/inspect.rs
src/lib.rs
src/main.rs
src/sver_config.rs
src/sver_repository.rs
tests/integration_test.rs
tests/test_tool.rs
Config
By placing a sver.toml
file, you can add dependent directories and files to the directory to be calculated.
sver.toml
is a configuration file for defining directory dependencies.
key | notes |
---|---|
<profile> | Profile. default value is "default". |
<profile>.dependencies[] | Dependency files of directories. Set relative path from repository root. |
<profile>.excludes[] | Exclude files of directories. Set relative path from target directory |
example1
service1 depends on lib1 directory.
.
├── README.md
├── libs1
│ └── lib.rs
└── service1
├── main.rs
└── sver.toml (1)
sver.toml (1)
[default]
# path from the root
dependencies = [
"lib1",
]
excludes = []
example2
service1 ignore service1/doc directory.
.
├── README.md
├── libs1
│ └── lib.rs
└── service1
├── main.rs
├── sver.toml (2)
└── doc
└── design.md
sver.toml (2)
[default]
dependencies = [
"lib1",
]
# path from the service1 directory
excludes = [
"doc",
]
profile support
If you want to switch between multiple source sets in version calculations, you can use profiles.
The profile is specified in the <path>:<profile>
format.
ex)
sver calc lib1:build
sver calc .:default .:build
sver list .:test
example3
add build profile for ignore tests.
.
├── README.md
├── src
│ └── lib.rs
├── tests
│ └── test.rs
└── sver.toml (3)
sver.toml (3)
[default]
dependencies = []
[build]
excludes = ["README.md", "tests"]
Use on GitHub Actions
If you want to use GitHub Actions, you can use sver-actions.