WRITEME - Scheduled Copilot README Review #40
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: WRITEME - Scheduled Copilot README Review | |
| on: | |
| schedule: | |
| # Runs at 17:00 UTC every Monday (1) and Thursday (4) | |
| - cron: '0 17 * * 1,4' | |
| # Optional manual trigger if you ever want to run it on-demand | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: write # Allow Copilot agent to create a branch/PR | |
| pull-requests: write # Allow PR operations | |
| jobs: | |
| create-copilot-job: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Read prompt file | |
| id: prompt | |
| run: | | |
| set -euo pipefail | |
| FILE=".github/workflows/writeme/prompt.md" | |
| if [ ! -f "$FILE" ]; then | |
| echo "Prompt file not found: $FILE" >&2 | |
| exit 1 | |
| fi | |
| # Convert entire file to a JSON string (properly escaped) | |
| PROMPT_JSON=$(jq -Rs . < "$FILE") | |
| echo "prompt=$PROMPT_JSON" >> "$GITHUB_OUTPUT" | |
| - name: Submit Copilot agent job | |
| id: submit | |
| env: | |
| TOKEN: ${{ secrets.COPILOT_PAT }} | |
| RAW_PROMPT: ${{ steps.prompt.outputs.prompt }} | |
| run: | | |
| set -euo pipefail | |
| # Derive base branch (fallback to main if not present in event payload) | |
| BASE_BRANCH="${{ github.event.repository.default_branch }}" | |
| if [ -z "$BASE_BRANCH" ]; then | |
| BASE_BRANCH="main" | |
| fi | |
| # RAW_PROMPT is already a quoted JSON string; unwrap safely via jq later | |
| BODY=$(jq -n --arg prompt "$RAW_PROMPT" --arg base "$BASE_BRANCH" ' { | |
| problem_statement: ($prompt | fromjson), | |
| event_type: "scheduled-workflow", | |
| pull_request: { | |
| title: "README Accuracy Review & Minimal Update", | |
| base_ref: $base, | |
| head_ref: null | |
| } | |
| }') | |
| echo "Request body:" >&2 | |
| echo "$BODY" | jq . >&2 || echo "$BODY" >&2 | |
| RESP=$(curl -sS -w "\nHTTP_STATUS:%{http_code}" -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -H "Copilot-Integration-Id: copilot-github-actions" -H "User-Agent: scheduled-copilot-workflow" -H "Accept: application/json" https://api.githubcopilot.com/agents/swe/jobs/intellectronica/ruler -d "$BODY") | |
| # Extract status code and response body | |
| RESPONSE_BODY=$(echo "$RESP" | sed -n '1,/HTTP_STATUS:/p' | sed '$d') | |
| STATUS_CODE=$(echo "$RESP" | grep "HTTP_STATUS:" | cut -d: -f2) | |
| echo "HTTP Status Code: $STATUS_CODE" >&2 | |
| echo "Response Body: $RESPONSE_BODY" >&2 | |
| # Check if response is just "Unauthorized" | |
| if [ "$RESPONSE_BODY" = "Unauthorized" ]; then | |
| echo "Authentication failed: Token may be invalid or missing required scopes" >&2 | |
| exit 1 | |
| fi | |
| JOB_ID=$(echo "$RESPONSE_BODY" | jq -r '.job_id // empty') | |
| STATE=$(echo "$RESPONSE_BODY" | jq -r '.status // empty') | |
| SESSION_URL=$(echo "$RESPONSE_BODY" | jq -r '.session_id // empty') | |
| PR_URL=$(echo "$RESPONSE_BODY" | jq -r '.pull_request.html_url // empty') | |
| if [ -z "$JOB_ID" ]; then | |
| echo "Failed to create Copilot agent job" >&2 | |
| exit 1 | |
| fi | |
| echo "job_id=$JOB_ID" >> "$GITHUB_OUTPUT" | |
| echo "job_state=$STATE" >> "$GITHUB_OUTPUT" | |
| echo "session_url=$SESSION_URL" >> "$GITHUB_OUTPUT" | |
| echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT" | |
| - name: Job summary | |
| run: | | |
| { | |
| echo "### Copilot Agent Job Created"; | |
| echo "* Job ID: ${{ steps.submit.outputs.job_id }}"; | |
| echo "* State: ${{ steps.submit.outputs.job_state }}"; | |
| if [ -n "${{ steps.submit.outputs.session_url }}" ]; then | |
| echo "* Session: ${{ steps.submit.outputs.session_url }}"; | |
| fi | |
| if [ -n "${{ steps.submit.outputs.pr_url }}" ] && [ "${{ steps.submit.outputs.pr_url }}" != "null" ]; then | |
| echo "* PR (if opened yet): ${{ steps.submit.outputs.pr_url }}"; | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" |