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

[storage] Updates to samples for CI and local runs #6496

Merged
merged 39 commits into from
Dec 16, 2019

Conversation

willmtemple
Copy link
Contributor

A lot of changes here. All addressing some different things. This is part of the work for #5679

  • added support for the JS samples to prep-samples (fixes part one of Samples run fails in CI #6362 )
  • We can run the samples again with npm run execute:samples. This command will prep, build, and run both the TS and JS samples (fixes part two of Samples run fails in CI #6362 )
  • The packages should be nicer to run locally and support dotenv
  • Should be fully ready for publication on docs.microsoft.com, though we are still not seeing the file-share samples there.
  • I made sure that the packages are really runnable, by zipping them up, unzipping them outside of the repo, and running npm install && npm run execute:all
  • There is a batch run command in the form of npm run execute:all, which replaces execute-samples.js and ensures that our CI process will mirror the user process
  • Fixed a couple of small bugs with the samples that only show up once they leave the repo
  • Added copyright headers to the sample files

@willmtemple willmtemple added Client This issue points to a problem in the data-plane of the library. Storage Storage Service (Queues, Blobs, Files) labels Dec 11, 2019
@willmtemple willmtemple self-assigned this Dec 11, 2019
@ramya-rao-a ramya-rao-a requested a review from xirzec December 11, 2019 04:41
@XiaoningLiu
Copy link
Member

Will this apply to queue and file-datalake?

Copy link
Member

@richardpark-msft richardpark-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runnable samples!

["basic", basicMain],
["customPipeline", customPipelineMain],
["iterators-files-and-directories", iteratorsFilesAndDirectoriesMain],
// ["iterators-handles", iteratorsHandlesMain], // Must be populated with a pre-existing share/directory name to run
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just add in the name of the share to the sample.env and let the user fill them in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but it would still require that it already exists, so we would have to then have some external way to mask it out for CI. I think a better solution is to modify the sample so that it doesn't rely on any pre-existing resources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not understanding this bit:

I think a better solution is to modify the sample so that it doesn't rely on any pre-existing resources.

This is true but by the time the sample runs how/when the resource was created doesn't really matter, only that the environment variables point to the right thing. So it still seems like having those values specified in the sample.env makes sense to me.

SDK developers will create the identity once, the storage account once and just use that over and over (via .env)
CI will create the identity multiple times, the storage account multiple times and just use that over and over (by injecting environment variables directly).

Or am I missing how you want to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the rest of the examples in the storage packages create and tear down their resources dynamically, and the only thing they need is an account. I think we should just have this sample do the same thing. What I'm going to do for now is just make the samples exit if they aren't configured, and so this one will run fine in the runner if the environment variables aren't set up. It'll just log a message and skip itself. I'll add the variables to sample.env for customers' sake, but our CI shouldn't have to provision a share and a directory with some open handles to run this sample since that's a lot for the CI harness to have to set up and I'm not even sure if it could do that.

@@ -0,0 +1,9 @@
# Used in most samples. Retrieve these values from a storage account in the Azure Portal.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For your identity tests you're welcome to copy the lines that I also copied from somewhere else:

# Used in the usingAadAuth.ts sample

That way they don't have to enter the credentials in the environment (or paste them into their source code).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can standardize on something between: maybe a quick set of instructions and links to the docs for EnvironmentCredential in identity

@willmtemple
Copy link
Contributor Author

@XiaoningLiu I'm working on Queue today, and it will apply to files-datalake eventually, but datalake isn't on my list of packages to take care of immediately.

writeFile: promisify(baseFS.writeFile)
};
})();

/**
* Breadth-first search for files ending in .ts, starting from `tsDir`
* Breadth-first search for files matching a given predicate
*
* @param {string} tsDir The root of the sample tree to search
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: tsDir => dir

"keywords": [
"Azure",
"Storage",
"File",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File [](start = 5, length = 4)

Minor. Should be "Queue", please check other package.json files

Copy link
Member

@XiaoningLiu XiaoningLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

const { AnonymousCredential, BlobServiceClient, newPipeline } = require("../.."); // Change to "@azure/storage-blob" in your package
const { AnonymousCredential, BlobServiceClient, newPipeline } = require("@azure/storage-blob");

const { runSample } = require("./sampleHelpers");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is addressed already.. this would confuse users?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offline discussion with Will..

  • We are going to provide samples through docs.microsoft.com similar to below
    https://docs.microsoft.com/en-ca/samples/browse/?products=azure-storage&languages=javascript%2Cnodejs
    • separate zipped folders for javascript and typescript samples - just like the Download Zip link here.
    • In the bullet-list of links in the readmes, docs.microsoft.com/samples link will be provided instead of the samples folder link
    • js samples are located at samples/javascript whereas the ts samples are at samples/typescript/src
  • To improve user-convenience of just copy/pasting one single sample, @willmtemple will be looking to remove ./sampleHelpers part of the samples

@jeremymeng

@willmtemple
Copy link
Contributor Author

@HarshaNalluru most recent changes modify prep-samples.js so that in addition to changing the imports around, it also snips main().catch and anything occurring thereafter from the file. Makes it so sampleHelpers isn't required.

@willmtemple
Copy link
Contributor Author

/azp run js - storage-queue - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

"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/",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NIT]
samples/typescript/dist/samples/typescript/src/ ?
samples/typescript/dist/ is not enough?

Copy link
Contributor Author

@willmtemple willmtemple Dec 16, 2019

Choose a reason for hiding this comment

The 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 samples/typescript/dist after compilation looks something like this:

dist/
  - samples/
    - typescript/
      - src/
        - basic.js
        - ... (compiled sample code)
  - src/
    - StorageClient.js
    - ... (compiled client code)

An alternative would be to use ts-node rather than compile and run the samples, like the previous script was doing, but that has its own set of problems (would need to make the *-samples scripts their own package and add ts-node as a dependency, otherwise we would be requiring global ts-node -- more than I think I can get done before leaving for the holidays).

@willmtemple
Copy link
Contributor Author

/azp run js - storage-blob - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@willmtemple
Copy link
Contributor Author

/azp run js - storage-file-share - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@willmtemple
Copy link
Contributor Author

/azp run js - storage-file-share - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@willmtemple
Copy link
Contributor Author

This last yellow check looks like it's stuck. AzP says that all pipelines have passed, so I am merging this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants