Skip to content

Commit 6d0f46e

Browse files
authored
chore: stop publish smoke from check git clean (#8058)
Im a big proponent of scripts working the same way in ci as they would locally. and that we should be able to run anything the ci does locally. The publish script is used to publish npm and ws packages, but also within a series of smoke tests. Making the flags clear it's either one of the two paths was my goal.
1 parent 9281ebf commit 6d0f46e

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

scripts/publish.js

+24-16
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ const getPublishes = async ({ force }) => {
7272
}
7373

7474
const main = async (opts) => {
75-
const { isLocal, smokePublish, packDestination } = opts
76-
const isPack = !!packDestination
77-
const publishes = await getPublishes({ force: isPack })
75+
const { test, otp, dryRun, smokePublish, packDestination } = opts
76+
77+
const hasPackDest = !!packDestination
78+
const publishes = await getPublishes({ force: smokePublish })
7879

7980
if (!publishes.length) {
8081
throw new Error(
@@ -88,13 +89,15 @@ const main = async (opts) => {
8889
table.push([publish.name, publish.version, publish.tag])
8990
}
9091

92+
const preformOperations = hasPackDest ? ['publish', 'pack'] : ['publish']
93+
9194
const confirmMessage = [
92-
`Ready to ${isPack ? 'pack' : 'publish'} the following packages:`,
95+
`Ready to ${preformOperations.join(',')} the following packages:`,
9396
table.toString(),
94-
isPack ? null : 'Ok to proceed? ',
97+
smokePublish ? null : 'Ok to proceed? ',
9598
].filter(Boolean).join('\n')
9699

97-
if (isPack) {
100+
if (smokePublish) {
98101
log.info(confirmMessage)
99102
} else {
100103
const confirm = await read({ prompt: confirmMessage, default: 'y' })
@@ -109,38 +112,43 @@ const main = async (opts) => {
109112
await npm('rm', '--global', '--force', 'npm')
110113
await npm('link', '--force', '--ignore-scripts')
111114

112-
if (opts.test) {
115+
if (test) {
113116
await npm('run', 'lint-all', '--ignore-scripts')
114117
await npm('run', 'postlint', '--ignore-scripts')
115118
await npm('run', 'test-all', '--ignore-scripts')
116119
}
117120

118121
await npm('prune', '--omit=dev', '--no-save', '--no-audit', '--no-fund')
119122
await npm('install', '-w', 'docs', '--ignore-scripts', '--no-audit', '--no-fund')
120-
if (isLocal && smokePublish) {
123+
124+
if (smokePublish) {
121125
log.info(`Skipping git dirty check due to local smoke publish test being run`)
122126
} else {
123127
await git.dirty()
124128
}
125129

130+
let count = -1
126131
for (const publish of publishes) {
132+
log.info(`Publishing ${publish.name}@${publish.version} to ${publish.tag} ${count++}/${publishes.length}`)
127133
const workspace = publish.workspace && `--workspace=${publish.name}`
128134
const publishPkg = (...args) => npm('publish', workspace, `--tag=${publish.tag}`, ...args)
129135

130-
await npm('version', 'prerelease', workspace, '--preid=smoke')
131-
if (isPack) {
136+
if (hasPackDest) {
132137
await npm(
133138
'pack',
134139
workspace,
135-
opts.packDestination && `--pack-destination=${opts.packDestination}`
140+
packDestination && `--pack-destination=${packDestination}`
136141
)
137-
if (smokePublish) {
138-
await publishPkg('--dry-run')
139-
}
142+
}
143+
144+
if (smokePublish) {
145+
// when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run
146+
await npm('version', 'prerelease', workspace, '--preid=smoke', '--ignore-scripts', '--no-git-tag-version')
147+
await publishPkg('--dry-run', '--ignore-scripts')
140148
} else {
141149
await publishPkg(
142-
opts.dryRun && '--dry-run',
143-
opts.otp && `--otp=${opts.otp === 'op' ? await op() : opts.otp}`
150+
dryRun && '--dry-run',
151+
otp && `--otp=${otp === 'op' ? await op() : otp}`
144152
)
145153
}
146154
}

scripts/smoke-publish-test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fi
6666
# were publishing it to the registry. The only difference is in the
6767
# publish.js script which will only pack and not publish
6868
node . version $NPM_VERSION --ignore-scripts --git-tag-version="$IS_CI"
69-
node scripts/publish.js --pack-destination=$RUNNER_TEMP --smoke-publish=true --is-local="$IS_LOCAL"
69+
node scripts/publish.js --pack-destination=$RUNNER_TEMP --smoke-publish=true
7070
NPM_TARBALL="$RUNNER_TEMP/npm-$NPM_VERSION.tgz"
7171
node . install --global $NPM_TARBALL
7272

0 commit comments

Comments
 (0)