Skip to content

Commit a8395ba

Browse files
authored
Improves 'Update samples' workflow. Closes #700 (#747)
## 🎯 Aim This PR updates 'Update Sample' workflow to include sample stats in the PR body. ## 📷 Result <img width="725" height="333" alt="image" src="https://github.com/user-attachments/assets/c2bf2a3b-c470-4f66-8f04-0f1bd5f0d397" /> ## ✅ What was done - [X] generated sample stats, JSON validation and injected in PR description ## 🔗 Related issue Closes: #700
1 parent 14f3c27 commit a8395ba

2 files changed

Lines changed: 63 additions & 4 deletions

File tree

.github/workflows/update-samples.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,29 @@ jobs:
4646
- run: |
4747
dir
4848
49-
- run: .\scripts\prepare-sample-data.ps1 -workspacePath "${{ github.workspace }}"
49+
- name: Generate sample data
50+
run: .\scripts\prepare-sample-data.ps1 -workspacePath "${{ github.workspace }}"
51+
shell: pwsh
52+
53+
- name: Read statistics
54+
id: stats
55+
run: |
56+
$delimiter = "EOF_STATS_$(Get-Random)"
57+
$stats = Get-Content sample-stats.txt -Raw
58+
"STATS<<$delimiter" >> $env:GITHUB_OUTPUT
59+
$stats >> $env:GITHUB_OUTPUT
60+
$delimiter >> $env:GITHUB_OUTPUT
61+
Remove-Item sample-stats.txt
5062
shell: pwsh
51-
continue-on-error: true
5263

5364
- name: Create Pull Request
5465
uses: peter-evans/create-pull-request@v5
5566
with:
5667
commit-message: Updates sample data
5768
branch: update-sample-data
5869
title: Sample data update
59-
body: Automated check and update of SPFx extensions and webparts samples data and aces sample data.
70+
body: |
71+
Automated check and update of SPFx extensions and webparts samples data and aces sample data.
72+
73+
${{ steps.stats.outputs.STATS }}
6074
...

scripts/prepare-sample-data.ps1

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,50 @@ $orderedSampleModel = [ordered]@{}
185185
foreach ($Item in ($sampleModel.GetEnumerator() | Sort-Object -Property Key)) {
186186
$orderedSampleModel[$Item.Key] = $Item.Value
187187
}
188-
New-Object -TypeName psobject -Property $orderedSampleModel | ConvertTo-Json -Depth 10 | Out-File "$workspacePath\data\sp-dev-fx-samples.json"
188+
189+
$jsonOutput = New-Object -TypeName psobject -Property $orderedSampleModel | ConvertTo-Json -Depth 10
190+
191+
try {
192+
$null = ConvertFrom-Json -InputObject $jsonOutput -ErrorAction Stop
193+
Write-Output "`nJSON validation passed"
194+
}
195+
catch {
196+
Write-Error "`nGenerated JSON is invalid: $($_.Exception.Message)"
197+
exit 1
198+
}
199+
200+
$jsonOutput | Out-File "$workspacePath\data\sp-dev-fx-samples.json"
201+
202+
$totalSamples = $samples.Count
203+
$statsByRepo = $samples | Group-Object -Property sampleGallery | Sort-Object Name
204+
205+
$statsLines = @()
206+
$statsLines += '## Sample Data Summary'
207+
$statsLines += ''
208+
$statsLines += '✅ **JSON Validation:** Passed'
209+
$statsLines += ''
210+
$statsLines += "**Total Samples:** $totalSamples"
211+
$statsLines += ''
212+
$statsLines += '### Breakdown by Repository'
213+
214+
foreach ($stat in $statsByRepo) {
215+
$statsLines += "- **$($stat.Name):** $($stat.Count)"
216+
}
217+
218+
$statsContent = $statsLines -join "`n"
219+
220+
# temp output for PR body; will be deleted after PR is raised
221+
$statsContent | Out-File "$workspacePath\sample-stats.txt" -Encoding utf8
222+
223+
if ($env:GITHUB_STEP_SUMMARY) {
224+
$statsContent | Out-File $env:GITHUB_STEP_SUMMARY -Encoding utf8
225+
Write-Output "Statistics written to GitHub Actions summary"
226+
}
227+
228+
Write-Output "`nSample data update complete: $totalSamples total samples`n"
229+
foreach ($stat in $statsByRepo) {
230+
Write-Output " $($stat.Name): $($stat.Count)"
231+
}
232+
233+
exit 0
189234

0 commit comments

Comments
 (0)