Skip to content

Commit 94de007

Browse files
committed
fix(mcl.utils.path.rootDir): Handle the case where we're not in a git repo
Which is the case when `actions/checkout` has not been ran.
1 parent 3bf7853 commit 94de007

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/mcl/src/src/mcl/commands/ci_matrix.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ unittest
422422

423423
void saveGHCIComment(SummaryTableEntry[] tableSummaryJSON)
424424
{
425-
import std.path : buildPath, absolutePath;
425+
import std.path : buildNormalizedPath, absolutePath;
426426

427427
string comment = "Thanks for your Pull Request!";
428428
comment ~= "\n\nBelow you will find a summary of the cachix status of each package, for each supported platform.";
@@ -432,7 +432,7 @@ void saveGHCIComment(SummaryTableEntry[] tableSummaryJSON)
432432
pkg => "\n| " ~ pkg.name ~ " | " ~ pkg.x86_64.linux ~ " | " ~ pkg.x86_64.darwin ~ " | " ~ pkg.aarch64.darwin ~ " |")
433433
.join("");
434434

435-
auto outputPath = rootDir.buildPath("comment.md").absolutePath;
435+
auto outputPath = rootDir.buildNormalizedPath("comment.md");
436436
write(outputPath, comment);
437437
infof("Wrote GitHub comment file to '%s'", outputPath);
438438
}

packages/mcl/src/src/mcl/utils/path.d

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
module mcl.utils.path;
2-
import mcl.utils.test;
32

43
import std.process : execute;
54
import std.string : strip;
65
import std.file : mkdirRecurse, rmdir, exists;
7-
import std.path : buildPath;
6+
import std.path : buildNormalizedPath, absolutePath;
87

98
immutable string rootDir, resultDir, gcRootsDir;
109

1110
shared static this()
1211
{
1312
rootDir = getTopLevel();
14-
resultDir = rootDir.buildPath(".result");
15-
gcRootsDir = resultDir.buildPath("gc-roots");
13+
resultDir = rootDir.buildNormalizedPath(".result");
14+
gcRootsDir = resultDir.buildNormalizedPath("gc-roots");
1615
}
1716

1817
string getTopLevel()
@@ -23,7 +22,11 @@ string getTopLevel()
2322
if (isNixbld)
2423
return environment["NIX_BUILD_TOP"];
2524

26-
return execute(["git", "rev-parse", "--show-toplevel"]).output.strip;
25+
auto res = execute(["git", "rev-parse", "--show-toplevel"]);
26+
if (res.status != 0)
27+
return ".".absolutePath.buildNormalizedPath;
28+
29+
return res.output.strip;
2730
}
2831

2932
@("rootDir")
@@ -35,13 +38,13 @@ unittest
3538
@("resultDir")
3639
unittest
3740
{
38-
assert(resultDir == rootDir.buildPath(".result"));
41+
assert(resultDir == rootDir.buildNormalizedPath(".result"));
3942
}
4043

4144
@("gcRootsDir")
4245
unittest
4346
{
44-
assert(gcRootsDir == resultDir.buildPath("gc-roots"));
47+
assert(gcRootsDir == resultDir.buildNormalizedPath("gc-roots"));
4548
}
4649

4750
void createResultDirs()

0 commit comments

Comments
 (0)