Skip to content

Update backport action to use env vars on process.* instead of inlined#1597

Open
pattonwebz wants to merge 2 commits intodevelopfrom
william/no-issue/update-backport-action-to-use-processed-env-vars
Open

Update backport action to use env vars on process.* instead of inlined#1597
pattonwebz wants to merge 2 commits intodevelopfrom
william/no-issue/update-backport-action-to-use-processed-env-vars

Conversation

@pattonwebz
Copy link
Copy Markdown
Member

@pattonwebz pattonwebz commented Mar 23, 2026

This pull request updates the .github/workflows/backport-to-develop.yml workflow 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:

  • Passes the branch name as an environment variable (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.
  • In the "Create backport PR" step, passes all relevant pull request metadata (branch name, PR number, title, body, author) as environment variables, and updates the script to read these from process.env instead of using direct context access. This makes the script more portable and less dependent on the workflow context object.

Checklist

  • PR is linked to the main issue in the repo
  • Tests are added that cover changes

Summary by CodeRabbit

  • Bug Fixes
    • Improved backport workflow reliability by correctly handling pull requests from forks when verifying branch existence and capturing PR metadata. The workflow now properly references fork repositories instead of the current origin, ensuring accurate branch validation during backport operations.

Copilot AI review requested due to automatic review settings March 23, 2026 22:00
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Note

Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_NAME via env: 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 from process.env in the script.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

A 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

Cohort / File(s) Summary
GitHub Actions Workflow
.github/workflows/backport-to-develop.yml
Updated branch existence verification to check against the fork's remote using the head repository URL and reference. Refactored PR metadata handling to pass branch name and original PR information via environment variables instead of template interpolation in the backport PR creation logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Branch checks now leap to distant forks,
No longer stuck on origin's familiar shores,
Variables whisper what templates once sang,
A cleaner flow through backport's twangs! 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: updating the backport workflow to use environment variables with process.* instead of inlined values.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch william/no-issue/update-backport-action-to-use-processed-env-vars

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🔴 Critical

Pass HEAD_REPO to the script and qualify the head parameter with the source owner.

Line 76 uses head: branchName without owner qualification. This fails when the merged PR originated from a fork. The head-repo output is already computed (line 30–34) but not passed to the script environment. The GitHub REST API requires owner:branch format 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7b6ef1f and 9d4003d.

📒 Files selected for processing (1)
  • .github/workflows/backport-to-develop.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants