diff --git a/.husky/pre-commit b/.husky/pre-commit index bf8e3e6..89a9bd3 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,6 +1,6 @@ lint-staged - #!/bin/sh + # Husky pre-commit hook to update companion/HELP.md with all action names and descriptions node scripts/update-actions-md.js git add companion/HELP.md \ No newline at end of file diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000..358e804 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,3 @@ +#!/bin/sh + +node scripts/check-tag.js \ No newline at end of file diff --git a/scripts/check-tag.js b/scripts/check-tag.js new file mode 100755 index 0000000..0982bbe --- /dev/null +++ b/scripts/check-tag.js @@ -0,0 +1,42 @@ +import { execSync } from 'child_process' +import * as fs from 'fs' + +function run(cmd) { + try { + return execSync(cmd, { stdio: ['ignore', 'pipe', 'ignore'] }) + .toString() + .trim() + } catch { + return null + } +} + +if (!fs.existsSync('package.json')) { + throw new Error('package.json not found') +} + +const tag = run('git describe --tags --abbrev=0') + +if (!tag) { + throw new Error('No git tag found on this branch') +} + +if (!/^v\d+(\.\d+){2,3}$/.test(tag)) { + throw new Error(`Latest tag '${tag}' does not match vX.Y.Z or vX.Y.Z.W`) +} + +let pkg +try { + pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')) +} catch { + throw new Error('Cannot parse package.json') +} + +const pkgVersion = pkg.version +const tagVersion = tag.slice(1) + +if (pkgVersion !== tagVersion) { + throw new Error(`ERROR: package.json version (${pkgVersion}) does not match git tag (${tag})`) +} + +console.log(`Git tag '${tag}' matches package.json version '${pkgVersion}'`)