Skip to content

Commit

Permalink
feat(ci): add commit details to index.html file with each fresh build (
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosPaunovic committed Jul 15, 2024
1 parent 15a6c0e commit adcf205
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ final linterTask = tasks.register('lintFrontend', RunNpm) {
script = 'run test:lint'
}

check.dependsOn linterTask
check.dependsOn linterTask

task addCommitInfo(type: Exec) {
dependsOn assembleFrontend
group = 'Frontend'
description = 'Adds the comment with commit details at the beginning of index.html'

commandLine 'node', 'scripts/commits.js'

workingDir = projectDir
}

assembleFrontend.finalizedBy addCommitInfo
25 changes: 25 additions & 0 deletions ui/scripts/commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require("fs");
const {execSync} = require("child_process");

// Get the last commit hash and date details
const hash = execSync("git rev-parse HEAD").toString().trim();
const date = execSync("git log -1 --format=%cd").toString().trim();

// Prepare the comment to add to the file
const comment = `
<!--
Commit: ${hash}
Date: ${date}
-->
`;

// Define the path to the index.html file
const path = "../webserver/src/main/resources/ui/index.html";

// Read the content of index.html
const content = fs.readFileSync(path, "utf8");

// Write the comment at the beginning of index.html
fs.writeFileSync(path, comment + content);

console.log(`Added commit details to ${path}`);

0 comments on commit adcf205

Please sign in to comment.