Skip to content

Commit

Permalink
chore(build): separate version from build (#3447)
Browse files Browse the repository at this point in the history
and cleared that thing and rotated it too
  • Loading branch information
sedghi authored Jun 6, 2023
1 parent ef9363e commit 4938014
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 30 deletions.
14 changes: 11 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,25 @@ 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:
name: build the other half of the packages
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
Expand Down
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

40 changes: 40 additions & 0 deletions publish-package.mjs
Original file line number Diff line number Diff line change
@@ -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);
});
33 changes: 8 additions & 25 deletions publish.mjs → publish-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -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 => {
Expand Down
3 changes: 2 additions & 1 deletion version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
});

0 comments on commit 4938014

Please sign in to comment.