|
| 1 | +name: Monthly Notebook Keyword Snapshots |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 3 1 * *' # 1st of each month at 03:00 UTC |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + collection_id: |
| 9 | + description: 'Single collection ID to refresh (empty = all)' |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + month: |
| 13 | + description: 'Override month (YYYY-MM, empty = current month)' |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: notebook-keyword-snapshots |
| 22 | + cancel-in-progress: false |
| 23 | + |
| 24 | +jobs: |
| 25 | + refresh: |
| 26 | + name: Refresh keyword snapshots |
| 27 | + runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 60 |
| 29 | + env: |
| 30 | + API_URL: ${{ vars.NOTEBOOK_API_URL || 'https://gruenerator.eu' }} |
| 31 | + steps: |
| 32 | + - name: Build request payload |
| 33 | + id: payload |
| 34 | + run: | |
| 35 | + PAYLOAD='{}' |
| 36 | + if [ -n "${{ inputs.collection_id }}" ]; then |
| 37 | + PAYLOAD=$(jq -n --arg id "${{ inputs.collection_id }}" '{collectionId: $id}') |
| 38 | + fi |
| 39 | + if [ -n "${{ inputs.month }}" ]; then |
| 40 | + PAYLOAD=$(echo "$PAYLOAD" | jq --arg m "${{ inputs.month }}" '. + {month: $m}') |
| 41 | + fi |
| 42 | + echo "payload=$PAYLOAD" >> "$GITHUB_OUTPUT" |
| 43 | + echo "Payload: $PAYLOAD" |
| 44 | +
|
| 45 | + - name: Trigger snapshot refresh |
| 46 | + id: refresh |
| 47 | + continue-on-error: true |
| 48 | + run: | |
| 49 | + echo "POST $API_URL/api/internal/notebook/refresh-keywords" |
| 50 | + RESULT=$(curl -sfS -X POST "$API_URL/api/internal/notebook/refresh-keywords" \ |
| 51 | + -H "x-admin-token: ${{ secrets.ADMIN_TOKEN }}" \ |
| 52 | + -H "Content-Type: application/json" \ |
| 53 | + -d '${{ steps.payload.outputs.payload }}' \ |
| 54 | + --max-time 3000) |
| 55 | +
|
| 56 | + echo "$RESULT" | jq . |
| 57 | + echo "result<<EOF" >> "$GITHUB_OUTPUT" |
| 58 | + echo "$RESULT" >> "$GITHUB_OUTPUT" |
| 59 | + echo "EOF" >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + - name: Generate summary |
| 62 | + if: always() |
| 63 | + run: | |
| 64 | + RESULT='${{ steps.refresh.outputs.result }}' |
| 65 | + RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 66 | +
|
| 67 | + if [ -z "$RESULT" ] || [ "$RESULT" = "" ]; then |
| 68 | + { |
| 69 | + echo "## :x: Snapshot Refresh — No Result" |
| 70 | + echo "" |
| 71 | + echo "Service did not return a result. Check [workflow logs]($RUN_URL)." |
| 72 | + } >> "$GITHUB_STEP_SUMMARY" |
| 73 | + exit 0 |
| 74 | + fi |
| 75 | +
|
| 76 | + COUNT=$(echo "$RESULT" | jq -r '.count // (.results | length)') |
| 77 | + SUCCESS=$(echo "$RESULT" | jq -r '.success') |
| 78 | +
|
| 79 | + if [ "$SUCCESS" = "true" ]; then |
| 80 | + ICON=":white_check_mark:" |
| 81 | + else |
| 82 | + ICON=":x:" |
| 83 | + fi |
| 84 | +
|
| 85 | + { |
| 86 | + echo "## $ICON Notebook Keyword Snapshots" |
| 87 | + echo "" |
| 88 | + echo "**Date:** $(date -u '+%d.%m.%Y %H:%M UTC')" |
| 89 | + echo "**Run:** [${{ github.run_id }}]($RUN_URL)" |
| 90 | + echo "**Collections refreshed:** $COUNT" |
| 91 | + echo "" |
| 92 | + echo "| Collection | Keywords | Sample | Total docs | Duration (ms) |" |
| 93 | + echo "|------------|---------:|-------:|-----------:|--------------:|" |
| 94 | + echo "$RESULT" | jq -r '.results[] | "| \(.collectionId) | \(.keywordCount) | \(.sampleSize) | \(.totalDocuments) | \(.durationMs) |"' |
| 95 | + } >> "$GITHUB_STEP_SUMMARY" |
| 96 | +
|
| 97 | + - name: Fail if refresh errored |
| 98 | + if: steps.refresh.outcome == 'failure' |
| 99 | + run: exit 1 |
0 commit comments