Skip to content

Commit

Permalink
chore(root): Fix preview packages (#6586)
Browse files Browse the repository at this point in the history
  • Loading branch information
SokratisVidros authored Sep 28, 2024
1 parent 0050e7f commit d02f669
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '!prod'

jobs:
release_packages_preview:
publish_preview_packages:
runs-on: ubuntu-latest

steps:
Expand All @@ -30,9 +30,8 @@ jobs:
run: pnpm run packages:set-latest

- name: Build
run: pnpm run build:affected
if: ${{ success() }}
run: pnpm run preview:pkg:build

- name: Release package previews to pkg.pr.new
run: pnpm run release:previews
run: pnpm run preview:pkg:publish
if: ${{ success() }}
Empty file removed apps/dashboard/legacy/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
"build:widget": "nx build @novu/widget",
"build:embed": "nx build @novu/embed",
"build:storybook": "nx run @novu/design-system:build-storybook",
"build:affected": "nx affected -t build --base=origin/next --head=HEAD --exclude=nextjs,@novu/shared",
"test:providers": "cross-env pnpm --filter './packages/providers/**' test",
"release:patch": "nx release version patch --no-push",
"release:minor": "nx release version minor --no-push",
"release:preminor": "nx release version preminor --no-push",
"release:prerelease": "nx release version prerelease --no-push",
"release:submodules": "ts-node scripts/release-with-submodules.ts",
"release:previews": "nx affected -t release:preview --base=origin/next --head=HEAD --exclude=nextjs,@novu/shared",
"preview:pkg:build": "nx affected -t build --base=origin/next --head=HEAD --exclude=nextjs",
"preview:pkg:publish": "node scripts/publish-preview-packages.mjs",
"start:integration:api": "cd apps/api && pnpm run test",
"start:e2e:api": "cd apps/api && pnpm run test:e2e",
"g:module": "hygen module new --name=$npm_config_name",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"start:test": "cross-env NODE_ENV=test PORT=1336 nodemon init",
"start:debug": "cross-env nodemon --config nodemon-debug.json",
"start:prod": "cross-env node dist/src/index.js",
"release:preview": "pnpx pkg-pr-new publish"
"print:project-path": "echo \"$PWD\" | sed 's|.*/novu/||'"
},
"keywords": [
"novu",
Expand Down
3 changes: 1 addition & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"doc:json": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json",
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
"reset-hard": "git clean -dfx && git reset --hard && pnpm install",
"prepare-release": "run-s reset-hard test",
"release:preview": "pnpx pkg-pr-new publish"
"prepare-release": "run-s reset-hard test"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"$comment:bump:prerelease": "This is a workaround to support `npm version prerelease` with lerna",
"bump:prerelease": "npm version prerelease --preid=alpha & PID=$!; (sleep 1 && kill -9 $PID) & wait $PID",
"release:alpha": "pnpm bump:prerelease || pnpm build && npm publish",
"devtool": "tsx ./scripts/devtool.ts",
"release:preview": "pnpx pkg-pr-new publish"
"devtool": "tsx ./scripts/devtool.ts"
},
"keywords": [
"novu",
Expand Down
3 changes: 1 addition & 2 deletions packages/headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"lint:fix": "eslint src --fix",
"test": "jest",
"test:watch": "jest --watch",
"release:preview": "pnpx pkg-pr-new publish"
"test:watch": "jest --watch"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
"check-exports": "attw --pack .",
"lint": "eslint src",
"lint:fix": "pnpm lint -- --fix",
"test": "jest",
"release:preview": "pnpx pkg-pr-new publish"
"test": "jest"
},
"browserslist": {
"production": [
Expand Down
3 changes: 1 addition & 2 deletions packages/nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "jest src --watch",
"reset-hard": "git clean -dfx && git reset --hard && pnpm install",
"prepare-release": "run-s reset-hard test",
"release:preview": "pnpx pkg-pr-new publish"
"prepare-release": "run-s reset-hard test"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"doc:json": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json",
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
"reset-hard": "git clean -dfx && git reset --hard && pnpm install",
"prepare-release": "run-s reset-hard test",
"release:preview": "pnpx pkg-pr-new publish"
"prepare-release": "run-s reset-hard test"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "vitest",
"reset-hard": "git clean -dfx && git reset --hard && yarn",
"prepare-release": "run-s reset-hard test",
"release:preview": "pnpx pkg-pr-new publish"
"prepare-release": "run-s reset-hard test"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
"build:watch": "tsup --watch",
"build": "tsup && pnpm run check-exports",
"lint": "eslint src",
"check-exports": "attw --pack .",
"release:preview": "pnpx pkg-pr-new publish"
"check-exports": "attw --pack ."
},
"browserslist": {
"production": [
Expand Down
3 changes: 1 addition & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"lint": "eslint src",
"lint:fix": "pnpm lint -- --fix",
"test": "vitest",
"watch:test": "pnpm test --watch",
"release:preview": "pnpx pkg-pr-new publish"
"watch:test": "pnpm test --watch"
},
"author": "",
"license": "ISC",
Expand Down
3 changes: 1 addition & 2 deletions packages/stateless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"doc:json": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json",
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
"reset-hard": "git clean -dfx && git reset --hard && pnpm install",
"prepare-release": "run-s reset-hard test",
"release:preview": "pnpx pkg-pr-new publish"
"prepare-release": "run-s reset-hard test"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 0 additions & 8 deletions scripts/print-affected-array.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ function pnpmRun(...args) {
});
}

