-
Notifications
You must be signed in to change notification settings - Fork 1.6k
.NET: Add github actions workflow for verify-samples #5034
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d761fb6
Add github actions workflow for verify-samples
westey-m 017621a
Make workflow run as part of PR (for now)
westey-m 5d931d2
Update workflow to remove pr trigger
westey-m 074199b
Merge branch 'main' into verify-samples-build
westey-m 1b9af24
Address PR comments
westey-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # | ||
| # Runs the .NET sample verification tool, which builds and executes sample projects | ||
| # and verifies their output using deterministic checks and AI-powered verification. | ||
| # | ||
| # Results are displayed as a GitHub Job Summary and the CSV report is uploaded as an artifact. | ||
| # | ||
|
|
||
| name: dotnet-verify-samples | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| category: | ||
| description: "Sample category to run (blank for all)" | ||
| required: false | ||
| type: choice | ||
| options: | ||
| - "" | ||
| - "01-get-started" | ||
| - "02-agents" | ||
| - "03-workflows" | ||
| parallelism: | ||
| description: "Max parallel sample runs" | ||
| required: false | ||
| default: "8" | ||
| type: string | ||
| schedule: | ||
| - cron: "0 6 * * 1-5" # Weekdays at 6:00 UTC | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| verify-samples: | ||
| runs-on: ubuntu-latest | ||
| environment: 'integration' | ||
| timeout-minutes: 90 | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
| sparse-checkout: | | ||
| . | ||
| .github | ||
| dotnet | ||
| workflow-samples | ||
|
|
||
| - name: Setup dotnet | ||
| uses: actions/setup-dotnet@v5.2.0 | ||
| with: | ||
| global-json-file: ${{ github.workspace }}/dotnet/global.json | ||
|
|
||
| - name: Azure CLI Login | ||
| if: github.event_name != 'pull_request' | ||
| uses: azure/login@v2 | ||
| with: | ||
| client-id: ${{ secrets.AZURE_CLIENT_ID }} | ||
| tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
| subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
|
|
||
| - name: Run verify-samples | ||
| id: verify | ||
| working-directory: dotnet | ||
| shell: bash | ||
| run: | | ||
| CATEGORY_ARG="" | ||
| if [ -n "$CATEGORY_INPUT" ]; then | ||
| CATEGORY_ARG="--category $CATEGORY_INPUT" | ||
| fi | ||
|
|
||
| dotnet run --project eng/verify-samples -- \ | ||
| $CATEGORY_ARG \ | ||
| --parallel "$PARALLELISM" \ | ||
| --md results.md \ | ||
| --csv results.csv \ | ||
| --log results.log | ||
| env: | ||
| CATEGORY_INPUT: ${{ github.event.inputs.category || '' }} | ||
| PARALLELISM: ${{ github.event.inputs.parallelism || '8' }} | ||
| # OpenAI Models | ||
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
| OPENAI_CHAT_MODEL_NAME: ${{ vars.OPENAI_CHAT_MODEL_NAME }} | ||
| OPENAI_REASONING_MODEL_NAME: ${{ vars.OPENAI_REASONING_MODEL_NAME }} | ||
| # Azure OpenAI Models | ||
| AZURE_OPENAI_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_DEPLOYMENT_NAME }} | ||
| AZURE_OPENAI_CHAT_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_DEPLOYMENT_NAME }} | ||
| AZURE_OPENAI_ENDPOINT: ${{ vars.AZURE_OPENAI_ENDPOINT }} | ||
| # Azure AI Foundry | ||
| AZURE_AI_PROJECT_ENDPOINT: ${{ vars.AZURE_AI_PROJECT_ENDPOINT }} | ||
| AZURE_AI_MODEL_DEPLOYMENT_NAME: ${{ vars.AZURE_AI_MODEL_DEPLOYMENT_NAME }} | ||
| AZURE_AI_BING_CONNECTION_ID: ${{ vars.AZURE_AI_BING_CONNECTION_ID }} | ||
|
|
||
| - name: Write Job Summary | ||
| if: always() | ||
| working-directory: dotnet | ||
| shell: bash | ||
| run: | | ||
| if [ -f results.md ]; then | ||
| cat results.md >> "$GITHUB_STEP_SUMMARY" | ||
| else | ||
| echo "⚠️ No results.md generated — verify-samples may have failed to start." >> "$GITHUB_STEP_SUMMARY" | ||
| fi | ||
|
|
||
| - name: Upload results | ||
| if: always() | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: verify-samples-results | ||
| path: | | ||
| dotnet/results.csv | ||
| dotnet/results.log | ||
| if-no-files-found: warn | ||
|
|
||
| - name: Fail if samples failed | ||
| if: always() && steps.verify.outcome == 'failure' | ||
| shell: bash | ||
| run: exit 1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Text; | ||
|
|
||
| namespace VerifySamples; | ||
|
|
||
| /// <summary> | ||
| /// Writes a Markdown summary of sample verification results. | ||
| /// </summary> | ||
| internal static class MarkdownResultWriter | ||
| { | ||
| /// <summary> | ||
| /// Writes the results to a Markdown file at the specified path. | ||
| /// </summary> | ||
| public static async Task WriteAsync( | ||
| string path, | ||
| IReadOnlyList<VerificationResult> orderedResults, | ||
| IReadOnlyList<(string Name, string Reason)> skipped, | ||
| TimeSpan elapsed) | ||
| { | ||
| var passCount = orderedResults.Count(r => r.Passed); | ||
| var failCount = orderedResults.Count(r => !r.Passed); | ||
|
|
||
| var sb = new StringBuilder(); | ||
| sb.AppendLine("# Sample Verification Results"); | ||
| sb.AppendLine(); | ||
| sb.AppendLine($"**{passCount} passed, {failCount} failed, {skipped.Count} skipped** | Elapsed: {elapsed.Hours:D2}:{elapsed.Minutes:D2}:{elapsed.Seconds:D2}"); | ||
| sb.AppendLine(); | ||
|
|
||
| // Results table | ||
| sb.AppendLine("| Sample | Status | Failed Checks | Failures |"); | ||
| sb.AppendLine("|--------|--------|---------------|----------|"); | ||
|
|
||
| foreach (var result in orderedResults) | ||
| { | ||
| var status = result.Passed ? "✅ PASSED" : "❌ FAILED"; | ||
| var failedChecks = result.Failures.Count; | ||
| var failures = MdEscape(string.Join("; ", result.Failures)); | ||
| sb.AppendLine($"| {MdEscape(result.SampleName)} | {status} | {failedChecks} | {failures} |"); | ||
| } | ||
|
|
||
| foreach (var (name, reason) in skipped) | ||
| { | ||
| sb.AppendLine($"| {MdEscape(name)} | ⏭️ SKIPPED | 0 | {MdEscape(reason)} |"); | ||
| } | ||
|
|
||
| // Collapsible AI reasoning details for failures | ||
| var failures2 = orderedResults.Where(r => !r.Passed && !string.IsNullOrEmpty(r.AIReasoning)).ToList(); | ||
| if (failures2.Count > 0) | ||
| { | ||
| sb.AppendLine(); | ||
| sb.AppendLine("## Failure Details"); | ||
| sb.AppendLine(); | ||
|
|
||
| foreach (var result in failures2) | ||
| { | ||
| sb.AppendLine($"<details><summary><strong>{HtmlEscape(result.SampleName)}</strong></summary>"); | ||
| sb.AppendLine(); | ||
| if (result.Failures.Count > 0) | ||
| { | ||
| foreach (var failure in result.Failures) | ||
| { | ||
| sb.AppendLine($"- {MdEscape(failure)}"); | ||
| } | ||
|
|
||
| sb.AppendLine(); | ||
| } | ||
|
|
||
| sb.AppendLine("**AI Reasoning:**"); | ||
| sb.AppendLine(); | ||
| sb.AppendLine("```"); | ||
| sb.AppendLine(result.AIReasoning); | ||
| sb.AppendLine("```"); | ||
| sb.AppendLine(); | ||
| sb.AppendLine("</details>"); | ||
|
westey-m marked this conversation as resolved.
|
||
| sb.AppendLine(); | ||
| } | ||
| } | ||
|
|
||
| await File.WriteAllTextAsync(path, sb.ToString()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Escapes pipe characters and newlines for use inside Markdown table cells. | ||
| /// </summary> | ||
| private static string MdEscape(string value) | ||
| { | ||
| return value.Replace("|", "\\|").Replace("\n", " ").Replace("\r", ""); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Escapes HTML special characters for use inside HTML tags. | ||
| /// </summary> | ||
| private static string HtmlEscape(string value) | ||
| { | ||
| return value.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.