Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Commit b727492

Browse files
committed
chore: updates tests with publish rollback, adds new demo gif
1 parent 7b11c5b commit b727492

File tree

16 files changed

+77
-52
lines changed

16 files changed

+77
-52
lines changed

.release-workspaces.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"metadata": {
3-
"version": "0.7.14"
3+
"version": "0.7.18"
44
}
55
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<a href="https://github.com/geotrev/release-workspaces/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/release-workspaces.svg?sanitize=true&style=flat-square" alt="License"></a>
66
<a href="https://github.com/geotrev/release-workspaces/actions/workflows/test.yml?query=branch%3Amain"><img src="https://badgen.net/github/checks/geotrev/release-workspaces/main?style=flat-square" alt="CI status" /></a>
77
<div align="center">
8-
<img width="600px" height="auto" src="https://github.com/geotrev/release-workspaces/raw/main/demo2.gif" />
8+
<img width="500px" height="auto" src="https://github.com/geotrev/release-workspaces/raw/main/demo3.gif" />
99
</div>
1010
</p>
1111

bin/__tests__/git.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import "../../.jest/mocks.js"
22
import { ReportSteps } from "../helpers/constants.js"
33
import { getCommitCmd, getTagCmd, getPushCmd } from "../helpers/commands.js"
44
import { setVersionToString } from "../helpers/transformers.js"
5-
import { setRollback } from "../helpers/rollback.js"
5+
import { queueRollback } from "../helpers/rollback.js"
66
import { reportCmd } from "../helpers/cmd.js"
77
import { runGit } from "../modules/git.js"
88

@@ -12,7 +12,7 @@ jest.mock("../helpers/cmd.js", () => ({
1212
}))
1313

1414
jest.mock("../helpers/rollback.js", () => ({
15-
setRollback: jest.fn(),
15+
queueRollback: jest.fn(),
1616
}))
1717

1818
const baseConfig = {
@@ -91,8 +91,8 @@ describe("runGit()", () => {
9191
)
9292
})
9393

94-
it("calls setRollback", async () => {
95-
expect(setRollback).toBeCalledWith(
94+
it("calls queueRollback", async () => {
95+
expect(queueRollback).toBeCalledWith(
9696
expect.objectContaining(config),
9797
expect.objectContaining({
9898
type: "commit",
@@ -167,8 +167,8 @@ describe("runGit()", () => {
167167
)
168168
})
169169

170-
it("calls setRollback", async () => {
171-
expect(setRollback).toBeCalledWith(
170+
it("calls queueRollback", async () => {
171+
expect(queueRollback).toBeCalledWith(
172172
expect.objectContaining(config),
173173
expect.objectContaining({
174174
type: "tag",

bin/__tests__/npm.spec.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ReportSteps } from "../helpers/constants.js"
44
import { getAddCommand } from "../helpers/commands.js"
55
import { report } from "../helpers/reporter.js"
66
import { reportCmd, cmd } from "../helpers/cmd.js"
7-
import { setRollback } from "../helpers/rollback.js"
7+
import { queueRollback } from "../helpers/rollback.js"
88
import { setRootVersion } from "../helpers/set-root-version.js"
99
import { runNpm } from "../modules/npm.js"
1010
import { runIncrement } from "../modules/increment.js"
@@ -21,7 +21,7 @@ jest.mock("../helpers/set-root-version.js", () => ({
2121
setRootVersion: jest.fn(),
2222
}))
2323
jest.mock("../helpers/rollback.js", () => ({
24-
setRollback: jest.fn(),
24+
queueRollback: jest.fn(),
2525
}))
2626
jest.mock("../modules/increment.js", () => ({
2727
runIncrement: jest.fn(),
@@ -140,14 +140,27 @@ describe("runNpm()", () => {
140140
// When
141141
await runNpm(config)
142142
// Then
143-
expect(setRollback).toBeCalledWith(
143+
expect(queueRollback).toBeCalledWith(
144144
expect.objectContaining(config),
145145
expect.objectContaining({
146146
type: "increment",
147147
callback: expect.any(Function),
148148
})
149149
)
150150
})
151+
152+
it("adds publish action", async () => {
153+
// when
154+
await runNpm(config)
155+
// Then
156+
expect(queueRollback).toBeCalledWith(
157+
expect.objectContaining(config),
158+
expect.objectContaining({
159+
type: "publish",
160+
callback: expect.any(Function),
161+
})
162+
)
163+
})
151164
})
152165

153166
describe("hooks", () => {

bin/__tests__/publish.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jest.mock("../helpers/reporter.js", () => ({
1212
report: jest.fn(),
1313
}))
1414
jest.mock("../helpers/rollback.js", () => ({
15-
setRollback: jest.fn(),
15+
queueRollback: jest.fn(),
1616
}))
1717

1818
const entry = {

bin/helpers/rollback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function disableRollback() {
3030
process.off("exit", rollback)
3131
}
3232

33-
export function setRollback(config, action) {
33+
export function queueRollback(config, action) {
3434
if (config.dryRun) return
3535
rollbackActions.push(action)
3636
}

bin/modules/git.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ReportSteps } from "../helpers/constants.js"
44
import { getCommitCmd, getTagCmd, getPushCmd } from "../helpers/commands.js"
55
import { setVersionToString } from "../helpers/transformers.js"
66
import { cmd, reportCmd } from "../helpers/cmd.js"
7-
import { setRollback } from "../helpers/rollback.js"
7+
import { queueRollback } from "../helpers/rollback.js"
88

99
export async function runGit(config) {
1010
const {
@@ -31,7 +31,7 @@ export async function runGit(config) {
3131
step: ReportSteps.COMMIT,
3232
})
3333

34-
setRollback(config, {
34+
queueRollback(config, {
3535
type: "commit",
3636
callback: async () => {
3737
await cmd("git reset --hard HEAD~1", config)
@@ -52,7 +52,7 @@ export async function runGit(config) {
5252
await reportCmd(pretag, { ...config, step: ReportSteps.PRETAG })
5353
}
5454

55-
setRollback(config, {
55+
queueRollback(config, {
5656
type: "tag",
5757
callback: async () => {
5858
await cmd(`git tag --delete v${config.releaseVersion}`, config)

bin/modules/npm.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getAddCommand } from "../helpers/commands.js"
66
import { cmd, reportCmd } from "../helpers/cmd.js"
77
import { runIncrement } from "./increment.js"
88
import { runPublish } from "./publish.js"
9-
import { setRollback } from "../helpers/rollback.js"
9+
import { queueRollback } from "../helpers/rollback.js"
1010
import { setRootVersion } from "../helpers/set-root-version.js"
1111

1212
export async function runNpm(config) {
@@ -15,7 +15,7 @@ export async function runNpm(config) {
1515
npm: { increment, publish },
1616
} = config
1717

18-
setRollback(config, {
18+
queueRollback(config, {
1919
type: "increment",
2020
callback: async () => {
2121
await cmd("git reset --hard HEAD", config)
@@ -49,6 +49,18 @@ export async function runNpm(config) {
4949
await reportCmd(prepublish, { ...config, step: ReportSteps.PREPUBLISH })
5050
}
5151

52+
queueRollback(config, {
53+
type: "publish",
54+
callback: async () => {
55+
for (const pkg of config.packages) {
56+
await cmd(
57+
`npm deprecate ${pkg.name}@${config.releaseVersion}`,
58+
config
59+
)
60+
}
61+
},
62+
})
63+
5264
await runPublish(config)
5365

5466
if (postpublish) {

demo2.gif

-430 KB
Binary file not shown.

demo3.gif

222 KB
Loading

0 commit comments

Comments
 (0)