update_git_version.d 928 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env dub --single
  2. /+dub.sdl:
  3. name "update_git_version"
  4. targetType "executable"
  5. +/
  6. void replaceContents(string inputFileName, string outputFileName, string replaceMark, string content)
  7. {
  8. import std.file: readText, write;
  9. import std.string: replace;
  10. auto inputContent = readText(inputFileName);
  11. auto outputContent = replace(inputContent, replaceMark, content);
  12. write(outputFileName, outputContent);
  13. }
  14. int main(string[] args)
  15. {
  16. import std.process: execute;
  17. import std.stdio: stderr;
  18. import std.string: strip;
  19. if (args.length < 3) {
  20. stderr.writefln("error: expected two arguments: <input> <output>");
  21. return 1;
  22. }
  23. auto output = execute(["git", "rev-parse", "--short", "HEAD"]);
  24. if (output.status != 0) {
  25. replaceContents(args[1], args[2], "@VCS_TAG@", "release");
  26. }
  27. replaceContents(args[1], args[2], "@VCS_TAG@", strip(output.output));
  28. return 0;
  29. }