PromucFlow_constructor/app/client/cypress/apply-patches.js
Saroj 4ad92d648a
ci: CI optimisation to reduce ci-test run time and modularise docker image building (#21219)
## Description
- Modularised the docker image building
- Optimised the `install dependancies` step to reduce the time from 8
mins to 30-40 secs now
- Removed unnecessary steps from the ci-dubugging.yml 
- Added ci-debug.sh file to ease the steps to run ngrok while running
ci-debugging
- Changes made to below files
1.  integration-tests-command.yml
2. test-build-docker-image.yml
3. ci-test.yml
4. build-docker-image.yml

## Type of change
- integration-tests-command.yml
- test-build-docker-image.yml
- ci-test.yml
- build-docker-image.yml

## How Has This Been Tested?
- Manual

## Checklist:
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
2023-03-10 12:51:32 +05:30

54 lines
1.7 KiB
JavaScript

const { getVersionDir } = require("cypress/lib/tasks/state");
const chalk = require("chalk");
const Diff = require("diff");
const fs = require("fs/promises");
const path = require("path");
async function applyPatches() {
const patchesDir = path.join("patches");
const patchesAbsDir = path.join(process.cwd(), patchesDir);
const patches = await fs.readdir(patchesAbsDir);
const installDir = getVersionDir();
console.log(`\n> Applying patches on to ${chalk.cyan(installDir)}\n`);
for (const filename of patches) {
if (!filename.endsWith(".patch")) {
continue;
}
const fullpath = path.join(patchesAbsDir, filename);
const enc = "utf8";
const patch = await fs.readFile(fullpath, enc);
const relativeFilename = path.join(patchesDir, filename);
console.log(`>> Applying patch ${chalk.cyan(relativeFilename)}`);
await Diff.applyPatches(patch, {
loadFile: (index, callback) => {
console.debug(`>>> Loading old file: ${chalk.red(index.oldFileName)}`);
fs.readFile(path.join(installDir, index.oldFileName), enc)
.then((contents) => {
callback(null, contents);
})
.catch(callback);
},
patched: (index, content, callback) => {
console.debug(
`>>> Patched new file: ${chalk.green(index.newFileName)}`,
);
fs.writeFile(path.join(installDir, index.newFileName), content, enc)
.then(callback)
.catch(callback);
},
complete: () => {
console.log(
`>> Successfully applied patch ${chalk.cyan(relativeFilename)}`,
);
},
});
}
}
applyPatches().catch((e) => {
console.error(e);
process.exit(42);
});