From 4938014a21f182be91bd7798313f0548c04e438d Mon Sep 17 00:00:00 2001 From: Alireza Date: Tue, 6 Jun 2023 16:49:18 -0400 Subject: [PATCH] chore(build): separate version from build (#3447) and cleared that thing and rotated it too --- .circleci/config.yml | 14 ++++++++--- .npmrc | 1 - publish-package.mjs | 40 ++++++++++++++++++++++++++++++ publish.mjs => publish-version.mjs | 33 ++++++------------------ version.mjs | 3 ++- 5 files changed, 61 insertions(+), 30 deletions(-) delete mode 100644 .npmrc create mode 100644 publish-package.mjs rename publish.mjs => publish-version.mjs (85%) diff --git a/.circleci/config.yml b/.circleci/config.yml index bbc40e6935d..873d20fbfdb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -284,7 +284,7 @@ jobs: command: | node ./increaseEventEmitterLimit.mjs - run: - name: build half of the packages + name: build half of the packages (to avoid out of memory in circleci) command: | yarn run build:package-all - run: @@ -292,9 +292,17 @@ jobs: command: | yarn run build:package-all-1 - run: - name: version and publish all packages + name: publish package versions command: | - node ./publish.mjs + node ./publish-version.mjs + - run: + name: Again set the NPM registry (was deleted in the version script) + command: + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc + - run: + name: publish package dist + command: | + node ./publish-package.mjs DOCKER_RELEASE_PUBLISH: <<: *defaults diff --git a/.npmrc b/.npmrc deleted file mode 100644 index d337c0cdbd8..00000000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -//registry.npmjs.org/:_authToken=16ec041c-ce66-48f0-a463-7429164d7801 diff --git a/publish-package.mjs b/publish-package.mjs new file mode 100644 index 00000000000..3fa73718b11 --- /dev/null +++ b/publish-package.mjs @@ -0,0 +1,40 @@ +import { execa } from 'execa'; + +async function run() { + const { stdout: branchName } = await execa('git', [ + 'rev-parse', + '--abbrev-ref', + 'HEAD', + ]); + + // using the environment variable NPM_TOKEN, create a .npmrc file + // and set the token to the value of the environment variable + // Publishing each package, if on master/main branch publish beta versions + // otherwise publish latest + if (branchName === 'release') { + await execa('npx', [ + 'lerna', + 'publish', + 'from-package', + '--no-verify-access', + '--yes', + ]); + } else { + await execa('npx', [ + 'lerna', + 'publish', + 'from-package', + '--no-verify-access', + '--yes', + '--dist-tag', + 'beta', + ]); + } + + console.log('Finished'); +} + +run().catch(err => { + console.error('Error encountered during package publish:', err); + process.exit(1); +}); diff --git a/publish.mjs b/publish-version.mjs similarity index 85% rename from publish.mjs rename to publish-version.mjs index 4259a1807a5..7f1ef617954 100644 --- a/publish.mjs +++ b/publish-version.mjs @@ -68,10 +68,16 @@ async function run() { } } + // remove the .npmrc to not accidentally publish to npm + await fs.unlink('.npmrc'); + + // rm -f ./.npmrc again + await execa('rm', ['-f', '.npmrc']); + // Todo: Do we really need to run the build command here? // Maybe we need to hook the netlify deploy preview // await execa('yarn', ['run', 'build']); - // console.log('Build command completed'); + console.log('Committing and pushing changes...'); await execa('git', ['add', '-A']); await execa('git', [ @@ -94,31 +100,8 @@ async function run() { '--message', 'chore(version): Update package versions [skip ci]', ]); - console.log('Version set using lerna'); - // Publishing each package, if on master/main branch publish beta versions - // otherwise publish latest - if (branchName === 'release') { - await execa('npx', [ - 'lerna', - 'publish', - 'from-package', - '--no-verify-access', - '--yes', - ]); - } else { - await execa('npx', [ - 'lerna', - 'publish', - 'from-package', - '--no-verify-access', - '--yes', - '--dist-tag', - 'beta', - ]); - } - - console.log('Finished'); + console.log('Version set using lerna'); } run().catch(err => { diff --git a/version.mjs b/version.mjs index 65a3f8aadeb..6af6b02c29f 100644 --- a/version.mjs +++ b/version.mjs @@ -65,6 +65,7 @@ async function run() { } console.log('Next version:', nextVersion); + console.log('Current commit hash:', currentCommitHash); const versionInfo = { version: nextVersion, commit: currentCommitHash }; await fs.writeFile('./version.json', JSON.stringify(versionInfo, null, 2)); @@ -75,6 +76,6 @@ async function run() { } run().catch(err => { - console.error('Error encountered during version bump:', err); + console.error('Error encountered during new version & commit write:', err); process.exit(1); });