Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DefinitelyTyped): add process with ui to run createMock on every type of DefinitelyTyped repository #136

Merged
merged 96 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
ddd27b0
first try
uittorio Dec 31, 2019
00206e9
remove bho
uittorio Dec 31, 2019
d793cde
add emit
uittorio Dec 31, 2019
5baa5c0
git ignore definitely typed repo clone
Pmyl Jan 1, 2020
ef528af
add package json, add ./ to tsconfig extends to make sure it works on…
Pmyl Jan 1, 2020
92c9b39
create the tsLogs.txt file if not exists
Pmyl Jan 1, 2020
85430d8
add some logs, install dependencies of types with package.json
Pmyl Jan 1, 2020
0529baf
change logs
Pmyl Jan 1, 2020
175b2a7
maximise types per process, add ability to specify to run all types
Pmyl Jan 1, 2020
c43a958
run npm install with only 20 parallel processes, add better logs
Pmyl Jan 1, 2020
16c159d
ignore destination folder for definitely typed project
Pmyl Jan 5, 2020
fb771bd
do not use tests from definitely typed repo, make sure ts-auto-mock a…
Pmyl Jan 5, 2020
c948d91
move process.js in a common folder, use it to get arguments for defin…
Pmyl Jan 5, 2020
cd91480
structure code, add npm scripts
Pmyl Jan 5, 2020
29d1314
exclude everything not needed in tsconfig.base
Pmyl Jan 5, 2020
85b2bec
remove unused code
Pmyl Jan 5, 2020
efd7cdb
remove unused scripts and package
Pmyl Jan 5, 2020
f3505ac
restore transformer functionality
Pmyl Jan 5, 2020
af50034
restore import equals functionality
Pmyl Jan 5, 2020
3ef4758
write output in json format to file
Pmyl Jan 7, 2020
a58f9fa
divide data file system reader and write to be able to use the reader…
Pmyl Jan 7, 2020
d1abf5a
remove comments and fix namings
Pmyl Jan 7, 2020
62070c7
make sure data file system services are reusable, create github workf…
Pmyl Jan 7, 2020
5346be4
test run definitely typed workflow by removing branch "master" filter
Pmyl Jan 7, 2020
f84083f
put back branch filter for definitelyTyped workflow
Pmyl Jan 7, 2020
643e33a
filter only on definitely typed branch on workflow
Pmyl Jan 7, 2020
fe9cd45
test push
Pmyl Jan 7, 2020
0640393
fix script
Pmyl Jan 7, 2020
8a5408e
add more logs
Pmyl Jan 7, 2020
12a35ea
fix folder path
Pmyl Jan 7, 2020
b358157
another fix to paths
Pmyl Jan 7, 2020
dc8e8f2
exit process with error when an error occur
Pmyl Jan 7, 2020
e17d4dd
fix paths again
Pmyl Jan 7, 2020
1fe1808
fix paths again v2
Pmyl Jan 7, 2020
82abd01
fix paths again v3
Pmyl Jan 7, 2020
51c9806
adjust data file system, first version of ui
Pmyl Jan 7, 2020
9406dff
put back test run on push
Pmyl Jan 7, 2020
b43e9b8
more work on ui
Pmyl Jan 8, 2020
06f159c
complete work on ui
Pmyl Jan 8, 2020
97326f5
make sure data reader can be used in both ts and js land
Pmyl Jan 8, 2020
2ff25bc
push to trigger action
Pmyl Jan 8, 2020
50ddcb3
run definitely typed tests every 2 days
Pmyl Jan 8, 2020
5c93905
other commit to trigger action
Pmyl Jan 8, 2020
478e6b4
cmon trigger action
Pmyl Jan 8, 2020
a026d91
use the correct github token to open PR
Pmyl Jan 9, 2020
ed78483
put back on push hook for testing
Pmyl Jan 9, 2020
efd1aa3
fixed types run and yml
Pmyl Jan 9, 2020
c640aef
please
Pmyl Jan 10, 2020
854047d
please work this time
Pmyl Jan 10, 2020
296577e
move folder
Pmyl Jan 10, 2020
415be7d
change folder in yml
Pmyl Jan 10, 2020
82a8de8
make sure submodule gets removed
Pmyl Jan 10, 2020
f185fd3
please run
Pmyl Jan 10, 2020
8e246d6
fixed build check
Pmyl Jan 10, 2020
dbcb711
show error when definitely typed cannot be removed
Pmyl Jan 10, 2020
cb1a9b5
use path join
Pmyl Jan 10, 2020
e5a6b6f
random changes hoping everything works
Pmyl Jan 10, 2020
f4a313d
what the hell
Pmyl Jan 10, 2020
94c7743
pleeeeeease
Pmyl Jan 10, 2020
46b2fb2
i'm stupid
Pmyl Jan 10, 2020
caa074b
hope last commit, make data file system generic, use pre for errors
Pmyl Jan 10, 2020
0abe6f0
restore npm dependencies for definitely typed
Pmyl Jan 10, 2020
6c325c8
lol
Pmyl Jan 10, 2020
adf039a
enhance ui for errors and colors, restore cron schedule for definitel…
Pmyl Jan 10, 2020
d91daf6
emit js to run transformer
Pmyl Jan 10, 2020
7a7dd82
run my son, run
Pmyl Jan 10, 2020
d4fda86
restore cron
Pmyl Jan 10, 2020
984b4ff
don't try to delete js file if does not exists
Pmyl Jan 10, 2020
4ed6866
test
Pmyl Jan 11, 2020
e873ebb
test
Pmyl Jan 11, 2020
7371c3f
save token in env variable ciao ciao
Pmyl Jan 11, 2020
e5ff820
fix yaml env in correct step
Pmyl Jan 11, 2020
9082d8a
change index to run workflow
Pmyl Jan 11, 2020
3b7d73d
bye token
uittorio Jan 11, 2020
864bcc1
update package to only run 100 types
uittorio Jan 11, 2020
d1e4029
trigger workflow
uittorio Jan 11, 2020
6d28554
add all types
uittorio Jan 11, 2020
7a7fa3d
500 types, hopefully 1 hour
uittorio Jan 11, 2020
15b7b0b
600 types, hopefully 1 hour
uittorio Jan 11, 2020
c1b9c40
2000 thanks
uittorio Jan 11, 2020
12bea99
200 again
uittorio Jan 11, 2020
4f2fecc
run definitely typed in chunks
uittorio Jan 11, 2020
7a791ed
allora
uittorio Jan 11, 2020
b525ed9
Add DefinitelyTyped Tests data (#159)
uittorio Jan 11, 2020
49da358
oppure
uittorio Jan 11, 2020
5b22dfd
move types
uittorio Jan 11, 2020
25707f3
push
uittorio Jan 11, 2020
e5688e8
push
uittorio Jan 11, 2020
d128a88
1 giorno
uittorio Jan 11, 2020
bad0b08
runna
uittorio Jan 11, 2020
ef1b605
Add DefinitelyTyped Tests data (#160)
uittorio Jan 11, 2020
17681d3
push
uittorio Jan 11, 2020
f49fd19
push
uittorio Jan 11, 2020
0d165df
Add DefinitelyTyped Tests data (#161)
uittorio Jan 11, 2020
521ffe2
final
uittorio Jan 11, 2020
fc02a85
Merge branch 'master' into feature/definitelytype
uittorio Jan 11, 2020
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
23 changes: 8 additions & 15 deletions .github/workflows/definitelyTyped.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
name: DefinitelyTyped Tests

on:
push:
branches:
- 'feature/definitelytype'
paths:
- 'src/**'
- 'definitelyTyped/**'
schedule:
- cron: '* * */1 * *'

jobs:
performance:
definitely-typed:
runs-on: ubuntu-latest

strategy:
Expand All @@ -26,14 +22,11 @@ jobs:
run: |
npm install
npm run build
env:
CI: true
- name: definitelyTyped
run: |
cd definitelyTyped
cd definitelyTypedTests
npm install
npm run install-types
npm run process-types TYPES=2
npm run start-chunk
- name: create environment variable date
run: echo "::set-env name=DATE::$(date +%Y-%m-%dT%H-%M-%S)"
- name: definitelyTyped push changes
Expand All @@ -44,13 +37,13 @@ jobs:
run: |
git add data/*
git checkout .
git config submodule.DefinitelyTyped.active false
- name: Create Pull Request
uses: peter-evans/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN_TYPESCRIPTTDD }}
with:
commit-message: Add DefinitelyTyped Tests data
committer: typescripttdd <[email protected]>
author: typescripttdd <[email protected]>
title: DefinitelyTyped Tests Data on ${{ env.DATE }}
branch: definitely-typed-tests-${{ env.DATE }}
token: ${{ secrets.GITHUB_TOKEN }}
branch: definitely-typed-tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
.idea
/definitelyTyped/DefinitelyTyped/
2 changes: 1 addition & 1 deletion config/karma/karma.config.base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const webpackConfig = require('../test/webpack.js');
const ProcessService = require('../process/process');
const ProcessService = require('../../utils/process/process');
process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function(config, url) {
Expand Down
18 changes: 0 additions & 18 deletions config/process/process.js

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/definitelyTyped/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":"756c5f8d-be26-43fc-8831-0a12df4c972e.json","initialDate":"2020-01-11T17:17:58.333Z","lastUpdatedDate":"2020-01-11T19:29:38.377Z","typesProcessed":512}]
1 change: 1 addition & 0 deletions definitelyTypedTests/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEFINITELY_TYPED_DATA_URL=../data/definitelyTyped
141 changes: 141 additions & 0 deletions definitelyTypedTests/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
process.on('unhandledRejection', error => {
console.log('unhandledRejection', error);
process.exit(1);
});

require('dotenv').config();
const fs = require('fs');
const processService = require('../utils/process/process')(process);
const execPromise = require('../utils/exec/execPromise');
const definitelyTyped = require('./src/definitelyTyped')();
const config = require('./src/config');
const output = require('./src/multiProcessOutput');
const dataFileSystem = require('../utils/dataFileSystem/dataFileSystemWriter')(process.env.DEFINITELY_TYPED_DATA_URL);

try {
processService.ensureArgumentsValidity(['TYPES', 'PROCESS_COUNT']);
} catch(e) {
console.error(e.message);
return;
}

const outputService = output.createNew();

(async function runApp() {
const typesDirectories = definitelyTyped.getTypes();
const runConfig = await config();

logConfig(runConfig);
let startDirectoryIndex = runConfig.offsetType;
const allRuns = [];

for(let i = 0; i < runConfig.processes.length; i++) {
allRuns.push(
runAllDir(typesDirectories.slice(startDirectoryIndex, startDirectoryIndex + runConfig.processes[i].items), i)
);
startDirectoryIndex += runConfig.processes[i].items;
}

Promise.all(allRuns).then(() => {
const generatedOutput = outputService.generateOutput();
const date = new Date().toISOString();

if (runConfig.entryToUpdate) {
dataFileSystem.updateData(runConfig.entryToUpdate.id, {
lastUpdatedDate: date,
typesProcessed: generatedOutput.length + runConfig.offsetType
}, generatedOutput);
} else {
dataFileSystem.addData({
initialDate: date,
lastUpdatedDate: date,
typesProcessed: generatedOutput.length
}, generatedOutput);
}
});
})();

function logConfig(processesConfig) {
console.log(`Total types: ${processesConfig.totalTypesCount}`);
console.log(`Processes: ${processesConfig.processes.length}`);
console.log(`Average types per process: ${processesConfig.averageTypesCountPerProcess}`);
console.log();
}

function runAllDir(dirs, processId) {
fs.writeFileSync(`${processId}.index.ts`, '');
fs.writeFileSync(`tsconfig.types.${processId}.json`, '');

return dirs.reduce((promise, dir) => promise.then(() => run(dir, processId)), Promise.resolve())
.then(() => {
fs.unlinkSync(`tsconfig.types.${processId}.json`);
fs.unlinkSync(`${processId}.index.ts`);
if (fs.existsSync(`${processId}.index.js`)) {
fs.unlinkSync(`${processId}.index.js`);
}
});
}

async function run(dir, processId) {
const config = {
'compilerOptions': {
'lib': [
'es6',
'dom'
],
'noEmit': false,
'plugins': [
{
'transform': '../dist/transformer',
'debug': true
}
],
'typeRoots': [
'./DefinitelyTyped/types/'
],
"types": [],
"baseUrl": "./DefinitelyTyped/types/"
},
'files': [
`./${processId}.index.ts`
]
};

fs.writeFileSync(`tsconfig.types.${processId}.json`, JSON.stringify(config));
fs.writeFileSync(`${processId}.index.ts`, `import pak = require('./${definitelyTyped.folder}/types/${dir}/'); import { createMock } from '../dist'; createMock<typeof pak>();`);

return execPromise(`npx ttsc --project tsconfig.types.${processId}.json`)
.then((response) => {
if (response) {
process.stdout.write(`TYPE: ${dir} P${processId} `);
console.warn('☐');
outputService.addData(processId, dir, {
response: 'warning',
message: response.toString()
});
} else {
process.stdout.write(`TYPE: ${dir} P${processId} `);
console.info('✔');
outputService.addData(processId, dir, {
response: 'success'
});
}
})
.catch((error) => {
process.stdout.write(`TYPE: ${dir} P${processId} `);
console.error('✘');

let errorData = error.error.toString();
console.error(error.error);

if (error.stdout.trim()) {
errorData += "\n" + error.stdout;
console.error(error.stdout);
}

outputService.addData(processId, dir, {
response: 'error',
message: errorData
});
});
}
39 changes: 39 additions & 0 deletions definitelyTypedTests/package-lock.json

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

22 changes: 22 additions & 0 deletions definitelyTypedTests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "definitelytyped-tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "npm run install-types && npm run process-all-types && npm run post-process-types",
"start-chunk": "npm run install-types && npm run process-chunk && npm run post-process-types",
"process-chunk": "npm run process-types TYPES=500 PROCESS_COUNT=20",
"install-types": "node src/installTypes.js",
"process-all-types": "node index.js TYPES=all PROCESS_COUNT=20",
"process-types": "node index.js",
"post-process-types": "node src/postProcessTypes.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"ttypescript": "^1.5.8",
"typescript": "^3.7.4"
}
}
56 changes: 56 additions & 0 deletions definitelyTypedTests/src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const processService = require('../../utils/process/process')(process);
const maximiseParallelRun = require('./maximiseParallel');
const definitelyTyped = require('./definitelyTyped')();
const nodeReader = require('../../utils/dataFileSystem/nodeFileReader')();
const dataFileSystemReader = require("../../utils/dataFileSystem/dataFileSystemReader");
const dataReader = dataFileSystemReader(process.env.DEFINITELY_TYPED_DATA_URL, nodeReader);

function getLatestEntry(latestListEntry) {
return latestListEntry.sort((a, b) => {
return a.lastUpdatedDate > b.lastUpdatedDate ? -1 : 1;
})[0];
}

async function getRunConfig() {
const listEntry = await dataReader.getDataIds();
const latestEntry = getLatestEntry(listEntry);
const totalTypes = definitelyTyped.getTypes().length;
const entryToUpdate = latestEntry && latestEntry.typesProcessed >= totalTypes ? null : latestEntry;
const offsetType = entryToUpdate ? entryToUpdate.typesProcessed : 0;

const totalTypesCount = getTotalTypesCount(offsetType, totalTypes);
const processesMaximized = maximiseParallelRun(getProcessesCount(), totalTypesCount);
const sum = processesMaximized.reduce((previous, current) => previous + current.items, 0);
const avg = sum / processesMaximized.length;

return {
totalTypesCount: totalTypesCount,
processes: processesMaximized,
averageTypesCountPerProcess: avg,
entryToUpdate: entryToUpdate,
offsetType: offsetType
};
}

function getTotalTypesCount(offsetType, totalTypes) {
const typesDirectoriesLength = totalTypes - offsetType;
const typesToProcess = processService.getArgument('TYPES');

if (typesToProcess) {
const maybeCount = parseInt(typesToProcess);

if (!Number.isNaN(maybeCount)) {
return Math.min(typesDirectoriesLength, maybeCount);
} else if (typesToProcess === "all") {
return typesDirectoriesLength;
}
}

return 50;
}

function getProcessesCount() {
return processService.getArgument('PROCESS_COUNT') || 1;
}

module.exports = getRunConfig;
18 changes: 18 additions & 0 deletions definitelyTypedTests/src/definitelyTyped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require('path');
const fs = require('fs');

function definitelyTyped() {
const definitelyTypedFolder = path.join('..', 'DefinitelyTyped');

return {
folder: definitelyTypedFolder,
typesFolder: path.join(definitelyTypedFolder, 'types'),
getTypes() {
return this._types || (this._types = fs.readdirSync(this.typesFolder, {withFileTypes: true})
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name));
}
}
}

module.exports = definitelyTyped;
Loading