Skip to content

Commit

Permalink
✨ feat: Add cypress-process-clean-up typescript action
Browse files Browse the repository at this point in the history
  • Loading branch information
honzabubenik committed Mar 8, 2024
1 parent 1e30908 commit c83a566
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fund=false
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
7 changes: 7 additions & 0 deletions cypress-process-clean-up/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Clean Cypress Process
description: ''

runs:
using: 'node20'
main: '../dist/main/index.js'
post: '../dist/post/index.js'
1 change: 1 addition & 0 deletions dist/main/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dist/main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
1 change: 1 addition & 0 deletions dist/post/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dist/post/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
92 changes: 89 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@
"description": "Localazy GitHub release action",
"author": "Localazy <[email protected]>",
"license": "MIT",
"type": "module",
"files": [
"dist"
],
"scripts": {
"build": "npm run build:main && npm run build:post",
"build:main": "npm run compile -- --out ./dist/main src/main.ts ",
"build:post": "npm run compile -- --out ./dist/post src/post.ts",
"compile": "ncc build --minify --no-cache --target es2022 --v8-cache"
},
"dependencies": {
"ps-list": "^8.1.1"
},
"devDependencies": {
"@localazy/conventional-changelog-preset": "github:localazy/conventional-changelog-preset",
"@types/node": "^20.6.2",
"@vercel/ncc": "^0.38.0",
"conventional-changelog": "^5.1.0",
"conventional-changelog-cli": "^4.1.0",
"conventional-changelog-writer": "github:localazy/conventional-changelog-writer",
"conventional-recommended-bump": "^9.0.0"
"conventional-recommended-bump": "^9.0.0",
"typescript": "^5.2.2"
}
}
33 changes: 33 additions & 0 deletions src/clean-up.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import psList, { ProcessDescriptor } from 'ps-list';

const workspace: string = process.env.GITHUB_WORKSPACE || '';

export const terminateOrphans = async (): Promise<void> => {
const processes: ProcessDescriptor[] = await psList();

const chromeProcesses: ProcessDescriptor[] = processes.filter(
(p: ProcessDescriptor) => p.cmd?.includes('/chrome/chrome')
);
const cypressProcesses: ProcessDescriptor[] = processes.filter(
(p: ProcessDescriptor) => p.cmd?.includes('/Cypress/Cypress') && p.cmd.includes('--run-project')
);
const cypressOrphans: ProcessDescriptor[] = cypressProcesses.filter(
(p: ProcessDescriptor) => p.cmd?.includes(`--run-project ${workspace}`)
);

console.log('Chrome processes:', chromeProcesses.length);
console.log('Cypress processes:', cypressProcesses.length);
console.log('Cypress orphans:', cypressOrphans.length);

cypressOrphans.forEach((cypressProcess: ProcessDescriptor): void => {
chromeProcesses
.filter((chromeProcess: ProcessDescriptor) => chromeProcess.cmd?.includes(`run-${cypressProcess.pid}`))
.forEach((chromeProcess: ProcessDescriptor): void => {
console.log(`Killing Chrome process ${chromeProcess.pid} ${chromeProcess.cmd}\n`);
process.kill(chromeProcess.pid, 'SIGKILL');
});

console.log(`Killing Cypress process ${cypressProcess.pid} ${cypressProcess.cmd}\n`);
process.kill(cypressProcess.pid, 'SIGKILL');
});
}
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { terminateOrphans } from './clean-up.js';

terminateOrphans().then();
3 changes: 3 additions & 0 deletions src/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { terminateOrphans } from './clean-up.js';

terminateOrphans().then();
14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"strict": true,
"types": [
"node"
]
},
"include": ["src"]
}

0 comments on commit c83a566

Please sign in to comment.