File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -3,4 +3,6 @@ lint-staged
33#!/bin/sh
44# Husky pre-commit hook to update companion/HELP.md with all action names and descriptions
55node scripts/update-actions-md.js
6- git add companion/HELP.md
6+ git add companion/HELP.md
7+
8+ node scripts/check-tag.js
Original file line number Diff line number Diff line change 1+ import { execSync } from 'child_process'
2+ import * as fs from 'fs'
3+
4+ function run ( cmd ) {
5+ try {
6+ return execSync ( cmd , { stdio : [ 'ignore' , 'pipe' , 'ignore' ] } )
7+ . toString ( )
8+ . trim ( )
9+ } catch {
10+ return null
11+ }
12+ }
13+
14+ if ( ! fs . existsSync ( 'package.json' ) ) {
15+ throw new Error ( 'package.json not found' )
16+ }
17+
18+ const tag = run ( 'git describe --tags --abbrev=0' )
19+
20+ if ( ! tag ) {
21+ throw new Error ( 'No git tag found on this branch' )
22+ }
23+
24+ if ( ! / ^ v \d + ( \. \d + ) { 2 , 3 } $ / . test ( tag ) ) {
25+ throw new Error ( `Latest tag '${ tag } ' does not match vX.Y.Z or vX.Y.Z.W` )
26+ }
27+
28+ let pkg
29+ try {
30+ pkg = JSON . parse ( fs . readFileSync ( 'package.json' , 'utf8' ) )
31+ } catch {
32+ throw new Error ( 'Cannot parse package.json' )
33+ }
34+
35+ const pkgVersion = pkg . version
36+ const tagVersion = tag . slice ( 1 )
37+
38+ if ( pkgVersion !== tagVersion ) {
39+ throw new Error ( `ERROR: package.json version (${ pkgVersion } ) does not match git tag (${ tag } )` )
40+ }
41+
42+ console . log ( `Git tag '${ tag } ' matches package.json version '${ pkgVersion } '` )
You can’t perform that action at this time.
0 commit comments