Skip to content

Commit

Permalink
Update publish script to skip lerna
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Sep 22, 2022
1 parent 50b98d5 commit d332460
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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)

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.

0 comments on commit d332460

Please sign in to comment.