## Description PR to update the Postgres posrt for TED container in CI. /test all ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9646981763> > Commit: d998c6fe77ac2acdb71888fe6b3d7603ddda508c > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9646981763&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `` <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Updated Docker port mapping from `5432` to `5433` across multiple CI workflow files to ensure consistency and avoid port conflicts. - **Bug Fixes** - Adjusted PostgreSQL connection port from `5432` to `5433` in test fixtures and scripts to align with environment changes and prevent connection issues. - **Tests** - Modified test scripts to handle new PostgreSQL port settings for improved reliability in testing scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
190 lines
5.8 KiB
JavaScript
190 lines
5.8 KiB
JavaScript
const { execSync } = require("child_process");
|
|
const { existsSync, readFileSync, writeFileSync } = require("fs");
|
|
const path = require("path");
|
|
const prompt = require("prompt-sync")();
|
|
|
|
// Function to check if a Docker container is running
|
|
function isContainerRunning(containerName) {
|
|
try {
|
|
const output = execSync(
|
|
`docker ps --format '{{.Names}}' | grep -w "${containerName}"`,
|
|
);
|
|
return output.length > 0;
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function ensureTEDIsRunning() {
|
|
// Check if TED is running. If not, then ask user if they wish to pull and run the TED container
|
|
const isTedRunning = isContainerRunning("ted");
|
|
|
|
if (isTedRunning) {
|
|
console.log("INFO", "TED (TestEventDriver) is already running");
|
|
} else {
|
|
try {
|
|
let user_input = prompt(
|
|
"TED (TestEventDriver) is not running. Do you want to pull & run the latest Docker container for TED (TestEventDriver)? (yes/no): ",
|
|
);
|
|
user_input = user_input.trim().toLowerCase();
|
|
switch (user_input) {
|
|
case "yes":
|
|
case "y":
|
|
console.log(
|
|
"INFO",
|
|
"Running the Docker container for TED (TestEventDriver)",
|
|
);
|
|
try {
|
|
execSync(
|
|
"docker run --name ted --rm -d --pull always -p 2022:22 -p 5001:5001 -p 3306:3306 -p 28017:27017 -p 5433:5432 -p 25:25 -p 4200:4200 appsmith/test-event-driver",
|
|
{ stdio: "inherit" },
|
|
);
|
|
console.log(
|
|
"INFO",
|
|
"Please check https://github.com/appsmithorg/TestEventDriver for more details and functionalities of TED",
|
|
);
|
|
} catch (error) {
|
|
console.error("ERROR", `Error installing TED: ${error.message}`);
|
|
}
|
|
break;
|
|
case "no":
|
|
case "n":
|
|
console.log("INFO", "Proceeding without TED");
|
|
break;
|
|
default:
|
|
console.log("ERROR", "Invalid input. Please enter yes or no.");
|
|
process.exit(1);
|
|
}
|
|
} catch (error) {
|
|
console.error("ERROR", `Error: ${error.message}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function checkIfAppsmithIsRunning(baseUrl) {
|
|
// Check if appsmith is running. If it's not running, check if we want the user to continue without it.
|
|
let isDevAppsmithAccessible;
|
|
try {
|
|
const response = await fetch(baseUrl);
|
|
isDevAppsmithAccessible = response.ok;
|
|
} catch (error) {
|
|
console.error(
|
|
"ERROR",
|
|
`Error checking availability of dev.appsmith.com: ${error.message}`,
|
|
);
|
|
isDevAppsmithAccessible = false;
|
|
}
|
|
|
|
if (!isDevAppsmithAccessible) {
|
|
let user_input = prompt(
|
|
`https://dev.appsmith.com is not accessible. Do you wish to continue without setting it up? (yes/no): `,
|
|
);
|
|
user_input = user_input.trim().toLowerCase();
|
|
switch (user_input) {
|
|
case "yes":
|
|
case "y":
|
|
console.log("INFO", "Continuing without setting up dev.appsmith.com");
|
|
break;
|
|
case "no":
|
|
case "n":
|
|
process.exit(1);
|
|
default:
|
|
console.log("ERROR", "Invalid input. Please enter yes or no.");
|
|
process.exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
function getBaseUrl(repoRoot) {
|
|
try {
|
|
const cypressConfig = readFileSync(`${repoRoot}/cypress.config.ts`, "utf8");
|
|
const baseUrlMatch = cypressConfig.match(/baseUrl\s*:\s*"([^"]+)"/);
|
|
if (baseUrlMatch) {
|
|
baseUrl = baseUrlMatch[1];
|
|
console.log(
|
|
"INFO",
|
|
`Base url is ${baseUrl}. Please verify if it is correct. If not, please update it in cypress.config.ts file.`,
|
|
);
|
|
return baseUrl;
|
|
} else {
|
|
console.error(
|
|
"ERROR",
|
|
"Base url not found in cypress.config.ts. Please configure `baseUrl` property in cypress.config.ts file.",
|
|
);
|
|
process.exit(1);
|
|
}
|
|
} catch (err) {
|
|
if (err.code === "ENOENT") {
|
|
console.error("ERROR", "cypress.config.ts file not found");
|
|
} else {
|
|
console.error("ERROR", "Error reading cypress.config.ts file:", err);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
function ensureCypressEnvFileExists(repoRoot) {
|
|
// Check if cypress.env.json file exists. If not, create it.
|
|
const filePath = `${repoRoot}/cypress.env.json`;
|
|
if (!existsSync(filePath)) {
|
|
const testEnvData = {
|
|
USERNAME: "testUser@test.com",
|
|
PASSWORD: "testPass",
|
|
TESTUSERNAME1: "viewerappsmith@test.com",
|
|
TESTPASSWORD1: "viewerPass",
|
|
TESTUSERNAME2: "developerappsmith@test.com",
|
|
TESTPASSWORD2: "developerPass",
|
|
};
|
|
writeFileSync(filePath, JSON.stringify(testEnvData, null, 2));
|
|
console.log("INFO", `${repoRoot}/cypress.env.json file created`);
|
|
} else {
|
|
console.log("INFO", `${repoRoot}/cypress.env.json file already exists`);
|
|
}
|
|
}
|
|
|
|
async function setupCypress() {
|
|
// Get the baseUrl from cypress.config.ts file
|
|
let repoRoot = path.join(__dirname, "..", "..");
|
|
let baseUrl = getBaseUrl(repoRoot);
|
|
|
|
await checkIfAppsmithIsRunning(baseUrl);
|
|
|
|
// Install Cypress using yarn install on the app/client repository
|
|
console.log("INFO", "Installing Cypress..");
|
|
try {
|
|
execSync("yarn install", { cwd: `${repoRoot}` });
|
|
} catch (error) {
|
|
console.error("ERROR", `Error installing Cypress: ${error.message}`);
|
|
}
|
|
|
|
ensureCypressEnvFileExists(repoRoot);
|
|
|
|
console.log(
|
|
"INFO",
|
|
"Please add APPSMITH_GIT_ROOT=./container-volumes/git-storage into server-side .env for running Git cases locally along with the server.",
|
|
);
|
|
|
|
ensureTEDIsRunning();
|
|
|
|
console.log(
|
|
"INFO",
|
|
"Please start cypress using the command: npx cypress open",
|
|
);
|
|
console.log(
|
|
"INFO",
|
|
`In order to run single spec, please use the command: cd ${repoRoot} && npx cypress run --spec <specpath> --browser chrome`,
|
|
);
|
|
console.log(
|
|
"INFO",
|
|
"For more details check https://github.com/appsmithorg/appsmith/blob/master/contributions/ClientSetup.md#integration-tests",
|
|
);
|
|
}
|
|
|
|
async function main() {
|
|
await setupCypress();
|
|
process.exit(0);
|
|
}
|
|
|
|
main();
|