fix(blog): use GH_PAT for publish workflow#691
Conversation
GITHUB_TOKEN lacks admin permissions to merge PRs that require approving reviews. Use GH_PAT (already available as repo secret) for both checkout and PR merge. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5fb26bc to
1eb99e4
Compare
Greptile SummaryThis PR fixes the blog publish workflow by replacing a direct Key changes:
Issue found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant WD as workflow_dispatch
participant GHA as GitHub Actions
participant Repo as Repository
participant GH as gh CLI (GH_PAT)
WD->>GHA: trigger (optional slug)
GHA->>Repo: checkout develop (GH_PAT)
GHA->>Repo: resolve article path
alt article found & is draft
GHA->>Repo: update status draft→published
GHA->>Repo: git checkout -b blog/publish-{slug}
GHA->>Repo: git push origin blog/publish-{slug}
GHA->>GH: gh pr create --base develop --head blog/publish-{slug}
GH-->>GHA: PR_URL
GHA->>GH: gh pr merge PR_URL --squash --admin --delete-branch
GH-->>Repo: squash-merged into develop, branch deleted
else article already published
GHA->>GHA: exit 0 (no outputs set)
Note over GHA: "Create and merge PR" step fires anyway<br/>(bug: condition checks wrong output)
end
Prompt To Fix All With AIThis is a comment left during a code review.
Path: .github/workflows/blog-publish.yml
Line: 93-94
Comment:
**Wrong condition gate for "Create and merge PR" step**
The condition `if: steps.resolve.outputs.article != ''` does not account for the case where the "Publish article" step exits early with `exit 0` (e.g. when the article is already published — see line 67-68). In that case `steps.publish.outputs.branch` is never set, so `$BRANCH` and `$TITLE` are empty strings, and `gh pr create --head ""` will fail with an error.
The condition should reference the `publish` step's outputs instead:
```suggestion
- name: Create and merge PR
if: steps.publish.outputs.branch != ''
```
This ensures the step only runs when the publish step actually created a branch and committed the article.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: .github/workflows/blog-publish.yml
Line: 87
Comment:
**Orphaned branch on downstream failure**
If `gh pr create` or `gh pr merge` (in the next step) fails, the branch `blog/publish-${SLUG}` will persist in the remote repository. A subsequent re-run for the same article will hit a `"branch already exists"` error on `git push origin "$BRANCH"`.
Consider adding a cleanup step that deletes the remote branch on failure, or add a `--force` push / branch-existence check:
```bash
# Before creating the branch, delete any existing remote ref
git push origin ":refs/heads/$BRANCH" 2>/dev/null || true
git checkout -b "$BRANCH"
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 1eb99e4 |
| - name: Create and merge PR | ||
| if: steps.resolve.outputs.article != '' |
There was a problem hiding this comment.
Wrong condition gate for "Create and merge PR" step
The condition if: steps.resolve.outputs.article != '' does not account for the case where the "Publish article" step exits early with exit 0 (e.g. when the article is already published — see line 67-68). In that case steps.publish.outputs.branch is never set, so $BRANCH and $TITLE are empty strings, and gh pr create --head "" will fail with an error.
The condition should reference the publish step's outputs instead:
| - name: Create and merge PR | |
| if: steps.resolve.outputs.article != '' | |
| - name: Create and merge PR | |
| if: steps.publish.outputs.branch != '' |
This ensures the step only runs when the publish step actually created a branch and committed the article.
Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/blog-publish.yml
Line: 93-94
Comment:
**Wrong condition gate for "Create and merge PR" step**
The condition `if: steps.resolve.outputs.article != ''` does not account for the case where the "Publish article" step exits early with `exit 0` (e.g. when the article is already published — see line 67-68). In that case `steps.publish.outputs.branch` is never set, so `$BRANCH` and `$TITLE` are empty strings, and `gh pr create --head ""` will fail with an error.
The condition should reference the `publish` step's outputs instead:
```suggestion
- name: Create and merge PR
if: steps.publish.outputs.branch != ''
```
This ensures the step only runs when the publish step actually created a branch and committed the article.
How can I resolve this? If you propose a fix, please make it concise.
Use GH_PAT instead of GITHUB_TOKEN to bypass branch protection on develop.