Skip to content

Commit

Permalink
chore: stop publish smoke from check git clean (npm#8058)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
reggi authored Jan 27, 2025
1 parent 9281ebf commit 6d0f46e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 24 additions & 16 deletions scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ const getPublishes = async ({ force }) => {
}

const main = async (opts) => {
const { isLocal, smokePublish, packDestination } = opts
const isPack = !!packDestination
const publishes = await getPublishes({ force: isPack })
const { test, otp, dryRun, smokePublish, packDestination } = opts

const hasPackDest = !!packDestination
const publishes = await getPublishes({ force: smokePublish })

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

const preformOperations = hasPackDest ? ['publish', 'pack'] : ['publish']

const confirmMessage = [
`Ready to ${isPack ? 'pack' : 'publish'} the following packages:`,
`Ready to ${preformOperations.join(',')} the following packages:`,
table.toString(),
isPack ? null : 'Ok to proceed? ',
smokePublish ? null : 'Ok to proceed? ',
].filter(Boolean).join('\n')

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

if (opts.test) {
if (test) {
await npm('run', 'lint-all', '--ignore-scripts')
await npm('run', 'postlint', '--ignore-scripts')
await npm('run', 'test-all', '--ignore-scripts')
}

await npm('prune', '--omit=dev', '--no-save', '--no-audit', '--no-fund')
await npm('install', '-w', 'docs', '--ignore-scripts', '--no-audit', '--no-fund')
if (isLocal && smokePublish) {

if (smokePublish) {
log.info(`Skipping git dirty check due to local smoke publish test being run`)
} else {
await git.dirty()
}

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

await npm('version', 'prerelease', workspace, '--preid=smoke')
if (isPack) {
if (hasPackDest) {
await npm(
'pack',
workspace,
opts.packDestination && `--pack-destination=${opts.packDestination}`
packDestination && `--pack-destination=${packDestination}`
)
if (smokePublish) {
await publishPkg('--dry-run')
}
}

if (smokePublish) {
// 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
await npm('version', 'prerelease', workspace, '--preid=smoke', '--ignore-scripts', '--no-git-tag-version')
await publishPkg('--dry-run', '--ignore-scripts')
} else {
await publishPkg(
opts.dryRun && '--dry-run',
opts.otp && `--otp=${opts.otp === 'op' ? await op() : opts.otp}`
dryRun && '--dry-run',
otp && `--otp=${otp === 'op' ? await op() : otp}`
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/smoke-publish-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fi
# were publishing it to the registry. The only difference is in the
# publish.js script which will only pack and not publish
node . version $NPM_VERSION --ignore-scripts --git-tag-version="$IS_CI"
node scripts/publish.js --pack-destination=$RUNNER_TEMP --smoke-publish=true --is-local="$IS_LOCAL"
node scripts/publish.js --pack-destination=$RUNNER_TEMP --smoke-publish=true
NPM_TARBALL="$RUNNER_TEMP/npm-$NPM_VERSION.tgz"
node . install --global $NPM_TARBALL

Expand Down

0 comments on commit 6d0f46e

Please sign in to comment.