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