From 058605802eafefc79644624dc19e0bebdf4c7ae9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Wed, 7 Aug 2024 17:26:23 +0800 Subject: [PATCH] workflow only verify commit message on main branch --- scripts/verify-commit.js | 49 ++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/scripts/verify-commit.js b/scripts/verify-commit.js index d37370df02..a08e6fb27a 100644 --- a/scripts/verify-commit.js +++ b/scripts/verify-commit.js @@ -2,27 +2,38 @@ import pico from 'picocolors' import { readFileSync } from 'node:fs' import path from 'node:path' +import { exec } from './utils.js' -const msgPath = path.resolve('.git/COMMIT_EDITMSG') -const msg = readFileSync(msgPath, 'utf-8').trim() +main() -const commitRE = - /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ +async function main() { + const { stdout: branch } = await exec('git', ['branch', '--show-current']) + // only verify commit message on main and minor branches + if (branch !== 'main' && branch !== 'minor') { + return + } -if (!commitRE.test(msg)) { - console.log() - console.error( - ` ${pico.white(pico.bgRed(' ERROR '))} ${pico.red( - `invalid commit message format.`, - )}\n\n` + - pico.red( - ` Proper commit message format is required for automated changelog generation. Examples:\n\n`, - ) + - ` ${pico.green(`feat(compiler): add 'comments' option`)}\n` + - ` ${pico.green( - `fix(v-model): handle events on blur (close #28)`, + const msgPath = path.resolve('.git/COMMIT_EDITMSG') + const msg = readFileSync(msgPath, 'utf-8').trim() + + const commitRE = + /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ + + if (!commitRE.test(msg)) { + console.log() + console.error( + ` ${pico.white(pico.bgRed(' ERROR '))} ${pico.red( + `invalid commit message format.`, )}\n\n` + - pico.red(` See .github/commit-convention.md for more details.\n`), - ) - process.exit(1) + pico.red( + ` Proper commit message format is required for automated changelog generation. Examples:\n\n`, + ) + + ` ${pico.green(`feat(compiler): add 'comments' option`)}\n` + + ` ${pico.green( + `fix(v-model): handle events on blur (close #28)`, + )}\n\n` + + pico.red(` See .github/commit-convention.md for more details.\n`), + ) + process.exit(1) + } } -- 2.47.2