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,14 +2,24 @@
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() {
const { stdout: branch } = await exec('git', ['branch', '--show-current'])
// only verify commit message on main and minor branches
if (branch !== 'main' && branch !== 'minor') {
return
}
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}/ /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
if (!commitRE.test(msg)) { if (!commitRE.test(msg)) {
console.log() console.log()
console.error( console.error(
` ${pico.white(pico.bgRed(' ERROR '))} ${pico.red( ` ${pico.white(pico.bgRed(' ERROR '))} ${pico.red(
@ -25,4 +35,5 @@ if (!commitRE.test(msg)) {
pico.red(` See .github/commit-convention.md for more details.\n`), pico.red(` See .github/commit-convention.md for more details.\n`),
) )
process.exit(1) process.exit(1)
}
} }