Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically generate the version based on the git tag
- Loading branch information
1 parent
d574614
commit 116b78e
Showing
4 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ dvm/dvm/dvm | |
bin/dvm | ||
*.deps | ||
.dub | ||
bin/* | ||
bin/* | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import std.file : exists, mkdirRecurse, readText, write; | ||
import std.path : buildPath; | ||
import std.process : execute, env = environment; | ||
import std.string : strip; | ||
|
||
enum outputDirectory = "tmp"; | ||
enum versionFile = "version"; | ||
|
||
void main() | ||
{ | ||
const outputDirectory = env.get("DUB_PACKAGE_DIR", ".").buildPath("tmp"); | ||
|
||
mkdirRecurse(outputDirectory); | ||
|
||
outputDirectory | ||
.buildPath("version") | ||
.updateIfChanged(generateVersion); | ||
} | ||
|
||
string generateVersion() | ||
{ | ||
const result = execute(["git", "describe", "--dirty", "--tags", "--always"]); | ||
|
||
if (result.status != 0) | ||
throw new Exception("Failed to execute 'git describe'"); | ||
|
||
return result.output.strip; | ||
} | ||
|
||
void updateIfChanged(const string path, const string content) | ||
{ | ||
const existingContent = path.exists ? path.readText : ""; | ||
|
||
if (content != existingContent) | ||
write(path, content); | ||
} |