Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
registry-url: "https://registry.npmjs.org"

- name: Setup local Turbo cache
uses: dtinth/setup-github-actions-caching-for-turbo@cc723b4600e40a6b8815b65701d8614b91e2669e # v1
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
registry-url: "https://registry.npmjs.org"

- name: Setup local Turbo cache
uses: dtinth/setup-github-actions-caching-for-turbo@cc723b4600e40a6b8815b65701d8614b91e2669e # v1
Expand Down Expand Up @@ -127,5 +127,8 @@ jobs:
- name: Run tests
run: yarn run test --continue --affected

- name: Verify wrappers
run: yarn workspace dynamic-plugins-utils run test:wrappers
- name: Install dynamic plugin dependencies
run: cd ./dynamic-plugins && yarn install && cd ..

- name: Verify dynamic plugin wrappers
run: cd ./dynamic-plugins && yarn test && cd ..
146 changes: 42 additions & 104 deletions .rhdh/docker/Dockerfile

Large diffs are not rendered by default.

136 changes: 38 additions & 98 deletions docker/Dockerfile

Large diffs are not rendered by default.

Empty file removed dynamic-plugins/.gitkeep
Empty file.

Large diffs are not rendered by default.

144 changes: 104 additions & 40 deletions dynamic-plugins/_utils/copy-plugins.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,115 @@
const fs = require('fs');
const path = require('path');
const process = require('process');
const fs = require("fs").promises; // Use the promises API
const path = require("path");
const process = require("process");

process.chdir(path.join(__dirname, '..'));

