Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
ci: fail build if there are uncommitted changes after transpiling
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Feb 27, 2024
1 parent f080432 commit bbf0fcf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: dotnet run --set-version

- name: Build Fusion
run: dotnet run
run: dotnet run --ci

- name: Cargo Publish
working-directory: for-rust
Expand Down
30 changes: 28 additions & 2 deletions build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
string projectDir = GetMsbuildParameter("RootProjectDir");

var setVersionArg = new Option<bool>("--set-version", "-v");
var isciArg = new Option<bool>("--ci");
var rootCommand = new Command("build") {
setVersionArg,
isciArg,
};
ParseResult parseResult = rootCommand.Parse(args);

Expand All @@ -29,6 +31,30 @@
var macros = LoadNativeMacros();
RunAll(BuildRust, BuildJs, BuildCpp, BuildCs);

// check for untracked changes in ci mode
if (parseResult.GetValueForOption(isciArg))
{
GetProcessOutput("git", "update-index --refresh", projectDir, throwNonZeroExit: false);
GetProcessOutput("git", "git add .", projectDir, throwNonZeroExit: false);
var status = GetProcessOutput("git", "status --porcelain", projectDir, throwNonZeroExit: false);
if (!String.IsNullOrEmpty(status))
{
var untrackedFiles = status.Split('\n', 'r', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Where(x => !x.Contains("package.json"))
.Where(x => !x.Contains("Cargo.toml"))
.Where(x => !x.Contains("Cargo.lock"))
.ToList();

if (untrackedFiles.Any())
{
Console.WriteLine();
Error("CI MODE: Untracked changes detected. Please build fusion before pushing commits.");
Error("The following files have been modified: " + "\n - " + String.Join("\n - ", untrackedFiles));
Environment.Exit(1);
}
}
}

void BuildRust(StringBuilder sb)
{
RunProcess(sb, "cargo", "check", Path.Combine(projectDir, "for-rust"));
Expand Down Expand Up @@ -374,7 +400,7 @@ void RunProcess(StringBuilder sb, string processPath, string arguments, string w
process.BeginOutputReadLine();
process.WaitForExit();

if (process.ExitCode != 0)
if (throwNonZeroExit && process.ExitCode != 0)
{
throw new Exception($"Process exited with code {process.ExitCode}");
}
Expand Down Expand Up @@ -411,7 +437,7 @@ string GetProcessOutput(string processPath, string arguments, string workDir, bo
process.BeginOutputReadLine();
process.WaitForExit();

if (process.ExitCode != 0)
if (throwNonZeroExit && process.ExitCode != 0)
{
throw new Exception($"Process exited with code {process.ExitCode}");
}
Expand Down

0 comments on commit bbf0fcf

Please sign in to comment.