12345678910111213141516171819202122232425262728293031323334353637 |
- #!/usr/bin/env dub --single
- /+dub.sdl:
- name "update_git_version"
- targetType "executable"
- +/
- void replaceContents(string inputFileName, string outputFileName, string replaceMark, string content)
- {
- import std.file: readText, write;
- import std.string: replace;
- auto inputContent = readText(inputFileName);
- auto outputContent = replace(inputContent, replaceMark, content);
- write(outputFileName, outputContent);
- }
- int main(string[] args)
- {
- import std.process: execute;
- import std.stdio: stderr;
- import std.string: strip;
- if (args.length < 3) {
- stderr.writefln("error: expected two arguments: <input> <output>");
- return 1;
- }
- auto output = execute(["git", "rev-parse", "--short", "HEAD"]);
- if (output.status != 0) {
- replaceContents(args[1], args[2], "@VCS_TAG@", "release");
- }
- replaceContents(args[1], args[2], "@VCS_TAG@", strip(output.output));
- return 0;
- }
|