if (!process.argv[2]) {
console.log('Usage: node copy-plugins.js <destination directory>');
process.exit(1);
// Helper function to check if a directory exists
async function directoryExists(dirPath) {
try {
const stats = await fs.stat(dirPath);
return stats.isDirectory();
} catch (error) {
if (error.code === "ENOENT") {
return false;
}
throw error; // Re-throw unexpected errors
}
}

const destination = process.argv[2];
fs.mkdirSync(destination, { recursive: true });
async function main() {
process.chdir(path.join(__dirname, ".."));

const wrappersDir = path.join('.', 'wrappers');
if (!process.argv[2]) {
console.log("Usage: node copy-plugins.js <destination directory>");
process.exit(1);
}

const wrappers = fs
.readdirSync(wrappersDir, {
withFileTypes: true,
})
.filter(dirent => dirent.isDirectory())
.map(dirent => path.join(wrappersDir, dirent.name));
const destination = process.argv[2];
// Ensure destination exists using async mkdir
await fs.mkdir(destination, { recursive: true });
console.log(`Ensured destination directory exists: ${destination}`);

for (const directory of wrappers) {
const distDynamicDir = path.join(directory, 'dist-dynamic');
const wrappersDir = path.join(".", "wrappers");

const packageToCopy = fs.existsSync(distDynamicDir)
? distDynamicDir
: directory;
// Read directories asynchronously
const dirents = await fs.readdir(wrappersDir, { withFileTypes: true });

const pkgJsonPath = path.join(packageToCopy, 'package.json');
if (!fs.existsSync(pkgJsonPath)) {
console.error(`No 'package.json' in '${directory}': skipping`);
continue;
}
const pkgJson = require(fs.realpathSync(pkgJsonPath));
if (!pkgJson?.name) {
console.error(
`Package '${directory}' is missing 'package.json' or 'name' attribute.`,
);
continue;
}
const copyName = pkgJson.name.replace(/^@/, '').replace(/\//, '-');
const wrapperDirs = dirents
.filter((dirent) => dirent.isDirectory())
.map((dirent) => path.join(wrappersDir, dirent.name));

// Create an array of promises, one for each directory processing task
const copyPromises = wrapperDirs.map(async (directory) => {
try {
const distDynamicDir = path.join(directory, "dist-dynamic");
let packageToCopy = directory; // Default source

// Check asynchronously if dist-dynamic exists and is a directory
if (await directoryExists(distDynamicDir)) {
packageToCopy = distDynamicDir;
}

const pkgJsonPath = path.join(packageToCopy, "package.json");
let pkgJson;
try {
// Read and parse package.json asynchronously
const pkgJsonContent = await fs.readFile(pkgJsonPath, "utf-8");
pkgJson = JSON.parse(pkgJsonContent);
} catch (error) {
if (error.code === "ENOENT") {
console.error(
`Skipping '${directory}': No 'package.json' found in '${packageToCopy}'`,
);
return; // Skip this directory successfully (promise resolves)
}
// Re-throw other read/parse errors
throw new Error(
`Error reading package.json from ${pkgJsonPath}: ${error.message}`,
);
}

console.log(`Copying ${packageToCopy} to ${destination}`);
const destinationDir = path.join(destination, copyName);
fs.rmSync(destinationDir, { recursive: true, force: true });
fs.cpSync(fs.realpathSync(packageToCopy), destinationDir, {
recursive: true,
if (!pkgJson?.name) {
console.error(
`Skipping '${directory}': Invalid 'package.json' in '${packageToCopy}' (missing 'name' attribute).`,
);
return; // Skip this directory successfully (promise resolves)
}

const copyName = pkgJson.name.replace(/^@/, "").replace(/\//, "-");
const destinationDir = path.join(destination, copyName);
// Get the real path of the source directory asynchronously
const sourceRealPath = await fs.realpath(packageToCopy);

console.log(
`Processing ${pkgJson.name}: Copying ${sourceRealPath} to ${destinationDir}`,
);

// Remove destination directory asynchronously
await fs.rm(destinationDir, { recursive: true, force: true });

// Copy directory asynchronously
await fs.cp(sourceRealPath, destinationDir, { recursive: true });

console.log(`Finished copying ${pkgJson.name} to ${destinationDir}`);
} catch (error) {
// Log the error and re-throw to make Promise.all fail
console.error(`Error processing directory '${directory}':`, error);
throw error;
}
});

// Wait for all copy operations to complete
try {
await Promise.all(copyPromises);
console.log("\nAll plugins copied successfully.");
} catch (error) {
// Error is already logged in the individual promise catch block
console.error("\nOne or more plugins failed to copy. See errors above.");
process.exit(1); // Exit with error status
}
}

// Run the main async function and catch any top-level errors
main().catch((err) => {
console.error("Script execution failed:", err);
process.exit(1);
});
2 changes: 1 addition & 1 deletion dynamic-plugins/_utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"copy-dynamic-plugins": "node ./copy-plugins.js",
"lint": "backstage-cli package lint",
"test:wrappers": "backstage-cli package test --passWithNoTests --coverage"
"test": "backstage-cli package test --passWithNoTests --coverage"
},
"devDependencies": {
"@backstage/cli": "0.30.0",
Expand Down
44 changes: 44 additions & 0 deletions dynamic-plugins/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "dynamic-plugins-root",
"version": "1.7.0",
"private": true,
"engines": {
"node": "22"
},
"scripts": {
"build": "turbo run build",
"tsc": "turbo run tsc",
"export-dynamic": "turbo run export-dynamic",
"export-dynamic:clean": "turbo run export-dynamic:clean",
"copy-dynamic-plugins": "turbo copy-dynamic-plugins --",
"clean": "turbo run clean",
"test": "turbo run test",
"lint:check": "turbo run lint:check",
"lint:fix": "turbo run lint:fix"
},
"workspaces": {
"packages": [
"_utils",
"wrappers/*"
]
},
"devDependencies": {
"turbo": "2.5.0"
},
"resolutions": {
"@types/react": "18.3.20",
"@types/react-dom": "18.3.6",
"@rjsf/utils": "=5.24.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resolution can be removed if we switch to using @backstage-community/plugin-rbac 1.40.1

"@aws-sdk/util-utf8-browser": "npm:@smithy/util-utf8@~2",
"@kubernetes/client-node@npm:0.20.0/jsonpath-plus": "^10.3.0",
"@backstage/plugin-auth-node@^0.6.0": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
"@backstage/plugin-auth-node@0.6.0": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
"@backstage/plugin-auth-node@^0.5.6": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
"@backstage/plugin-auth-node@^0.5.1": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
"@backstage/plugin-auth-node@^0.4.17": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
"@backstage/plugin-auth-node@^0.4.13": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
"@backstage/plugin-auth-node@^0.5.2": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch",
"@backstage/plugin-auth-node@^0.4.16": "patch:@backstage/plugin-auth-node@npm%3A0.6.0#./.yarn/patches/@backstage-plugin-auth-node-npm-0.6.0-69f2f0dc3f.patch"
},
"packageManager": "yarn@3.8.7"
}
34 changes: 34 additions & 0 deletions dynamic-plugins/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"export-dynamic": {
"dependsOn": ["tsc"]
},
"export-dynamic:clean": {
"cache": false,
"dependsOn": ["tsc"]
},
"start": {
"cache": false,
"persistent": true
},
"build": {
"outputs": ["dist/**"],
"dependsOn": ["tsc", "^build"]
},
"clean": {
"cache": false
},
"test": {
"outputs": ["coverage/**"]
},
"lint:check": {},
"lint:fix": {
"cache": false
},
"tsc": {
"dependsOn": ["^tsc"]
},
"copy-dynamic-plugins": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": ["src", "dev", "migrations"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-3scale-backend-dynamic",
"outDir": "../../dist-types/wrappers/backstage-community-plugin-3scale-backend-dynamic",
"rootDir": "."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": {
"tsc": {
"outputs": [
"../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-3scale-backend-dynamic/**"
"../../dist-types/wrappers/backstage-community-plugin-3scale-backend-dynamic/**"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": ["src", "dev", "migrations"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-acr",
"outDir": "../../dist-types/wrappers/backstage-community-plugin-acr",
"rootDir": "."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"extends": ["//"],
"tasks": {
"tsc": {
"outputs": [
"../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-acr/**"
]
"outputs": ["../../dist-types/wrappers/backstage-community-plugin-acr/**"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": ["src", "dev", "migrations"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-analytics-provider-segment",
"outDir": "../../dist-types/wrappers/backstage-community-plugin-analytics-provider-segment",
"rootDir": "."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": {
"tsc": {
"outputs": [
"../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-analytics-provider-segment/**"
"../../dist-types/wrappers/backstage-community-plugin-analytics-provider-segment/**"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": ["src", "dev", "migrations"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-azure-devops-backend-dynamic",
"outDir": "../../dist-types/wrappers/backstage-community-plugin-azure-devops-backend-dynamic",
"rootDir": "."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": {
"tsc": {
"outputs": [
"../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-azure-devops-backend-dynamic/**"
"../../dist-types/wrappers/backstage-community-plugin-azure-devops-backend-dynamic/**"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": ["src", "dev", "migrations"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-azure-devops",
"outDir": "../../dist-types/wrappers/backstage-community-plugin-azure-devops",
"rootDir": "."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": {
"tsc": {
"outputs": [
"../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-azure-devops/**"
"../../dist-types/wrappers/backstage-community-plugin-azure-devops/**"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": ["src", "dev", "migrations"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-catalog-backend-module-keycloak-dynamic",
"outDir": "../../dist-types/wrappers/backstage-community-plugin-catalog-backend-module-keycloak-dynamic",
"rootDir": "."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": {
"tsc": {
"outputs": [
"../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-catalog-backend-module-keycloak-dynamic/**"
"../../dist-types/wrappers/backstage-community-plugin-catalog-backend-module-keycloak-dynamic/**"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": ["src", "dev", "migrations"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "../../../dist-types/dynamic-plugins/wrappers/backstage-community-plugin-catalog-backend-module-pingidentity-dynamic",
"outDir": "../../dist-types/wrappers/backstage-community-plugin-catalog-backend-module-pingidentity-dynamic",
"rootDir": "."
}
}
Loading
Loading