should-semantic-release
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -0,2 +1,3 @@ | ||
export * from "./cli.js"; | ||
export * from "./shouldSemanticRelease.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,2 +1,3 @@ | ||
export * from "./cli.js"; | ||
export * from "./shouldSemanticRelease.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,3 @@ | ||
export declare function shouldSemanticRelease(): Promise<boolean>; | ||
import { ShouldSemanticReleaseOptions } from "./types.js"; | ||
export declare function shouldSemanticRelease({ verbose, }: ShouldSemanticReleaseOptions): Promise<boolean>; | ||
//# sourceMappingURL=shouldSemanticRelease.d.ts.map |
@@ -5,10 +5,16 @@ import conventionalCommitsParser from "conventional-commits-parser"; | ||
const ignoredTypes = new Set(["chore", "docs"]); | ||
export async function shouldSemanticRelease() { | ||
export async function shouldSemanticRelease({ verbose, }) { | ||
const rawHistory = await execOrThrow(`git log --pretty=format:"%s"`); | ||
const history = rawHistory.split("\n"); | ||
for (let i = 0; i < history.length; i += 1) { | ||
const message = history[i]; | ||
const log = verbose | ||
? console.log.bind(console) | ||
: // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
() => { }; | ||
log(`Checking up to ${history.length} commits for release readiness...`); | ||
for (const message of history) { | ||
log(`Checking commit: ${message}`); | ||
// If the commit is a release, we should only release if other commits have been found | ||
if (isReleaseCommit(message)) { | ||
return !!i; | ||
log(`Found a release commit. Returning false.`); | ||
return false; | ||
} | ||
@@ -18,8 +24,11 @@ // Otherwise, we should release if a non-ignored commit type is found | ||
if (type && !ignoredTypes.has(type)) { | ||
log(`Found a meaningful commit. Returning true.`); | ||
return true; | ||
} | ||
log(`Found type ${type}. Continuing.`); | ||
} | ||
// If we've seen every commit in the history and none match, don't release | ||
log("No commits found that indicate a semantic release is necessary. Returning false."); | ||
return false; | ||
} | ||
//# sourceMappingURL=shouldSemanticRelease.js.map |
{ | ||
"author": "Josh Goldberg <npm@joshuakgoldberg.com>", | ||
"bin": "./bin/should-semantic-release.mjs", | ||
"bin": "./bin/should-semantic-release", | ||
"dependencies": { | ||
@@ -12,3 +12,3 @@ "conventional-commits-parser": "^3.2.4" | ||
"@typescript-eslint/parser": "^5.48.0", | ||
"@vitest/coverage-istanbul": "^0.26.3", | ||
"@vitest/coverage-istanbul": "^0.28.0", | ||
"cspell": "^6.18.1", | ||
@@ -23,5 +23,5 @@ "eslint": "^8.31.0", | ||
"eslint-plugin-regexp": "^1.12.0", | ||
"eslint-plugin-simple-import-sort": "^8.0.0", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
"eslint-plugin-typescript-sort-keys": "^2.1.0", | ||
"eslint-plugin-vitest": "^0.0.25", | ||
"eslint-plugin-vitest": "^0.0.32", | ||
"husky": "^8.0.3", | ||
@@ -40,3 +40,3 @@ "jsonc-eslint-parser": "^2.1.0", | ||
"typescript": "^4.9.4", | ||
"vitest": "^0.26.3" | ||
"vitest": "^0.28.0" | ||
}, | ||
@@ -52,3 +52,3 @@ "engines": { | ||
"name": "should-semantic-release", | ||
"packageManager": "pnpm@7.23.0", | ||
"packageManager": "pnpm@7.26.3", | ||
"repository": { | ||
@@ -71,3 +71,3 @@ "type": "git", | ||
"type": "module", | ||
"version": "0.0.1" | ||
"version": "0.0.2" | ||
} |
@@ -31,12 +31,55 @@ <h1 align="center">Should Semantic Release</h1> | ||
This CLI script determines whether a semantic release should occur for a package based on Git history. | ||
Specifically, it returns truthy only if a commit whose type _isn't_ `chore` or `docs` has come since the most recent release commit. | ||
```shell | ||
npm i should-semantic-release | ||
if npx should-semantic-release ; then npx release-it ; fi | ||
``` | ||
This can be useful, for example, to [prevent a `release-it` release](https://github.com/release-it/release-it/issues/969): | ||
```json | ||
{ | ||
"hooks": { | ||
"before:bump": "if ! npx should-semantic-release ; then exit 1 ; fi" | ||
} | ||
} | ||
``` | ||
`should-semantic-release` accepts the following CLI flag: | ||
- `-v`/`--verbose` _(default: `false`)_: Whether to log debug information to the console | ||
```plaintext | ||
$ npx should-semantic-release | ||
Checking up to 123 commits for release readiness... | ||
Checking commit: chore: an example chore (#101) | ||
Found type chore. | ||
Checking commit: chore: another example chore (#100) | ||
Found type chore. | ||
Checking commit: chore: release v1.27.31 | ||
This is a release commit. Returning false. | ||
``` | ||
### Node API | ||
Alternately, you can call this import asynchronous `shouldSemanticRelease` function into Node scripts: | ||
```ts | ||
import { greet } from "should-semantic-release"; | ||
import { shouldSemanticRelease } from "should-semantic-release"; | ||
greet("Hello, world!"); | ||
if (await shouldSemanticRelease()) { | ||
console.log("Let's release! 🚀"); | ||
} | ||
``` | ||
`shouldSemanticRelease` accepts an optional options object with the following parameter: | ||
- `verbose` _(default: `false`)_ | ||
```js | ||
await shouldSemanticRelease({ verbose: true }); | ||
``` | ||
## Development | ||
@@ -43,0 +86,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17461
29
120
73