|
| 1 | +name: Hourly Automation Summary |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 * * * *' # hourly at minute 0 |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + summary: |
| 10 | + name: Post hourly summary for automation PR |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Install jq |
| 14 | + run: | |
| 15 | + sudo apt-get update -y |
| 16 | + sudo apt-get install -y jq |
| 17 | +
|
| 18 | + - name: Build summary and post comment to PR |
| 19 | + env: |
| 20 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + BRANCH: automation/bot-auto-pr |
| 22 | + API: https://api.github.com/repos/${{ github.repository }} |
| 23 | + run: | |
| 24 | + set -euo pipefail |
| 25 | + owner_repo="${GITHUB_REPOSITORY}" |
| 26 | + owner="${owner_repo%%/*}" |
| 27 | +
|
| 28 | + echo "Looking up open PR for head ${owner}:${BRANCH}..." |
| 29 | + prs=$(curl -sS -H "Authorization: token ${GITHUB_TOKEN}" "${API}/pulls?state=open&head=${owner}:${BRANCH}") |
| 30 | + pr_number=$(echo "$prs" | jq -r '.[0].number // empty') |
| 31 | + if [ -z "$pr_number" ]; then |
| 32 | + echo "No open PR found for branch ${BRANCH}. Nothing to post." |
| 33 | + exit 0 |
| 34 | + fi |
| 35 | +
|
| 36 | + echo "Found PR #${pr_number} — gathering workflow runs..." |
| 37 | + runs=$(curl -sS -H "Authorization: token ${GITHUB_TOKEN}" "${API}/actions/runs?branch=${BRANCH}&per_page=50") |
| 38 | + total_runs=$(echo "$runs" | jq '.workflow_runs | length') |
| 39 | + in_progress=$(echo "$runs" | jq '[.workflow_runs[] | select(.status=="in_progress")] | length') |
| 40 | + completed=$(echo "$runs" | jq '[.workflow_runs[] | select(.status=="completed")] | length') |
| 41 | + failed=$(echo "$runs" | jq '[.workflow_runs[] | select(.conclusion=="failure")] | length') |
| 42 | + success=$(echo "$runs" | jq '[.workflow_runs[] | select(.conclusion=="success")] | length') |
| 43 | + pending=$(echo "$runs" | jq '[.workflow_runs[] | select(.status=="queued")] | length') |
| 44 | +
|
| 45 | + latest_codeql=$(echo "$runs" | jq -r '.workflow_runs[] | select(.name=="CodeQL") | .conclusion' | head -n1 || echo "none") |
| 46 | +
|
| 47 | + now=$(date -u +"%Y-%m-%d %H:%M UTC") |
| 48 | + body="Hourly Automation Summary — ${now}\n\n" |
| 49 | + body+="PR: #${pr_number}\n" |
| 50 | + body+="Branch: ${BRANCH}\n\n" |
| 51 | + body+="Workflow runs (recent 50): total=${total_runs}, completed=${completed}, in_progress=${in_progress}, queued=${pending}\n" |
| 52 | + body+="Success: ${success}, Failed: ${failed}\n\n" |
| 53 | + body+="Latest CodeQL conclusion: ${latest_codeql}\n\n" |
| 54 | + body+="_This comment was posted automatically by the repository automation workflow._" |
| 55 | +
|
| 56 | + echo "Posting summary comment to PR #${pr_number}..." |
| 57 | + post=$(jq -n --arg body "$body" '{body: $body}') |
| 58 | + curl -sS -X POST -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: application/json" "${API}/issues/${pr_number}/comments" -d "$post" >/dev/null |
| 59 | + echo "Posted." |
0 commit comments