Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update publish script to skip lerna #40815

Merged
merged 4 commits into from Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_test_deploy.yml
Expand Up @@ -1008,7 +1008,7 @@ jobs:
- run: npm i -g pnpm@${PNPM_VERSION}
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: ./scripts/publish-native.js $GITHUB_REF
- run: ./scripts/publish-release.sh
- run: ./scripts/publish-release.js

testDeployE2E:
name: E2E (deploy)
Expand Down
76 changes: 76 additions & 0 deletions scripts/publish-release.js
@@ -0,0 +1,76 @@
#!/usr/bin/env node

const path = require('path')
const { readdir } = require('fs/promises')
const { execSync } = require('child_process')

const cwd = process.cwd()

;(async function () {
let isCanary = false

if (!process.env.NPM_TOKEN) {
console.log('No NPM_TOKEN, exiting..')
return
}

try {
const tagOutput = execSync('git describe --exact-match').toString()
console.log(tagOutput)
isCanary = tagOutput.includes('-canary')
} catch (err) {
console.log(err)

if (err.message && err.message.includes('no tag exactly matches')) {
console.log('Nothing to publish, exiting..')
return
}
throw err
}
console.log(`Publishing ${isCanary ? 'canary' : 'stable'}`)

// TODO: remove after testing, this is a safe guard to ensure we
// don't publish stable unexpectedly
if (!isCanary) {
return
}

const packagesDir = path.join(cwd, 'packages')
const packageDirs = readdir(packagesDir)
styfle marked this conversation as resolved.
Show resolved Hide resolved

const publish = async (pkg, retry = 0) => {
try {
execSync(
`npm publish ${path.join(packagesDir, pkg)} --access public${
isCanary ? ' --tag canary' : ''
}`
)
} catch (err) {
console.error(`Failed to publish ${pkg}`, err)

if (
err.message &&
err.message.includes(
'You cannot publish over the previously published versions'
)
) {
console.error('Ignoring already published error', pkg)
return
}

if (retry < 3) {
const retryDelaySeconds = 15
console.log(`retrying in ${retryDelaySeconds}s`)
await new Promise((resolve) =>
setTimeout(resolve, retryDelaySeconds * 1000)
)
await publish(pkg, retry + 1)
}
throw err
}
}

for (const packageDir of packageDirs) {
await publish(packageDir)
}
})()
38 changes: 0 additions & 38 deletions scripts/publish-release.sh

This file was deleted.