@@ -2,35 +2,77 @@ name: Content Sync
22
33on :
44 push :
5- branches :
6- - main
7- paths :
8- - ' Content/**'
5+ branches : [main]
6+ paths : ['Content/**']
7+ workflow_dispatch :
8+ schedule :
9+ - cron : ' 0 0 * * *' # Run daily at midnight UTC
910
1011jobs :
1112 sync-content :
1213 runs-on : ubuntu-latest
14+ permissions :
15+ contents : write
1316
1417 steps :
15- - name : Checkout code
16- uses : actions/checkout@v4
18+ - uses : actions/checkout@v4
1719
18- - name : Setup .NET
19- uses : actions/setup-dotnet@v4
20- with :
21- dotnet-version : ' 9.0.x'
20+ - name : Count Content Articles
21+ id : count-articles
22+ shell : pwsh
23+ run : |
24+ $count = (Get-ChildItem -Path "Content" -Recurse -File -Filter "*.md").Count
25+ "article-count=$count" >> $env:GITHUB_OUTPUT
26+
27+ - uses : actions/setup-dotnet@v4
28+ with :
29+ dotnet-version : ' 9.0.x'
2230
23- - name : Build ContentLoader
24- run : |
25- dotnet build ContentLoader/ContentLoader.csproj --configuration Release
31+ - name : Build ContentLoader
32+ run : dotnet build ContentLoader/ContentLoader.csproj --configuration Release
2633
27- - name : Upload Content
28- env :
29- AZURE_STORAGE_CONNECTION_STRING : ${{ secrets.CONTENT_STORAGE_CONNECTION_STRING }}
30- run : dotnet run --project ContentLoader/ContentLoader.csproj --configuration Release -- Content
34+ - name : Upload Content
35+ env :
36+ AZURE_STORAGE_CONNECTION_STRING : ${{ secrets.CONTENT_STORAGE_CONNECTION_STRING }}
37+ run : dotnet run --project ContentLoader/ContentLoader.csproj --configuration Release -- Content
3138
32- - name : Handle Failure
33- if : failure()
34- run : |
35- echo "Content sync failed. Check the build output and Azure Storage connection string."
36- exit 1
39+ - name : Handle Failure
40+ if : failure()
41+ run : |
42+ echo "Content sync failed. Check the build output and Azure Storage connection string."
43+ exit 1
44+
45+ - name : Update README Badges
46+ if : success()
47+ shell : pwsh
48+ run : |
49+ $date = Get-Date -Format "yyyy-MM-dd"
50+ $articleCount = "${{ steps.count-articles.outputs.article-count }}"
51+
52+ # Create badge URLs using shields.io
53+ $lastUpdateBadge = ""
54+ $articleCountBadge = ""
55+
56+ # Read current README content
57+ $readmeContent = Get-Content README.md -Raw
58+
59+ # Replace existing badges or add new ones at the top of the file
60+ $badgeSection = "${lastUpdateBadge}`n${articleCountBadge}`n"
61+
62+ if ($readmeContent -match "!\[Content Last Updated\].*`n!\[Content Articles\].*`n") {
63+ $readmeContent = $readmeContent -replace "!\[Content Last Updated\].*`n!\[Content Articles\].*`n", $badgeSection
64+ } else {
65+ $readmeContent = $badgeSection + $readmeContent
66+ }
67+
68+ # Write updated content back to README
69+ $readmeContent | Set-Content README.md -NoNewline
70+
71+ - name : Commit README Changes
72+ if : success()
73+ run : |
74+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
75+ git config --local user.name "github-actions[bot]"
76+ git add README.md
77+ git commit -m "docs: update content sync badges [skip ci]" || exit 0
78+ git push
0 commit comments