workflow only verify commit message on main branch

This commit is contained in:
三咲智子 Kevin Deng 2024-08-07 17:26:23 +08:00
parent 1058ce8e74
commit 058605802e
No known key found for this signature in database
1 changed files with 30 additions and 19 deletions

View File

@ -2,27 +2,38 @@
import pico from 'picocolors' import pico from 'picocolors'
import { readFileSync } from 'node:fs' import { readFileSync } from 'node:fs'
import path from 'node:path' import path from 'node:path'
import { exec } from './utils.js'
const msgPath = path.resolve('.git/COMMIT_EDITMSG') main()
const msg = readFileSync(msgPath, 'utf-8').trim()
const commitRE = async function main() {
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ 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)) { const msgPath = path.resolve('.git/COMMIT_EDITMSG')
console.log() const msg = readFileSync(msgPath, 'utf-8').trim()
console.error(
` ${pico.white(pico.bgRed(' ERROR '))} ${pico.red( const commitRE =
`invalid commit message format.`, /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
)}\n\n` +
pico.red( if (!commitRE.test(msg)) {
` Proper commit message format is required for automated changelog generation. Examples:\n\n`, console.log()
) + console.error(
` ${pico.green(`feat(compiler): add 'comments' option`)}\n` + ` ${pico.white(pico.bgRed(' ERROR '))} ${pico.red(
` ${pico.green( `invalid commit message format.`,
`fix(v-model): handle events on blur (close #28)`,
)}\n\n` + )}\n\n` +
pico.red(` See .github/commit-convention.md for more details.\n`), pico.red(
) ` Proper commit message format is required for automated changelog generation. Examples:\n\n`,
process.exit(1) ) +
` ${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)
}
} }