-
Notifications
You must be signed in to change notification settings - Fork 3
102 lines (84 loc) · 3.74 KB
/
content-sync.yml
File metadata and controls
102 lines (84 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Content Sync
on:
push:
branches: [main]
paths: ['Content/**']
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Run daily at midnight UTC
jobs:
sync-content:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Count Content Articles
id: count-articles
shell: pwsh
run: |
$count = (Get-ChildItem -Path "Content" -Recurse -File -Filter "*.md").Count
"article-count=$count" >> $env:GITHUB_OUTPUT
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Build ContentLoader
run: dotnet build ContentLoader/ContentLoader.csproj --configuration Release
- name: Upload Content
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.CONTENT_STORAGE_CONNECTION_STRING }}
run: dotnet run --project ContentLoader/ContentLoader.csproj --configuration Release -- Content
- name: Refresh Web App Cache
if: success()
env:
CACHE_REFRESH_API_KEY: ${{ secrets.CACHE_REFRESH_API_KEY }}
run: |
echo "Refreshing web application cache..."
# Wait a moment for the content to be fully uploaded
sleep 5
# Call the cache refresh endpoint with API key authentication
response=$(curl -s -w "%{http_code}" -X POST "https://copilotthatjawn.com/api/cache/refresh" \
-H "X-API-Key: $CACHE_REFRESH_API_KEY" \
-o /tmp/cache_response.json)
if [ "$response" = "200" ]; then
echo "Cache refresh successful"
cat /tmp/cache_response.json
else
echo "Cache refresh failed with HTTP status: $response"
cat /tmp/cache_response.json || echo "No response body"
# Don't fail the workflow if cache refresh fails - it's not critical
echo "Continuing workflow despite cache refresh failure..."
fi
- name: Handle Failure
if: failure()
run: |
echo "Content sync failed. Check the build output and Azure Storage connection string."
exit 1
- name: Update README Badges
if: success()
shell: pwsh
run: |
$date = Get-Date -Format "yyyy--MM--dd"
$articleCount = "${{ steps.count-articles.outputs.article-count }}"
# Create badge URLs using shields.io
$lastUpdateBadge = ""
$articleCountBadge = ""
# Read current README content
$readmeContent = Get-Content README.md -Raw
# Replace existing badges or add new ones at the top of the file
$badgeSection = "${lastUpdateBadge}`n${articleCountBadge}`n"
if ($readmeContent -match "!\[Content Last Updated\].*`n!\[Content Articles\].*`n") {
$readmeContent = $readmeContent -replace "!\[Content Last Updated\].*`n!\[Content Articles\].*`n", $badgeSection
} else {
$readmeContent = $badgeSection + $readmeContent
}
# Write updated content back to README
$readmeContent | Set-Content README.md -NoNewline
- name: Commit README Changes
if: success()
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add README.md
git commit -m "docs: update content sync badges [skip ci]" || exit 0
git push