Skip to content

Commit

Permalink
fix: single commit branches: Do not fail on target main branches that…
Browse files Browse the repository at this point in the history
… have single commit.
  • Loading branch information
duki994 committed Jan 4, 2023
1 parent 177b483 commit 133adb8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
19 changes: 16 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13755,17 +13755,23 @@ let BASE_SHA;
process.stdout.write('\n');
process.stdout.write(`NOTE: You can instead make this a hard error by setting 'error-on-no-successful-workflow' on the action in your workflow.\n`);

BASE_SHA = execSync(`git rev-parse origin/${mainBranchName}~1`, { encoding: 'utf-8' });
let getBaseShaCommand = `git rev-parse origin/${mainBranchName}`;
const commitCountOutput = execSync(`git rev-list --count origin/${mainBranchName}`, { encoding: 'utf-8' });
const commitCount = parseInt(stripNewLineEndings(commitCountOutput), 10);
if (commitCount > 1) {
getBaseShaCommand = `${getBaseShaCommand}~1`;
}

BASE_SHA = execSync(getBaseShaCommand, { encoding: 'utf-8' });
core.setOutput('noPreviousBuild', 'true');
}
} else {
process.stdout.write('\n');
process.stdout.write(`Found the last successful workflow run on 'origin/${mainBranchName}'\n`);
process.stdout.write(`Commit: ${BASE_SHA}\n`);
}
}

const stripNewLineEndings = sha => sha.replace('\n', '');
}
core.setOutput('base', stripNewLineEndings(BASE_SHA));
core.setOutput('head', stripNewLineEndings(HEAD_SHA));
})();
Expand Down Expand Up @@ -13843,6 +13849,13 @@ async function commitExists(commitSha) {
}
}

/**
* Strips LF line endings from given string
* @param {string} string
*/
function stripNewLineEndings(string) {
return string.replace('\n', '');
}
})();

module.exports = __webpack_exports__;
Expand Down
20 changes: 17 additions & 3 deletions find-successful-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,23 @@ let BASE_SHA;
process.stdout.write('\n');
process.stdout.write(`NOTE: You can instead make this a hard error by setting 'error-on-no-successful-workflow' on the action in your workflow.\n`);

BASE_SHA = execSync(`git rev-parse origin/${mainBranchName}~1`, { encoding: 'utf-8' });
let getBaseShaCommand = `git rev-parse origin/${mainBranchName}`;
const commitCountOutput = execSync(`git rev-list --count origin/${mainBranchName}`, { encoding: 'utf-8' });
const commitCount = parseInt(stripNewLineEndings(commitCountOutput), 10);
if (commitCount > 1) {
getBaseShaCommand = `${getBaseShaCommand}~1`;
}

BASE_SHA = execSync(getBaseShaCommand, { encoding: 'utf-8' });
core.setOutput('noPreviousBuild', 'true');
}
} else {
process.stdout.write('\n');
process.stdout.write(`Found the last successful workflow run on 'origin/${mainBranchName}'\n`);
process.stdout.write(`Commit: ${BASE_SHA}\n`);
}
}

const stripNewLineEndings = sha => sha.replace('\n', '');
}
core.setOutput('base', stripNewLineEndings(BASE_SHA));
core.setOutput('head', stripNewLineEndings(HEAD_SHA));
})();
Expand Down Expand Up @@ -134,3 +140,11 @@ async function commitExists(commitSha) {
return false;
}
}

/**
* Strips LF line endings from given string
* @param {string} string
*/
function stripNewLineEndings(string) {
return string.replace('\n', '');
}

0 comments on commit 133adb8

Please sign in to comment.