|
7 | 7 |
|
8 | 8 | concurrency: |
9 | 9 | group: competitive-matrix |
10 | | - cancel-in-progress: true |
| 10 | + # NOT cancel-in-progress, same as update-adoption-wall.yml: this job pushes a |
| 11 | + # branch, opens a PR and (for a state-only report) merges it. Cancelling it |
| 12 | + # between `git push` and `gh pr merge` leaves a pushed branch or an open PR |
| 13 | + # that nobody is looking at. A re-run queues behind the running one instead. |
| 14 | + cancel-in-progress: false |
11 | 15 |
|
12 | 16 | permissions: |
13 | 17 | contents: read |
14 | 18 |
|
| 19 | +env: |
| 20 | + # `pnpm install` runs `prepare` -> husky, which would make the unattended |
| 21 | + # `git commit` below run lint-staged. HUSKY=0 asks husky not to install the |
| 22 | + # hooks; the `--no-verify` on the bot commit is the part that does not depend |
| 23 | + # on husky honouring it. Same as update-adoption-wall.yml. |
| 24 | + HUSKY: "0" |
| 25 | + |
15 | 26 | jobs: |
16 | 27 | update-matrix: |
17 | 28 | runs-on: ubuntu-latest |
@@ -51,15 +62,126 @@ jobs: |
51 | 62 | echo "docs_changed=false" >> "$GITHUB_OUTPUT" |
52 | 63 | fi |
53 | 64 |
|
| 65 | + # The run's report, where a human can read it without a PR: the job |
| 66 | + # summary page. Reports only; it must never fail the job. |
| 67 | + - name: Publish run summary |
| 68 | + if: always() |
| 69 | + run: | |
| 70 | + SUMMARY=/tmp/matrix-summary.md |
| 71 | + # $GITHUB_STEP_SUMMARY is capped at 1 MiB and an oversized file is |
| 72 | + # discarded, not truncated. Leave headroom for the notice. |
| 73 | + LIMIT=$((1024 * 1024 - 4096)) |
| 74 | + if [ -s "$SUMMARY" ]; then |
| 75 | + head -c "$LIMIT" "$SUMMARY" >> "$GITHUB_STEP_SUMMARY" || true |
| 76 | + if [ "$(wc -c < "$SUMMARY")" -gt "$LIMIT" ]; then |
| 77 | + { |
| 78 | + echo |
| 79 | + echo "_Truncated at ${LIMIT} bytes for the job-summary cap._" |
| 80 | + } >> "$GITHUB_STEP_SUMMARY" || true |
| 81 | + fi |
| 82 | + else |
| 83 | + echo "## Competitive matrix: no summary was produced; see the \`Update competitive matrix\` step log." >> "$GITHUB_STEP_SUMMARY" || true |
| 84 | + fi |
| 85 | +
|
| 86 | + # A run whose ONLY change is the feature-watch state file is a report, not |
| 87 | + # a page edit: it lands itself through a bot PR (below), and its content |
| 88 | + # stays visible in the PR body, the job summary and the Slack digest. |
| 89 | + # Anything that touches docs/ (a homepage or migration page edit) still |
| 90 | + # goes to a review PR for a human. This step decides which path applies, |
| 91 | + # on the exact set of paths the commit stages. |
| 92 | + - name: Verify the auto-land diff is confined to the state file |
| 93 | + id: confine |
| 94 | + if: >- |
| 95 | + steps.changes.outputs.changed == 'true' && |
| 96 | + steps.changes.outputs.docs_changed == 'false' |
| 97 | + run: | |
| 98 | + STATUS=$(git status --porcelain -- docs/ scripts/competitive-watch-state.json) |
| 99 | + if [ "$STATUS" = " M scripts/competitive-watch-state.json" ]; then |
| 100 | + echo "confined=true" >> "$GITHUB_OUTPUT" |
| 101 | + echo "Only scripts/competitive-watch-state.json changed; it may auto-land." |
| 102 | + else |
| 103 | + echo "confined=false" >> "$GITHUB_OUTPUT" |
| 104 | + echo "::warning::The change is not exactly a modified scripts/competitive-watch-state.json; it goes to a review PR instead:" |
| 105 | + echo "$STATUS" |
| 106 | + fi |
| 107 | +
|
| 108 | + # The workflow token cannot land this: a PR it opens triggers no CI, and |
| 109 | + # ruleset `blorpathupap` requires an approved PR on the default branch. |
| 110 | + # copilotkit-bot (app 1108748) is a PULL-REQUEST-ONLY bypass actor on that |
| 111 | + # ruleset. This is the same app, the same pinned action, the same secret |
| 112 | + # and the same scopes that update-adoption-wall.yml and fix-drift.yml use. |
| 113 | + # Minted behind the SAME condition as the push it serves, so a run that is |
| 114 | + # not auto-landing never mints a token. The token reaches git and gh |
| 115 | + # through the environment only. |
| 116 | + - name: Mint app token |
| 117 | + id: app-token |
| 118 | + if: >- |
| 119 | + steps.changes.outputs.changed == 'true' && |
| 120 | + steps.changes.outputs.docs_changed == 'false' && |
| 121 | + steps.confine.outputs.confined == 'true' |
| 122 | + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 |
| 123 | + with: |
| 124 | + app-id: "1108748" |
| 125 | + private-key: ${{ secrets.DEVOPS_BOT_PRIVATE_KEY }} |
| 126 | + permission-contents: write |
| 127 | + permission-pull-requests: write |
| 128 | + |
| 129 | + - name: Auto-land via bot PR |
| 130 | + id: land |
| 131 | + if: >- |
| 132 | + steps.changes.outputs.changed == 'true' && |
| 133 | + steps.changes.outputs.docs_changed == 'false' && |
| 134 | + steps.confine.outputs.confined == 'true' |
| 135 | + env: |
| 136 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 137 | + run: | |
| 138 | + AUTH=$(printf 'x-access-token:%s' "$GH_TOKEN" | base64 | tr -d '\n') |
| 139 | + echo "::add-mask::${AUTH}" |
| 140 | + export GIT_CONFIG_COUNT=1 |
| 141 | + export GIT_CONFIG_KEY_0="http.https://github.com/.extraheader" |
| 142 | + export GIT_CONFIG_VALUE_0="AUTHORIZATION: basic ${AUTH}" |
| 143 | + git config user.name "copilotkit-bot[bot]" |
| 144 | + git config user.email "194550712+copilotkit-bot[bot]@users.noreply.github.com" |
| 145 | + # Run id + attempt: a same-day re-run must not collide with the first |
| 146 | + # run's branch. |
| 147 | + BRANCH="bot/competitive-watch-$(date -u +%Y%m%d)-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" |
| 148 | + git checkout -b "$BRANCH" |
| 149 | + # ONE NAMED FILE: the bot merges the state file and nothing else. |
| 150 | + git add -- scripts/competitive-watch-state.json |
| 151 | + # --no-verify: see the HUSKY note in the workflow env block. |
| 152 | + git commit --no-verify -m "chore: update competitor feature-watch state" |
| 153 | + git push -u origin "$BRANCH" |
| 154 | + PR_URL=$(gh pr create \ |
| 155 | + --title "chore: competitor feature-watch report" \ |
| 156 | + --body-file /tmp/matrix-summary.md \ |
| 157 | + --base "${GITHUB_REF_NAME}" \ |
| 158 | + --head "$BRANCH") |
| 159 | + echo "url=${PR_URL}" >> "$GITHUB_OUTPUT" |
| 160 | + # --admin merges now, through the bot's pull-request bypass (--auto |
| 161 | + # would wait forever for the approval the ruleset requires). --merge |
| 162 | + # because the ruleset allows merge commits only. A real conflict |
| 163 | + # fails here and leaves the PR open for a human. |
| 164 | + if ! gh pr merge "$BRANCH" --merge --admin; then |
| 165 | + echo "::error::Opened the feature-watch PR for ${BRANCH} but could not merge it into ${GITHUB_REF_NAME}; it is left open for a human." |
| 166 | + exit 1 |
| 167 | + fi |
| 168 | + echo "merged=true" >> "$GITHUB_OUTPUT" |
| 169 | +
|
| 170 | + # A docs/ change, or a state change that is not confined, goes to a |
| 171 | + # review PR on the workflow token, as before. |
54 | 172 | - name: Configure git credentials |
55 | | - if: steps.changes.outputs.changed == 'true' |
| 173 | + if: >- |
| 174 | + steps.changes.outputs.changed == 'true' && |
| 175 | + steps.confine.outputs.confined != 'true' |
56 | 176 | run: | |
57 | 177 | git config --local --unset-all http.https://github.com/.extraheader || true |
58 | 178 | git config --local url."https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/" |
59 | 179 |
|
60 | 180 | - name: Create PR |
61 | 181 | id: pr |
62 | | - if: steps.changes.outputs.changed == 'true' |
| 182 | + if: >- |
| 183 | + steps.changes.outputs.changed == 'true' && |
| 184 | + steps.confine.outputs.confined != 'true' |
63 | 185 | env: |
64 | 186 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
65 | 187 | RUN_ID: ${{ github.run_id }} |
@@ -91,14 +213,20 @@ jobs: |
91 | 213 | SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
92 | 214 | CHANGED: ${{ steps.changes.outputs.changed }} |
93 | 215 | DOCS_CHANGED: ${{ steps.changes.outputs.docs_changed }} |
94 | | - PR_URL: ${{ steps.pr.outputs.url }} |
| 216 | + PR_URL: ${{ steps.land.outputs.url || steps.pr.outputs.url }} |
| 217 | + LANDED: ${{ steps.land.outputs.merged }} |
95 | 218 | JOB_STATUS: ${{ job.status }} |
96 | 219 | RUN_ID: ${{ github.run_id }} |
97 | 220 | run: | |
98 | 221 | if [ -z "$SLACK_WEBHOOK" ]; then echo "SLACK_WEBHOOK not set, skipping"; exit 0; fi |
99 | 222 | # "PR created" only when the PR step really produced a URL; a failed |
100 | | - # Create PR falls through to the failure message. |
101 | | - if [ "$CHANGED" = "true" ] && [ -n "$PR_URL" ] && [ "$DOCS_CHANGED" = "true" ]; then |
| 223 | + # Create PR falls through to the failure message. "Merged" only when |
| 224 | + # the bot PR's merge really succeeded; an unmerged bot PR is left open |
| 225 | + # and reported as a PR to review. |
| 226 | + if [ "$LANDED" = "true" ] && [ -n "$PR_URL" ]; then |
| 227 | + EMOJI="🔎" |
| 228 | + MSG="*Competitor feature-watch report* — state merged into main via a bot PR; check the changes below. <https://github.com/CopilotKit/aimock/actions/runs/${RUN_ID}|View run>" |
| 229 | + elif [ "$CHANGED" = "true" ] && [ -n "$PR_URL" ] && [ "$DOCS_CHANGED" = "true" ]; then |
102 | 230 | EMOJI="📊" |
103 | 231 | MSG="*Competitive matrix changes detected* — PR created with updated migration pages. <https://github.com/CopilotKit/aimock/actions/runs/${RUN_ID}|View run>" |
104 | 232 | elif [ "$CHANGED" = "true" ] && [ -n "$PR_URL" ]; then |
|
0 commit comments