Update backport action to use env vars on process.* instead of inlined#1597
Update backport action to use env vars on process.* instead of inlined#1597pattonwebz wants to merge 2 commits intodevelopfrom
Conversation
|
Note Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported. |
There was a problem hiding this comment.
Pull request overview
Updates the backport workflow to pass PR metadata between steps via step-level environment variables and to consume them from process.env in the actions/github-script step, reducing inline context interpolation in the script body.
Changes:
- Exposes the merged PR head branch as
BRANCH_NAMEviaenv:in the “Get merged branch name” and “Check if branch exists” steps. - Passes PR metadata (number/title/body/author) into the backport creation step via
env:and reads those values fromprocess.envin the script.
📝 WalkthroughWalkthroughA GitHub Actions workflow was updated to capture the head repository information from merged pull requests and verify branch existence against the fork's Git remote instead of the current origin. PR metadata is now read from environment variables instead of template interpolation in the backport PR creation step. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/backport-to-develop.yml (1)
55-77:⚠️ Potential issue | 🔴 CriticalPass
HEAD_REPOto the script and qualify theheadparameter with the source owner.Line 76 uses
head: branchNamewithout owner qualification. This fails when the merged PR originated from a fork. Thehead-repooutput is already computed (line 30–34) but not passed to the script environment. The GitHub REST API requiresowner:branchformat for cross-repository pull requests.Suggested patch
- name: Create backport PR if: steps.check-branch.outputs.branch-exists == 'true' uses: actions/github-script@v7 env: BRANCH_NAME: ${{ steps.get-branch.outputs.branch-name }} + HEAD_REPO: ${{ steps.get-branch.outputs.head-repo }} ORIGINAL_PR_NUMBER: ${{ github.event.pull_request.number }} ORIGINAL_PR_TITLE: ${{ github.event.pull_request.title }} ORIGINAL_PR_BODY: ${{ github.event.pull_request.body }} ORIGINAL_PR_AUTHOR: ${{ github.event.pull_request.user.login }} with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const branchName = process.env.BRANCH_NAME; + const headRepo = process.env.HEAD_REPO; + const headOwner = headRepo.split('/')[0]; const originalPrNumber = process.env.ORIGINAL_PR_NUMBER; const originalPrTitle = process.env.ORIGINAL_PR_TITLE; const originalPrBody = process.env.ORIGINAL_PR_BODY || ''; const originalPrAuthor = process.env.ORIGINAL_PR_AUTHOR; // Create the backport PR try { const response = await github.rest.pulls.create({ owner: context.repo.owner, repo: context.repo.repo, title: `[Backport] ${originalPrTitle}`, - head: branchName, + head: `${headOwner}:${branchName}`, base: 'develop',🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/backport-to-develop.yml around lines 55 - 77, The script sets BRANCH_NAME and calls github.rest.pulls.create with head: branchName, which breaks for forked PRs; pass the previously computed head-repo output into the script environment (expose it as HEAD_REPO) and then qualify the pull request head when calling github.rest.pulls.create by combining HEAD_REPO and BRANCH_NAME (owner:branch) so the head parameter uses the required owner:branch format for cross-repo PRs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In @.github/workflows/backport-to-develop.yml:
- Around line 55-77: The script sets BRANCH_NAME and calls
github.rest.pulls.create with head: branchName, which breaks for forked PRs;
pass the previously computed head-repo output into the script environment
(expose it as HEAD_REPO) and then qualify the pull request head when calling
github.rest.pulls.create by combining HEAD_REPO and BRANCH_NAME (owner:branch)
so the head parameter uses the required owner:branch format for cross-repo PRs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a7fc83bd-b665-48b4-8891-d04ccac0082b
📒 Files selected for processing (1)
.github/workflows/backport-to-develop.yml
This pull request updates the
.github/workflows/backport-to-develop.ymlworkflow to improve how environment variables are managed and accessed between workflow steps. The main focus is on passing key data as environment variables instead of inline shell variable assignments or direct context access, which helps make the workflow more robust and easier to maintain.Workflow environment variable handling:
BRANCH_NAME) instead of setting it as a shell variable in the "Get merged branch name" and "Check if branch exists" steps, improving consistency and reliability.process.envinstead of using direct context access. This makes the script more portable and less dependent on the workflow context object.Checklist
Summary by CodeRabbit