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,6 +2,16 @@
import pico from 'picocolors'
import { readFileSync } from 'node:fs'
import path from 'node:path'
import { exec } from './utils.js'
main()
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()
@ -26,3 +36,4 @@ if (!commitRE.test(msg)) {
)
process.exit(1)
}
}