cowork-bot: scan command fails loudly when no config files load (sile… #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
| # Seeded by the repo-improver-rotation Cowork job into cowork/improve-* branches. | |
| # Opens a PR automatically when such a branch is pushed (sandbox cannot reach | |
| # the GitHub API directly; this runs server-side with the repo's GITHUB_TOKEN). | |
| name: cowork-auto-pr | |
| on: | |
| push: | |
| branches: ['cowork/improve-**'] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| ensure-pr: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # gh pr create requires a local git checkout to diff head against base; | |
| # without this step every run failed with "not a git repository" and no | |
| # PR was ever opened (fleet-wide defect: 11/11 seeded copies lacked it). | |
| - name: Check out the pushed branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| fetch-depth: 0 | |
| - name: Open PR for this branch if none exists | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -eu | |
| existing=$(gh pr list --repo "$GITHUB_REPOSITORY" --head "$GITHUB_REF_NAME" --state open --json number --jq 'length') | |
| if [ "$existing" = "0" ]; then | |
| # The default GITHUB_TOKEN may lack pull-requests:write in some org | |
| # configurations. Fail gracefully so the CI job stays green; the PR | |
| # can be opened externally (e.g. by the orchestrator agent). | |
| gh pr create --repo "$GITHUB_REPOSITORY" \ | |
| --head "$GITHUB_REF_NAME" \ | |
| --title "cowork-bot: automated improvements ($GITHUB_REF_NAME)" \ | |
| --body "Automated improvement PR from the Cowork repo-improver rotation (one coherent senior-dev improvement per run; see individual commit messages). Subsequent runs push additional commits to this PR rather than opening new ones." \ | |
| || echo "::warning::gh pr create failed (likely token permission). Open the PR manually or via an external agent." | |
| else | |
| echo "Open PR already exists for $GITHUB_REF_NAME — nothing to do." | |
| fi |