2020-06-11 08:33:49 +02:00
|
|
|
|
const { context } = require("@actions/github");
|
|
|
|
|
const core = require("@actions/core");
|
|
|
|
|
|
|
|
|
|
const isValidCommitMessage = message => message.match(/^[a-z].*:/);
|
|
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
|
core.info(
|
|
|
|
|
`ℹ️ Checking if commit messages are following the Conventional Commits specification...`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const hasCommits = context.payload && Array.isArray(context.payload.commits);
|
|
|
|
|
if (!hasCommits) {
|
|
|
|
|
core.info(`No commits to check, skipping...`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-11 08:42:06 +02:00
|
|
|
|
let hasErrors;
|
2020-06-11 08:51:04 +02:00
|
|
|
|
core.startGroup("Commit messages:");
|
2020-06-11 08:33:49 +02:00
|
|
|
|
for (let i = 0; i < context.payload.commits.length; i++) {
|
|
|
|
|
let commit = context.payload.commits[i];
|
2020-06-11 08:42:06 +02:00
|
|
|
|
if (isValidCommitMessage(commit.message)) {
|
|
|
|
|
core.info(`✅ ${commit.message}`);
|
|
|
|
|
} else {
|
|
|
|
|
core.info(`🚩 ${commit.message}`);
|
|
|
|
|
hasErrors = true;
|
2020-06-11 08:33:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-11 08:44:55 +02:00
|
|
|
|
core.endGroup();
|
2020-06-11 08:33:49 +02:00
|
|
|
|
|
2020-06-11 08:42:06 +02:00
|
|
|
|
if (hasErrors) {
|
|
|
|
|
core.setFailed(
|
|
|
|
|
`🚫 According to the conventional-commits specification, some of the commit messages are not valid.`
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
core.info("🎉 All commit messages are following the Conventional Commits specification.");
|
|
|
|
|
}
|
2020-06-11 08:33:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
run();
|