function commaSeparatedListToArray(str) {
return str
.trim()
.split(',')
.map((element) => element.trim())
.filter((element) => !!element.length);
}

function getAffectedCommandResult(str) {
const outputLines = str.trim().split(/\r?\n/);
if (outputLines.length > 2) {
Expand Down
82 changes: 82 additions & 0 deletions scripts/publish-preview-packages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* This script publishes a preview package via https://pkg.pr.new/ for all affected packages between
* the base branch of the repoand the current HEAD.
*
*/

import { execa } from 'execa';
import { exec } from 'node:child_process';

// Remove quoted lines from the nx show projects command
function removeQuotedLines(input) {
// Split the input into an array of lines
let lines = input.split('\n');

// Filter out lines that start with the '>' symbol
let filteredLines = lines.filter((line) => !line.trim().startsWith('>'));

// Join the filtered lines back into a single string
return filteredLines.join('\n');
}

// Get all affected package names in the monorepo as a set
async function getPackageNames() {
const { stdout } = await execa`pnpm nx show projects --affected --base=origin/next --head=HEAD --json`;
const packageNamesArray = JSON.parse(removeQuotedLines(stdout));
return new Set(packageNamesArray);
}

// Get all packages names and paths in the monorepo
async function getPackages() {
const { stdout } = await execa`pnpm list -r --depth -1 --json`;
return JSON.parse(stdout);
}

// Function to execute a shell command and return it as a Promise instead of using execa.
// Execa does not work well with the necessary quotes of the publish command due to its internal escaping capabilities.
// See https://github.com/sindresorhus/execa/blob/main/docs/escaping.md
async function myExec(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(`Error: ${error.message}`);
return;
}
resolve(stdout); // Resolve with the command output
});
});
}

try {
const affectedPackageNames = await getPackageNames();

const novuPackages = await getPackages();

// Get the paths of the affected packages
const affectedPackagePaths = novuPackages.reduce((memo, pkg) => {
// Ignore packages that are marked as private
if (pkg.private) {
return memo;
}

// Ignore packages that are not in the "packages" folder
if (!pkg.path.includes('packages')) {
return memo;
}

// Preview only affected public packages
if (affectedPackageNames.has(pkg.name)) {
// Pnpm list returms absolute paths are absolute. Keep only the "./packages/{{package_folder}}" path
const relativePath = pkg.path.match(/\/packages.*/)[0];
memo.push(`'.${relativePath}'`);
}

return memo;
}, []);

const command = `pnpx pkg-pr-new publish ${affectedPackagePaths.join(' ')}`;
console.log(await myExec(command));
} catch (err) {
console.error(`Error: ${err.message || err}`);
process.exit(1);
}

0 comments on commit d02f669

Please sign in to comment.