Skip to content

Commit

Permalink
Add PR CI step to build samples (Azure#12715)
Browse files Browse the repository at this point in the history
* Add PR CI step to build samples

* Made a change to rush-runner

* Fixed an issue with rush-runner patch

* Repaired metricsadvisor and anomalydetector samples builds

* Repaired storage samples build scripts, added skip to storage-internal-avro

* Added skips to core packages without samples

* Resolved conflicting options in identity samples

* Skipped broken test scripts

* pnpm-lock

* [eventhubs-checkpointstore-blob] fix build:samples script (#3)

* [event-processor-host] fix build:samples script

* Revert sorting of package.json script entries

* Fixed merge artifact in dev-tool package.json

* pnpm-lock

* Revert formatting changes to anomalydetector

* Run build phase with transitive dependencies.

* Add stub build:samples commands for synapse

* Added samples build setup for tables

* Repaired two broken links in EPH

Co-authored-by: chradek <[email protected]>
Co-authored-by: chradek <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2020
1 parent af4c58e commit 6ffd578
Show file tree
Hide file tree
Showing 55 changed files with 1,294 additions and 154 deletions.
705 changes: 623 additions & 82 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/tools/dev-tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build": "tsc",
"build:test": "echo skipped",
"build:test": "echo Skipped.",
"clean": "rimraf dist dist-* *.tgz *.log",
"extract-api": "echo skipped",
"format": "prettier --write src/**/*.ts test/**/*.ts *.{js,json}",
Expand Down
10 changes: 7 additions & 3 deletions common/tools/dev-tool/src/commands/samples/prep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export const commandInfo = makeCommandInfo(
* @param pkgName name of the package to use when looking for package-local imports
* @param usePackages uses package dependencies if true, uses source dependencies if false
*/
async function enableLocalRun(fileName: string, baseDir: string, pkgName: string, usePackages: boolean) {
async function enableLocalRun(
fileName: string,
baseDir: string,
pkgName: string,
usePackages: boolean
) {
const fileContents = await fs.readFile(fileName, { encoding: "utf-8" });
const isTs = fileName.endsWith(".ts");

Expand All @@ -54,7 +59,6 @@ async function enableLocalRun(fileName: string, baseDir: string, pkgName: string
return;
}


const relativeDir = path.dirname(fileName.replace(baseDir, ""));

// `string.length - string.split(path.sep).join("").length` is a dirty but well-supported way to
Expand Down Expand Up @@ -99,7 +103,7 @@ export default leafCommand(commandInfo, async (options) => {
// Create dist-samples and copy to it
const outputDir = path.join(pkg.path, "dist-samples");
if (fs.existsSync(outputDir)) {
log.warn("Cleaning up old dist-samples folder.");
log.info("Cleaning up old dist-samples folder.");
await fs.remove(outputDir);
}
await fs.copy(path.join(pkg.path, "samples"), outputDir);
Expand Down
1 change: 1 addition & 0 deletions common/tools/eslint-plugin-azure-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
],
"scripts": {
"build": "tsc -p tsconfig.build.json && prettier --write dist/**/*.{js,json,md}",
"build:samples": "echo Skipped.",
"build:test": "npm run clean && tsc -p tsconfig.json",
"clean": "rimraf dist/",
"format": "prettier --write \"./**/*.{ts,json,md}\"",
Expand Down
6 changes: 5 additions & 1 deletion eng/pipelines/templates/steps/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ steps:
# Option "-p max" ensures parallelism is set to the number of cores on all platforms, which improves build times.
# The default on Windows is "cores - 1" (microsoft/rushstack#436).
- script: |
node eng/tools/rush-runner.js build "${{parameters.ServiceDirectory}}" --verbose -p max
node eng/tools/rush-runner.js build "${{parameters.ServiceDirectory}}" --verbose -p max --TransitiveDep
displayName: "Build libraries"
- pwsh: |
Expand All @@ -48,6 +48,10 @@ steps:
node eng/tools/rush-runner.js pack "${{parameters.ServiceDirectory}}" --verbose
displayName: "Pack libraries"
- script: |
node eng/tools/rush-runner.js build:samples "${{parameters.ServiceDirectory}}" --verbose
displayName: "Build samples"
# Unlink node_modules folders to significantly improve performance of subsequent tasks
# which need to walk the directory tree (and are hardcoded to follow symlinks).
- script: |
Expand Down
1 change: 1 addition & 0 deletions sdk/anomalydetector/ai-anomaly-detector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@types/node": "^8.0.0",
"chai": "^4.2.0",
"cross-env": "^7.0.2",
"csv-parse": "^4.4.0",
"dotenv": "^8.2.0",
"eslint": "^6.1.0",
"inherits": "^2.0.3",
Expand Down
16 changes: 13 additions & 3 deletions sdk/anomalydetector/ai-anomaly-detector/samples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
"compilerOptions": {
"module": "commonjs",
"outDir": "typescript/dist",
"lib": ["DOM", "ES6"]
"lib": [
"DOM",
"ES6"
]
},
"include": ["typescript/src/**.ts"],
"exclude": ["typescript/*.json", "**/node_modules/", "../node_modules", "../typings"]
"include": [
"typescript/src/**.ts"
],
"exclude": [
"typescript/*.json",
"**/node_modules/",
"../node_modules",
"../typings"
]
}
2 changes: 1 addition & 1 deletion sdk/communication/communication-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:autorest": "autorest ./swagger/README.md --typescript --version=3.0.6267 --v3 --package-version=1.0.0-beta.3 && rushx format",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "cd samples && tsc -p .",
"build:samples": "echo Skipped.",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
"check-format": "prettier --list-different \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/communication-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "cd samples && tsc -p .",
"build:samples": "echo Skipped.",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
"check-format": "prettier --list-different \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/communication-sms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build:autorest": "autorest ./swagger/README.md --typescript --v3 --package-version=1.0.0-beta.3 && rushx format",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "cd samples && tsc -p .",
"build:samples": "echo Skipped.",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
"check-format": "prettier --list-different \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "cd samples && tsc -p .",
"build:samples": "echo Skipped.",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build:types": "downlevel-dts types/latest types/3.1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local && npm run build:types",
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "npm run build:ts && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "npm run build:ts && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "cd samples && tsc -p .",
"build:samples": "echo Skipped.",
"build:test": "npm run build:ts && npm run bundle:test",
"build:test:browser": "npm run build:ts && npm run bundle:test:browser",
"build:test:node": "npm run build:ts && npm run bundle:test:node",
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-https/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "npm run build:ts && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "npm run build:ts && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "cd samples && tsc -p .",
"build:samples": "echo Skipped.",
"build:test": "npm run build:ts && npm run bundle:test",
"build:test:browser": "npm run build:ts && npm run bundle:test:browser",
"build:test:node": "npm run build:ts && npm run bundle:test:node",
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-tracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "cd samples && tsc -p .",
"build:samples": "echo Skipped.",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-xml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "npm run build:ts && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "npm run build:ts && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "cd samples && tsc -p .",
"build:samples": "echo Skipped.",
"build:test": "npm run build:ts && npm run bundle:test",
"build:test:browser": "npm run build:ts && npm run bundle:test:browser",
"build:test:node": "npm run build:ts && npm run bundle:test:node",
Expand Down
2 changes: 1 addition & 1 deletion sdk/digitaltwins/digital-twins-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1",
"build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1",
"build:test": "npm run build:test:node && npm run build:test:browser",
"build:samples": "dev-tool samples prep && cd dist-samples && tsc -p .",
"build:samples": "echo Skipped.",
"check-format": "prettier --list-different --config ../../.prettierrc.json --ignore-path ../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-esm dist-browser test-dist test-browser types *.tgz *.log",
"coverage": "nyc --reporter=lcov --exclude-after-remap=false mocha -t 120000 dist-test/index.node.js --reporter ../../../common/tools/mocha-multi-reporter.js",
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventgrid/eventgrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"build:autorest": "autorest ./swagger/README.md --typescript --v3",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "node ../../../common/scripts/prep-samples.js && cd samples && tsc -p .",
"build:samples": "echo Skipped.",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventhub/event-processor-host/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## 2.1.0 (2019-08-06)

- Added support for WebSockets. WebSockets enable Event processor Host to work over an HTTP proxy and in environments where the standard AMQP port 5671 is blocked.
Refer to the [websockets](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-processor-host/samples/websockets.ts) sample to see how to use WebSockets.
Refer to the [websockets](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-processor-host/samples/typescript/src/websockets.ts) sample to see how to use WebSockets.
- Fixed [bug 4363](https://github.com/Azure/azure-sdk-for-js/issues/4363) which stopped users from providing their own LeaseManager. If both a lease manager and the options for leaseDuration/leaseRenewInterval are provided, then the latter will be ignored in favor of the leaseDuration/leaseRenewInterval properties on the lease manager.

## 2.0.0 (2019-07-16)
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventhub/event-processor-host/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ create each instance in a separate process or a separate machine. This should pr
The following samples focus on EPH (Event Processor Host) which is responsible for receiving messages.
For sending messages to the EventHub, please use the `azure-event-hubs` package from npm. More
information about the event hub client can be found over [here](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs).
You can also use [this example](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-processor-host/samples/sendBatch.ts) that sends
You can also use [this example](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-processor-host/samples/typescript/src/sendBatch.ts) that sends
multiple messages batched together. You should be able to run the `send` example from one terminal window and see those messages
being received in the `singleEph` or `multipleEph` example being run in the second terminal window.

Expand Down
3 changes: 2 additions & 1 deletion sdk/eventhub/event-processor-host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "cd samples && tsc -p .",
"build:samples": "dev-tool samples prep && cd dist-samples && tsc",
"build:test": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1 && npm run extract-api",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand Down Expand Up @@ -76,6 +76,7 @@
"uuid": "^8.3.0"
},
"devDependencies": {
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@microsoft/api-extractor": "7.7.11",
"@rollup/plugin-commonjs": "11.0.2",
Expand Down
33 changes: 33 additions & 0 deletions sdk/eventhub/event-processor-host/samples/javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Getting started with samples

## Install the library

Run the below in your samples folder to install the npm package for Event Processor Host library.

```bash
npm install @azure/event-processor-host
```

## Get connection string & Event Hubs name

- In the [Azure Portal](https://portal.azure.com), go to **Dashboard > Event Hubs > _your-eventhubs-namespace_**.
- If you don't have a Event Hubs resource, then Here are the docs which would help you create a EventHubs/Iothub resources in the portal:
- [Azure Event Hubs - NodeJS DOCS](https://docs.microsoft.com/azure/event-hubs/event-hubs-node-get-started-send).
- [Azure IoT Hubs - NodeJS DOCS](https://docs.microsoft.com/azure/iot-hub/iot-hub-node-node-module-twin-getstarted).
- Note down the "Primary Connection String" of **RootManageSharedAccessKey** at **Shared access policies** under **Settings** tab.
- Find the "Event Hubs" tab right under "Entities" at **_your-eventhubs-namespace_**, create a Event Hub and note down its name.
> _Note : **RootManageSharedAccessKey** is automatically created for the namespace and has permissions for the entire namespace. If you want to use restricted access, refer [Shared Access Signatures](https://docs.microsoft.com/rest/api/eventhub/generate-sas-token), create the Access Keys exclusive to the specific Event Hubs._
- You would also need an Azure Storage Account when working with Event Processor Host. The docs are at
[Create a storage account](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal). After the storage account is created, find the connection string at **Access keys** tab in the **Settings** section.

Before running a sample, update it with the connection string and the hub name you have noted down above.

## Running a sample

Copy the sample to your samples folder and use `node` to run it.

```bash
node sample.js
```

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Feventhub%2Fevent-processor-host%2Fsamples%2FREADME.png)
106 changes: 106 additions & 0 deletions sdk/eventhub/event-processor-host/samples/javascript/iothubEph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT Licence.
This sample demonstrates how to use Event Processor Host to receive events from all partitions
of an IoTHub instance. It also shows how to checkpoint metadata for received events at regular
intervals in an Azure Storage Blob.
*/

const { EventProcessorHost, delay } = require("@azure/event-processor-host");

// Define IoT Hub and storage connection strings here
const iotConnectionString = "";
const storageConnectionString = "";

// Use `createHostName` to create a unique name based on given prefix to use different storage containers on each run if needed.
const storageContainerName = EventProcessorHost.createHostName("iothub-container");
const ephName = "my-iothub-eph";

async function main() {
// Start eph.
const eph = await startEph(ephName);
// Sleeeping for 90 seconds. This will give time for eph to receive messages.
await delay(90000);
// After 90 seconds stop eph.
await stopEph(eph);
}

main().catch((err) => {
console.log("Exiting from main() due to an error: %O.", err);
});

/**
* Creates an EPH with the given name and starts the EPH.
* @param ephName The name of the EPH.
* @returns {Promise<EventProcessorHost>} Promise<EventProcessorHost>
*/
async function startEph(ephName) {
// Create an Event Processor Host from an IotHub ConnectionString
const eph = await EventProcessorHost.createFromIotHubConnectionString(
ephName,
storageConnectionString,
storageContainerName,
iotConnectionString,
{
onEphError: (error) => {
console.log("[%s] Error: %O", ephName, error);
}
}
);
// Message handler
const partionCount = {};
const onMessage = async (context, event) => {
!partionCount[context.partitionId]
? (partionCount[context.partitionId] = 1)
: partionCount[context.partitionId]++;
console.log(
"[%s] %d - Received message from partition: '%s', offset: '%s'",
ephName,
partionCount[context.partitionId],
context.partitionId,
event.offset
);
// Checkpointing every 100th event received for a given partition.
if (partionCount[context.partitionId] % 100 === 0) {
try {
console.log(
"[%s] EPH is currently receiving messages from partitions: %O",
ephName,
eph.receivingFromPartitions
);
await context.checkpointFromEventData(event);
console.log(
"[%s] Successfully checkpointed message number %d",
ephName,
partionCount[context.partitionId]
);
} catch (err) {
console.log(
"[%s] An error occurred while checkpointing msg number %d: %O",
ephName,
partionCount[context.partitionId],
err
);
}
}
};
// Error handler
const onError = (error) => {
console.log("[%s] Received Error: %O", ephName, error);
};
console.log("Starting the EPH - %s", ephName);
await eph.start(onMessage, onError);
return eph;
}

/**
* Stops the given EventProcessorHost.
* @param eph The event processor host.
* @returns {Promise<void>} Promise<void>
*/
async function stopEph(eph) {
console.log("Stopping the EPH - '%s'.", eph.hostName);
await eph.stop();
console.log("Successfully stopped the EPH - '%s'.", eph.hostName);
}
Loading

0 comments on commit 6ffd578

Please sign in to comment.