Model Discovery #773
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: Model Discovery | |
| on: | |
| schedule: | |
| - cron: "0 * * * *" | |
| workflow_dispatch: {} | |
| jobs: | |
| discover: | |
| name: Discover Model Events | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| outputs: | |
| actionable_issue_numbers: ${{ steps.discover.outputs.actionable_issue_numbers }} | |
| actionable_issue_count: ${{ steps.discover.outputs.actionable_issue_count }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| cache: npm | |
| - name: Install and build | |
| run: npm ci && npm run build && npm install -g . | |
| - name: Generate GitHub App token | |
| id: app_token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.POE_CODE_AGENT_APP_ID }} | |
| private-key: ${{ secrets.POE_CODE_AGENT_PRIVATE_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| - name: Discover models | |
| id: discover | |
| env: | |
| POE_API_KEY: ${{ secrets.POE_API_KEY }} | |
| GITHUB_TOKEN: ${{ steps.app_token.outputs.token }} | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| PROJECT_NUMBER: "3" | |
| PROJECT_OWNER: "poe-platform" | |
| run: node scripts/workflows/discover-models.mjs | |
| resolve: | |
| name: Resolve Actionable Model Issues | |
| needs: [discover] | |
| if: ${{ needs.discover.outputs.actionable_issue_count != '0' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| issue_number: ${{ fromJson(needs.discover.outputs.actionable_issue_numbers || '[]') }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| concurrency: | |
| group: model-discovery-issue-${{ matrix.issue_number }} | |
| cancel-in-progress: true | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Generate GitHub App token | |
| id: app_token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.POE_CODE_AGENT_APP_ID }} | |
| private-key: ${{ secrets.POE_CODE_AGENT_PRIVATE_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| cache: npm | |
| - name: Install and build | |
| run: npm ci && npm run build && npm install -g . | |
| - name: Configure agent | |
| env: | |
| POE_API_KEY: ${{ secrets.POE_API_KEY }} | |
| run: | | |
| poe-code login --api-key "${POE_API_KEY}" | |
| poe-code install claude-code --yes | |
| poe-code configure claude-code --yes | |
| - name: Configure git author | |
| run: | | |
| git config user.name "Poe Code Agent" | |
| git config user.email "developers@poe.com" | |
| - name: Fetch issue details | |
| id: issue | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ steps.app_token.outputs.token }} | |
| script: | | |
| const issueNumber = Number("${{ matrix.issue_number }}"); | |
| const issue = await github.rest.issues.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber | |
| }); | |
| core.setOutput("title", issue.data.title ?? ""); | |
| core.setOutput("body", issue.data.body ?? ""); | |
| - name: Build prompt and spawn agent | |
| env: | |
| ISSUE_NUMBER: ${{ matrix.issue_number }} | |
| GITHUB_TOKEN: ${{ steps.app_token.outputs.token }} | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| run: node scripts/workflows/resolve-model-issue.cjs | |
| - name: Resolve issue PR branch | |
| id: issue_branch | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ steps.app_token.outputs.token }} | |
| script: | | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const issueNumber = Number("${{ matrix.issue_number }}"); | |
| const issueKey = `issue-${issueNumber}`; | |
| const preferredBranch = `agent/${issueKey}`; | |
| const candidateBranches = [ | |
| preferredBranch, | |
| `agent/comment/${issueKey}`, | |
| `agent/auto-resolve/${issueKey}` | |
| ]; | |
| for (const branch of candidateBranches) { | |
| const response = await github.rest.pulls.list({ | |
| owner, | |
| repo, | |
| state: "open", | |
| head: `${owner}:${branch}`, | |
| per_page: 1 | |
| }); | |
| const pr = response.data[0]; | |
| if (!pr) { | |
| continue; | |
| } | |
| core.info(`Reusing open PR #${pr.number} (${branch})`); | |
| core.setOutput("branch", branch); | |
| core.setOutput("pr_number", String(pr.number)); | |
| return; | |
| } | |
| core.info(`No open PR found for issue #${issueNumber}; using ${preferredBranch}`); | |
| core.setOutput("branch", preferredBranch); | |
| core.setOutput("pr_number", ""); | |
| - name: Generate PR metadata | |
| id: generated_pr_metadata | |
| continue-on-error: true | |
| env: | |
| ISSUE_NUMBER: ${{ matrix.issue_number }} | |
| ISSUE_TITLE: ${{ steps.issue.outputs.title }} | |
| ISSUE_BODY: ${{ steps.issue.outputs.body }} | |
| run: node scripts/workflows/generate-pr-metadata.cjs | |
| - name: Resolve PR metadata | |
| id: pr_metadata | |
| uses: actions/github-script@v7 | |
| env: | |
| GENERATED_TITLE: ${{ steps.generated_pr_metadata.outputs.title }} | |
| GENERATED_BODY: ${{ steps.generated_pr_metadata.outputs.body }} | |
| with: | |
| script: | | |
| const issueNumber = Number("${{ matrix.issue_number }}"); | |
| const defaultTitle = `fix: resolve issue #${issueNumber}`; | |
| const defaultBody = [ | |
| `Resolves #${issueNumber}`, | |
| "", | |
| "Auto-resolved by model-discovery workflow." | |
| ].join("\n"); | |
| const title = (process.env.GENERATED_TITLE ?? "").trim() || defaultTitle; | |
| const body = (process.env.GENERATED_BODY ?? "").trim() || defaultBody; | |
| core.setOutput("title", title); | |
| core.setOutput("body", body); | |
| - name: Create pull request if changes exist | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| token: ${{ steps.app_token.outputs.token }} | |
| branch: ${{ steps.issue_branch.outputs.branch }} | |
| title: ${{ steps.pr_metadata.outputs.title }} | |
| body: ${{ steps.pr_metadata.outputs.body }} | |
| commit-message: "fix: resolve issue #${{ matrix.issue_number }}" | |
| delete-branch: true |