Skip to content

Commit dd40be3

Browse files
committed
chore(ghPagesDeploy): check for changes before trying to commit
1 parent d6b4858 commit dd40be3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

scripts/ghPagesDeploy.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ function main() {
105105
// add stage all changes
106106
execSync('git add *', { stdio: 'inherit' });
107107

108+
if (!hasChanges()) {
109+
console.log('No changes, exiting');
110+
111+
return;
112+
}
113+
108114
let commitmsg = commitMessage;
109115
const githubSHA = process.env['GITHUB_SHA'];
110116

@@ -130,6 +136,26 @@ function main() {
130136

131137
main();
132138

139+
/**
140+
* Check if the current git repo has changes staged
141+
* @returns {boolean} `true` if there are changes staged, `false` otherwise
142+
*/
143+
function hasChanges() {
144+
try {
145+
// the following command exists with "0" if there are no changes, otherwise "1"
146+
execSync('git diff-index --quiet HEAD --');
147+
148+
return false;
149+
} catch (err) {
150+
// check if the error is a childprocess error, which will always have a "status" property
151+
if (!!err.status) {
152+
return true;
153+
}
154+
155+
throw err;
156+
}
157+
}
158+
133159
/**
134160
* Generate the versions.json file
135161
* @returns Object with keys sorted so that "beta" is first and otherwise the highest number descending

0 commit comments

Comments
 (0)