-
Notifications
You must be signed in to change notification settings - Fork 2k
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
README - compilable code snippets #6609
Conversation
I like this a lot. It will help to ensure our samples are always accurate and compiling. I think introducing a new sample file (ReadmeSamples.java) is a good idea and should be used consistently, especially given the line referencing approach used in the markdown. I would recommend you introduce some warning text at the top of these files to warn users against making any changes to the code that may result in line number differences. |
Would it be possible to update the Blob Batch README to use these? It already has a |
Need to update the exclusion regex here to include ReademeSamples classes. |
@@ -34,6 +34,8 @@ The following sections provide several code snippets covering some of the most c | |||
Create a Netty Http client that uses port 80 and has no proxy. | |||
|
|||
```java | |||
// ./src/samples/java/com/azure/core/http/netty/ReadmeSamples.java#L19-L19 |
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.
Is there a way to hide this in the README?
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.
There is a way to hide but I like to leave it as it is so that we'll know where the snippets are coming from and leaving it here will allow for future updates to automatically pick up the changes.
@JonathanGiles Added a warning message to ReadmeSamples.java to ensure line numbers are correct. |
@@ -558,7 +558,8 @@ | |||
<Match> | |||
<Or> | |||
<Class name="~.*JavaDoc(CodeSnippets|CodeSamples|Samples)"/> | |||
<Class name="com.azure.storage.blob.batch.ReadmeCodeSamples"/> | |||
<Class name="~.*ReadmeSamples"/> | |||
<Class name="com.azure.storage.blob.batch.ReadmeSamples"/> |
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.
You shouldn't need to explicitly call out the batch file should you?
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.
Removed it.
@@ -34,6 +34,8 @@ The following sections provide several code snippets covering some of the most c | |||
Create a Netty Http client that uses port 80 and has no proxy. | |||
|
|||
```java | |||
// ./src/samples/java/com/azure/core/http/netty/ReadmeSamples.java#L23-L23 |
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.
I agree with Alan, I'm not convinced that we want these to show up in all of the code samples. If we can hide it, whilst still retaining the ability for it to be updated when the sample code is changed, that would be best IMHO.
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.
Using alternate embedding syntax that will hide the comment in README and will continue to be updated when sample code changes.
Should we introduce tooling into /eng that would run this over all readme files? |
@JonathanGiles Yes, I will have a follow-up task to introduce tooling that will automatically run this to update READMEs. This PR is a first step to get everyone's thoughts on the tool and usage. If we want to go ahead with this, I will look into integrating with eng tools. |
* Use compilable code snippets in README * Update paths and line numbers * Add warning to ReadmeSamples.java and update storage blob batch snippets as well * Address PR comments * Update Identity samples * Remove unused file
READMEs are the first point of interaction for users looking to use our SDKs. It contains several useful code snippets for users to get started quickly. It is important to keep these code samples correct at all times. However, when code is modified README gets outdated and hard to figure out which README is referencing the modified piece of code.
So, this change will introduce a mechanism to inject code from a compiled Java class to ensure freshness of samples.
Tool used - https://github.com/zakhenry/embedme
How to use:
embedme
tool as shown below:This PR is using this tool for
Partially fixes #6608