Skip to content

Pin #:package versions for deterministic restores #21

Pin #:package versions for deterministic restores

Pin #:package versions for deterministic restores #21

name: Validate Samples
on:
workflow_dispatch: # Manual trigger
push:
branches: [ master ]
paths:
- 'samples/**'
- '.github/workflows/**'
pull_request:
branches: [ master ]
paths:
- 'samples/**'
jobs:
compile-samples:
name: Compile All Samples
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
dotnet-quality: 'preview'
- name: Verify .NET version
run: dotnet --version
- name: Compile all samples
run: |
echo "🔨 Compiling all sample files..."
errors=0
for file in samples/*.cs; do
echo ""
echo "=== Compiling: $file ==="
if dotnet build "$file" 2>&1; then
echo "✅ Compiled: $file"
else
echo "❌ Compilation failed: $file"
errors=$((errors + 1))
fi
done
echo ""
if [ $errors -gt 0 ]; then
echo "❌ $errors sample(s) failed to compile"
exit 1
fi
echo "✅ All samples compiled successfully!"
run-samples:
name: Run Samples with Copilot
runs-on: ubuntu-latest
needs: compile-samples
env:
GH_TOKEN: ${{ secrets.COPILOT_PAT }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
dotnet-quality: 'preview'
- name: Validate GitHub auth
run: |
echo "🔐 Validating GitHub auth..."
if [ -z "$GH_TOKEN" ]; then
echo "❌ Missing COPILOT_PAT secret. Add it in repo Settings > Secrets and variables > Actions."
exit 1
fi
gh --version
# GH_TOKEN is provided via secrets.COPILOT_PAT; no interactive auth required.
gh auth status
echo "Token login: $(gh api /user -q .login)"
echo "✅ GitHub auth OK"
- name: Create test fixtures
run: |
# Create a sample log file for log-analyzer
cat > /tmp/test-app.log << 'EOF'
2026-02-07 10:00:01 INFO Application started
2026-02-07 10:00:02 INFO Connected to database
2026-02-07 10:00:05 WARN Slow query detected: 3200ms for SELECT * FROM users
2026-02-07 10:00:10 ERROR NullReferenceException in UserService.GetUser()
2026-02-07 10:00:11 INFO Request processed in 45ms
2026-02-07 10:00:15 ERROR TimeoutException: Connection to Redis timed out after 5000ms
2026-02-07 10:00:20 INFO Health check passed
2026-02-07 10:00:25 WARN Memory usage at 85%
2026-02-07 10:00:30 ERROR SqlException: Deadlock detected
2026-02-07 10:00:35 INFO Cache invalidated for key: user:42
EOF
# Create a sample OpenAPI spec for api-test-generator
cat > /tmp/test-api.json << 'EOF'
{
"openapi": "3.0.0",
"info": { "title": "Test API", "version": "1.0.0" },
"paths": {
"/users": {
"get": { "summary": "List users", "operationId": "listUsers" },
"post": { "summary": "Create user", "operationId": "createUser" }
},
"/users/{id}": {
"get": { "summary": "Get user by ID", "operationId": "getUser" },
"put": { "summary": "Update user", "operationId": "updateUser" },
"delete": { "summary": "Delete user", "operationId": "deleteUser" }
}
}
}
EOF
# Stage a file for git-commit-writer
echo "test change" > /tmp/test-change.txt
echo "✅ Test fixtures created"
- name: "Run: hello-copilot.cs"
run: |
echo "🧪 Running hello-copilot.cs..."
timeout 240 dotnet run samples/hello-copilot.cs 2>&1
echo "✅ hello-copilot.cs completed"
- name: "Run: streaming-chat.cs"
run: |
echo "🧪 Running streaming-chat.cs..."
timeout 240 dotnet run samples/streaming-chat.cs 2>&1
echo "✅ streaming-chat.cs completed"
- name: "Run: custom-tools.cs"
run: |
echo "🧪 Running custom-tools.cs..."
timeout 240 dotnet run samples/custom-tools.cs 2>&1
echo "✅ custom-tools.cs completed"
- name: "Run: multi-model.cs"
run: |
echo "🧪 Running multi-model.cs..."
timeout 240 dotnet run samples/multi-model.cs 2>&1
echo "✅ multi-model.cs completed"
- name: "Run: code-reviewer.cs"
run: |
echo "🧪 Running code-reviewer.cs with samples/hello-copilot.cs as input..."
timeout 240 dotnet run samples/code-reviewer.cs -- samples/hello-copilot.cs 2>&1
echo "✅ code-reviewer.cs completed"
- name: "Run: file-summarizer.cs"
run: |
echo "🧪 Running file-summarizer.cs with README.md as input..."
timeout 240 dotnet run samples/file-summarizer.cs -- README.md 2>&1
echo "✅ file-summarizer.cs completed"
- name: "Run: git-commit-writer.cs"
run: |
echo "🧪 Running git-commit-writer.cs..."
# Create a staged change so the tool has something to work with
echo "// CI test" >> samples/hello-copilot.cs
git add samples/hello-copilot.cs
timeout 240 dotnet run samples/git-commit-writer.cs 2>&1
# Restore the file
git checkout samples/hello-copilot.cs
echo "✅ git-commit-writer.cs completed"
- name: "Run: log-analyzer.cs"
run: |
echo "🧪 Running log-analyzer.cs with test log file..."
timeout 240 dotnet run samples/log-analyzer.cs -- /tmp/test-app.log errors 2>&1
echo "✅ log-analyzer.cs completed"
- name: "Run: api-test-generator.cs"
run: |
echo "🧪 Running api-test-generator.cs with test OpenAPI spec..."
timeout 240 dotnet run samples/api-test-generator.cs -- /tmp/test-api.json xunit 2>&1
echo "✅ api-test-generator.cs completed"
- name: "Run: test-data-generator.cs"
run: |
echo "🧪 Running test-data-generator.cs..."
timeout 240 dotnet run samples/test-data-generator.cs -- user 5 json 2>&1
echo "✅ test-data-generator.cs completed"
- name: "Run: interactive-chat.cs (piped stdin)"
run: |
echo "🧪 Running interactive-chat.cs with simulated input..."
# Pipe two messages then 'exit' to simulate an interactive REPL session
printf "What is 2+2?\nexit\n" | timeout 240 dotnet run samples/interactive-chat.cs 2>&1
echo "✅ interactive-chat.cs completed"
- name: Install Playwright browsers
run: |
echo "🌐 Installing Playwright Chromium browser..."
# Build the sample first so the Playwright package is restored
dotnet build samples/playwright-agent.cs
# Install Chromium with system dependencies
dotnet tool install --global Microsoft.Playwright.CLI || true
playwright install --with-deps chromium || npx --yes playwright install --with-deps chromium || true
echo "✅ Playwright browsers installed"
- name: "Run: playwright-agent.cs (headless Chromium)"
run: |
echo "🧪 Running playwright-agent.cs against https://example.com..."
timeout 240 dotnet run samples/playwright-agent.cs -- https://example.com "Describe what you see on the page" 2>&1
echo "✅ playwright-agent.cs completed"
- name: Summary
run: |
echo ""
echo "========================================="
echo " 📊 Sample Execution Summary"
echo "========================================="
echo ""
echo "✅ All 12/12 samples executed:"
echo " hello-copilot.cs"
echo " streaming-chat.cs"
echo " custom-tools.cs"
echo " multi-model.cs"
echo " code-reviewer.cs"
echo " file-summarizer.cs"
echo " git-commit-writer.cs"
echo " log-analyzer.cs"
echo " api-test-generator.cs"
echo " test-data-generator.cs"
echo " interactive-chat.cs (piped stdin)"
echo " playwright-agent.cs (headless Chromium)"
echo ""
echo "========================================="
validate-readme:
name: Validate Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check all samples are documented
run: |
echo "📚 Checking README documentation..."
samples=$(ls samples/*.cs | xargs -n 1 basename)
missing=0
for sample in $samples; do
if ! grep -q "$sample" README.md; then
echo "❌ Not documented: $sample"
missing=$((missing + 1))
else
echo "✅ Documented: $sample"
fi
done
if [ $missing -gt 0 ]; then
echo "❌ $missing sample(s) missing from README"
exit 1
fi
echo "✅ All samples documented!"