Skip to content
This repository was archived by the owner on Feb 25, 2024. It is now read-only.

Commit a65c605

Browse files
committed
Prevent publish-tag-push from running on unclean repo
1 parent bd67f01 commit a65c605

File tree

4 files changed

+172
-1
lines changed

4 files changed

+172
-1
lines changed

tools/publish-tag-push/bin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { main, handleTerminationError } = require('./index')
33

44
main({
55
print: console.info,
6+
printErr: console.error,
67
process,
78
})
89
.catch(handleTerminationError)

tools/publish-tag-push/lib/main.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import fs from 'fs'
2+
import { statusMatrix } from 'isomorphic-git'
3+
import places from '@tools/places'
14
import { Printer } from '../utils/types'
25
import { StyledText, normal, dim, bold } from './styled-text'
36
import { command } from './command'
@@ -15,17 +18,26 @@ export interface Process {
1518

1619
export interface Options {
1720
readonly print: Printer
21+
readonly printErr: Printer
1822
readonly process: Process
1923
}
2024

2125
export async function main(options: Options): Promise<number> {
22-
const { print, process } = options
26+
const { print, printErr, process } = options
2327
const { env } = process
2428
const npm = env.PUBLISH_TAG_PUSH_EXECUTOR || 'npm'
2529
const git = env.PUBLISH_TAG_PUSH_VCS || 'git'
2630
const remote = env.PUBLISH_TAG_PUSH_REMOTE || 'origin'
2731
const branch = env.PUBLISH_TAG_PUSH_BRANCH || 'master'
2832

33+
const changes = await statusMatrix({ fs, dir: places.project })
34+
if (changes.length) {
35+
printErr('[ERROR] Repo is not clean')
36+
for (const [filename] of changes) {
37+
printErr(' → ' + filename)
38+
}
39+
}
40+
2941
const exec = (cmd: StyledText, ...args: StyledText[]) => command(print, cmd, args)
3042
await exec(dim(npm), dim('run'), bold('project-publish'))
3143
await exec(dim(npm), dim('run'), bold('git-tag-versions'))

tools/publish-tag-push/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"bin": "bin.js",
66
"dependencies": {
77
"chalk": "^4.1.0",
8+
"isomorphic-git": "^1.7.4",
89
"advanced-spawn-async": "^0.1.3",
10+
"@tools/places": "file:../places",
911
"@tools/preloaded-node": "file:../preloaded-node"
1012
}
1113
}

tools/publish-tag-push/pnpm-lock.yaml

Lines changed: 156 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)