Weekly PatternFly Analytics Report #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Weekly PatternFly Analytics Report | |
| on: | |
| schedule: | |
| # Every Monday at 06:00 UTC | |
| - cron: '0 6 * * 1' | |
| workflow_dispatch: | |
| jobs: | |
| collect-and-report: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 120 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install Node dependencies | |
| run: npm install | |
| - name: Install Python dependencies | |
| run: pip install -r requirements.txt | |
| - name: Collect PatternFly stats | |
| run: node src/static-analysis/cli.js collect -j -d | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate Excel report | |
| run: python3 to_xls.py | |
| - name: Get report date | |
| id: date | |
| run: echo "date=$(date -u '+%Y-%m-%d')" >> "$GITHUB_OUTPUT" | |
| - name: Create zip archive | |
| run: | | |
| REPORT_DATE="${{ steps.date.outputs.date }}" | |
| zip -r "pf-analytics-${REPORT_DATE}.zip" \ | |
| "reports/${REPORT_DATE}/pf_report.xlsx" \ | |
| "stats-static/${REPORT_DATE}/" | |
| - name: Upload to Confluence | |
| if: ${{ env.HAS_CONFLUENCE == 'true' }} | |
| env: | |
| HAS_CONFLUENCE: ${{ secrets.CONFLUENCE_API_TOKEN != '' }} | |
| CONFLUENCE_EMAIL: ${{ secrets.CONFLUENCE_EMAIL }} | |
| CONFLUENCE_API_TOKEN: ${{ secrets.CONFLUENCE_API_TOKEN }} | |
| run: | | |
| REPORT_DATE="${{ steps.date.outputs.date }}" | |
| ZIP_NAME="pf-analytics-${REPORT_DATE}.zip" | |
| CONFLUENCE_BASE="https://redhat.atlassian.net/wiki" | |
| CONFLUENCE_PAGE_ID="385791717" | |
| # Upload zip as attachment | |
| HTTP_CODE=$(curl -s -o /tmp/upload_response.json -w "%{http_code}" \ | |
| -X PUT \ | |
| -u "${CONFLUENCE_EMAIL}:${CONFLUENCE_API_TOKEN}" \ | |
| -H "X-Atlassian-Token: nocheck" \ | |
| -F "file=@${ZIP_NAME}" \ | |
| "${CONFLUENCE_BASE}/rest/api/content/${CONFLUENCE_PAGE_ID}/child/attachment") | |
| if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then | |
| echo "✅ Confluence upload successful (HTTP ${HTTP_CODE})" | |
| else | |
| echo "❌ Confluence upload failed (HTTP ${HTTP_CODE})" | |
| cat /tmp/upload_response.json | |
| exit 1 | |
| fi | |
| - name: Update Confluence page table | |
| if: ${{ env.HAS_CONFLUENCE == 'true' }} | |
| env: | |
| HAS_CONFLUENCE: ${{ secrets.CONFLUENCE_API_TOKEN != '' }} | |
| CONFLUENCE_EMAIL: ${{ secrets.CONFLUENCE_EMAIL }} | |
| CONFLUENCE_API_TOKEN: ${{ secrets.CONFLUENCE_API_TOKEN }} | |
| run: | | |
| REPORT_DATE="${{ steps.date.outputs.date }}" | |
| ZIP_NAME="pf-analytics-${REPORT_DATE}.zip" | |
| CONFLUENCE_BASE="https://redhat.atlassian.net/wiki" | |
| CONFLUENCE_PAGE_ID="385791717" | |
| export CONFLUENCE_BASE CONFLUENCE_PAGE_ID REPORT_DATE ZIP_NAME | |
| python3 -c " | |
| import json, urllib.request, os, sys, base64 | |
| base = os.environ['CONFLUENCE_BASE'] | |
| page_id = os.environ['CONFLUENCE_PAGE_ID'] | |
| date = os.environ['REPORT_DATE'] | |
| zip_name = os.environ['ZIP_NAME'] | |
| email = os.environ['CONFLUENCE_EMAIL'] | |
| token = os.environ['CONFLUENCE_API_TOKEN'] | |
| auth = base64.b64encode(f'{email}:{token}'.encode()).decode() | |
| headers = {'Authorization': f'Basic {auth}', 'Content-Type': 'application/json'} | |
| req = urllib.request.Request(f'{base}/rest/api/content/{page_id}?expand=body.storage,version', headers=headers) | |
| with urllib.request.urlopen(req) as resp: | |
| data = json.load(resp) | |
| version = data['version']['number'] | |
| body = data['body']['storage']['value'] | |
| marker = '</tbody></table>' | |
| if marker not in body: | |
| print('WARNING: Page does not contain expected table structure - skipping table update') | |
| sys.exit(0) | |
| new_row = ( | |
| f'<tr><td><p>{date}</p></td>' | |
| f'<td><p><a href=\"/wiki/download/attachments/{page_id}/{zip_name}\">{zip_name}</a></p></td></tr>' | |
| ) | |
| body = body.replace(marker, new_row + marker) | |
| payload = json.dumps({ | |
| 'version': {'number': version + 1}, | |
| 'type': 'page', | |
| 'title': data['title'], | |
| 'body': {'storage': {'value': body, 'representation': 'storage'}} | |
| }).encode() | |
| req = urllib.request.Request(f'{base}/rest/api/content/{page_id}', data=payload, headers=headers, method='PUT') | |
| with urllib.request.urlopen(req) as resp: | |
| print(f'Download link added to page (HTTP {resp.status})') | |
| " | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: pf-analytics-${{ steps.date.outputs.date }} | |
| path: | | |
| reports/${{ steps.date.outputs.date }}/pf_report.xlsx | |
| stats-static/${{ steps.date.outputs.date }}/ | |
| retention-days: 90 |