Skip to content

Commit

Permalink
Print git info
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Sep 15, 2023
1 parent 6ad2340 commit a7ef919
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,6 @@ local.properties

# Don't know what's creating this
.project

# Generated git info file
src/main/deploy/git-info.txt
28 changes: 28 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,34 @@ spotless {
trimTrailingWhitespace();
}
}

task writeGitInfo {
def addGitOutput = { PrintStream output, String name, String... args ->
output.println("### $name (git ${String.join(' ', args)})")
def execOutput = new ByteArrayOutputStream()
def ex = exec {
workingDir projectDir
executable 'git'
delegate.args args
standardOutput = execOutput
}
output.print(execOutput)
}

doLast {
try (PrintStream output = new PrintStream('src\\main\\deploy\\git-info.txt')) {
addGitOutput(output, 'Latest commit', 'log', '-1', '--decorate=short', '--format=medium')
addGitOutput(output, 'Changed files', 'diff-index', '--name-only', 'HEAD', '--')
addGitOutput(output, 'Untracked files', 'ls-files', '--exclude-standard', '--others')
output.println('### (END)')
}
}
}
if (getProjectBooleanProperty('jarWriteGitInfo', true)) {
jar.dependsOn(writeGitInfo)
}

// Set up spotless
tasks.named("build") { finalizedBy("spotlessApply") }
tasks.named("deploy") { finalizedBy("spotlessApply") }
spotlessCheck.mustRunAfter(compileJava);
14 changes: 14 additions & 0 deletions src/main/java/frc/team2412/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import frc.team2412.robot.sim.PhysicsSim;
import frc.team2412.robot.util.MACAddress;
import frc.team2412.robot.util.auto.AutonomousChooser;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Optional;

Expand Down Expand Up @@ -103,6 +106,17 @@ public void robotInit() {
DriverStation.silenceJoystickConnectionWarning(true);

PathPlannerServer.startServer(5811);

logRobotInfo();
}

private void logRobotInfo() {
try {
File gitInfoFile = new File(Filesystem.getDeployDirectory(), "git-info.txt");
System.out.println("Git info:\n" + Files.readString(gitInfoFile.toPath()));
} catch (IOException e) {
DriverStation.reportWarning("Could not open git info file", true);
}
}

public SwerveAutoBuilder getAutoBuilder(HashMap<String, Command> eventMap) {
Expand Down

0 comments on commit a7ef919

Please sign in to comment.