-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[storage] Updates to samples for CI and local runs #6496
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
Changes from 33 commits
2a5230b
dd98eb2
2fe35d9
0d68724
72e49cb
adb764c
160ab84
8d1070d
7951b5a
03c7b22
6adcb5d
9a793e6
ef9a3d4
6ac61c7
12b3d00
5465f4c
8039b80
e552211
b77c6b4
14e6fbe
d2e70ca
1ab154b
b27c65c
0a1edcf
8f8b6e2
2de6076
5de8348
30b38b4
46ac984
77c602d
c1fd600
6f97268
98fa55c
787e631
1e25ece
d6653e5
e10e99b
3145d3c
3be4483
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| /** | ||
| * run-samples.js | ||
| * | ||
| * Runs all JavaScript files in a directory, using the calling convention for | ||
| * our sample code. | ||
| */ | ||
|
|
||
| const baseFS = require("fs"); | ||
| const path = require("path"); | ||
|
|
||
| const IGNORE = ["node_modules", "sampleHelpers.js"]; | ||
|
|
||
| // Node >= 10 provide fs.promises, but since we're still building Node 8 for now | ||
| // we need to use util.promisify if fs.promises doesn't exist | ||
| const fs = | ||
| baseFS.promises || | ||
| (() => { | ||
| const promisify = require("util").promisify; | ||
| return { | ||
| readdir: promisify(baseFS.readdir) | ||
| }; | ||
| })(); | ||
|
|
||
| /** | ||
| * Breadth-first search for files matching a given predicate | ||
| * | ||
| * @param {string} tsDir The root of the sample tree to search | ||
| * @param {(fs.Entry) => boolean} matches Predicate that decides whether or not a file entry is included | ||
| * @returns | ||
| */ | ||
| async function* findMatchingFiles(tsDir, matches) { | ||
| const initialFiles = await fs.readdir(tsDir, { withFileTypes: true }); | ||
|
|
||
| // BFS Queue and queue index | ||
| const q = initialFiles.map(f => [f, tsDir]); | ||
|
|
||
| while (q.length) { | ||
| // [fs.Dirent, string] (file and dirName part of the full path) | ||
| const [entry, dirName] = q.shift(); | ||
| const fullPath = path.join(dirName, entry.name); | ||
|
|
||
| if (IGNORE.includes(entry.name)) { | ||
| console.log("[run-samples] Ignoring", fullPath); | ||
| continue; | ||
| } | ||
|
|
||
| if (entry.isDirectory()) { | ||
| // Enqueue children of this directory to the bfs | ||
| const children = await fs.readdir(fullPath, { withFileTypes: true }); | ||
| for (const child of children) { | ||
| q.push([child, fullPath]); | ||
| } | ||
| } else if (matches(entry)) { | ||
| yield fullPath; | ||
| } | ||
| } | ||
|
|
||
| // The full trace of files visited by the iterator is returned and can be accessed using `iter.value` | ||
| // once it is `done`, in case it is ever needed for debugging | ||
| return q; | ||
| } | ||
|
|
||
| async function main() { | ||
| // Accept a base directory | ||
| const args = process.argv.slice(2); | ||
|
|
||
| let sampleDir; | ||
| if (args.length) { | ||
| sampleDir = path.resolve(args[0]); | ||
| } else { | ||
| sampleDir = process.cwd(); | ||
| } | ||
|
|
||
| // Patch the environment for the sample helper | ||
| process.env.BATCH_RUN_SAMPLES = "true"; | ||
|
|
||
| console.log("[run-samples] Running all samples in:", sampleDir); | ||
|
|
||
| let errors = []; | ||
|
|
||
| for await (const fileName of findMatchingFiles( | ||
| sampleDir, | ||
| entry => entry.isFile() && entry.name.endsWith(".js") | ||
| )) { | ||
| console.log("[run-samples] Running", fileName); | ||
| const { main: sampleMain } = require(fileName); | ||
| try { | ||
| await sampleMain(); | ||
| } catch (err) { | ||
| const truncatedError = err | ||
| .toString() | ||
| .split("\n")[0] | ||
| .slice(0, 100); | ||
| errors.push([path.basename(fileName), truncatedError]); | ||
| console.warn("[run-samples] Error in", fileName, ":", err); | ||
| console.warn("[run-samples] Continuing ..."); | ||
| } | ||
| } | ||
|
|
||
| if (errors.length > 0) { | ||
| console.error("[run-samples] Errors occurred in the following files:"); | ||
| for (const [fileName, error] of errors) { | ||
| console.error(" -", fileName, "(", error, ")"); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| main().catch(err => { | ||
| console.error("[run-samples] Error:", err); | ||
| process.exit(1); | ||
| }); |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,14 +24,17 @@ | |
| "build:autorest": "autorest ./swagger/README.md --typescript --package-version=12.0.1 --use=@microsoft.azure/autorest.typescript@5.0.1", | ||
| "build:es6": "tsc -p tsconfig.json", | ||
| "build:nodebrowser": "rollup -c 2>&1", | ||
| "build:js-samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1", | ||
| "build:ts-samples": "npm run clean && cd samples && tsc -p . ", | ||
| "build:samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1 && npm run build:prep-samples", | ||
| "build:prep-samples": "node ../../../common/scripts/prep-samples.js && cd samples && tsc", | ||
| "build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1", | ||
| "build": "npm run build:es6 && npm run build:nodebrowser && api-extractor run --local", | ||
| "check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", | ||
| "clean": "rimraf dist dist-esm dist-test typings temp browser/*.js* browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", | ||
| "clean:samples": "rimraf samples/javascript/node_modules samples/typescript/node_modules samples/typescript/dist samples/typescript/package-lock.json samples/javascript/package-lock.json", | ||
| "extract-api": "tsc -p . && api-extractor run --local", | ||
| "execute:samples": "node execute-samples.js", | ||
| "execute:js-samples": "node ../../../common/scripts/run-samples.js samples/javascript/", | ||
| "execute:ts-samples": "node ../../../common/scripts/run-samples.js samples/typescript/dist/samples/typescript/src/", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [NIT]
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because it is not using the rollup artifact. It is actually importing the package sources as modules, so the tree in An alternative would be to use |
||
| "execute:samples": "npm run build:samples && npm run execute:js-samples && npm run execute:ts-samples", | ||
| "format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", | ||
| "integration-test:browser": "karma start --single-run", | ||
| "integration-test:node": "nyc mocha --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace -t 120000 --retries 2 dist-test/index.node.js", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
tsDir=>dir