Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress with backport action #4608

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 54 additions & 49 deletions .github/workflows/backport-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
actions: write
steps:
- name: Cleanup workflow runs
uses: actions/github-script@v7
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const repo_owner = context.payload.repository.owner.login;
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
pull-requests: write
steps:
- name: Extract backport target branch
uses: actions/github-script@v7
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
id: target-branch-extractor
with:
result-encoding: string
Expand All @@ -85,23 +85,66 @@ jobs:
return target_branch[1];

- name: Extract PR id
uses: actions/github-script@v7
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
id: pr-id-extractor
with:
result-encoding: string
script: |
return context.issue.number;

- name: Calculate backport branch name
uses: actions/github-script@v7
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
id: backport-branch-name-extractor
with:
result-encoding: string
script: |
return `backport/${{ steps.pr-id-extractor.outputs.result }}/to/${{ steps.target-branch-extractor.outputs.result }}`;

- name: Calculate backport PR title
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
id: backport-pr-title-extractor
env:
BACKPORT_PR_TITLE_TEMPLATE: ${{ inputs.pr_title_template }}
with:
result-encoding: string
script: |
// replace the special placeholder tokens with values
const { BACKPORT_PR_TITLE_TEMPLATE } = process.env
const target_branch = '${{ steps.target-branch-extractor.outputs.result }}';

const backport_pr_title = BACKPORT_PR_TITLE_TEMPLATE
.replace(/%target_branch%/g, target_branch)
.replace(/%source_pr_title%/g, context.payload.issue.title)
.replace(/%source_pr_number%/g, context.payload.issue.number)

return backport_pr_title;

- name: Calculate backport PR description
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
id: backport-pr-description-extractor
env:
BACKPORT_PR_DESCRIPTION_TEMPLATE: ${{ inputs.pr_description_template }}
with:
result-encoding: string
script: |
// get users to cc (append PR author if different from user who issued the backport command)
const comment_user = context.payload.comment.user.login;
let cc_users = `@${comment_user}`;
if (comment_user != context.payload.issue.user.login) cc_users += ` @${context.payload.issue.user.login}`;

// replace the special placeholder tokens with values
const { BACKPORT_PR_DESCRIPTION_TEMPLATE } = process.env
const target_branch = '${{ steps.target-branch-extractor.outputs.result }}';

const backport_pr_description = BACKPORT_PR_DESCRIPTION_TEMPLATE
.replace(/%target_branch%/g, target_branch)
.replace(/%source_pr_title%/g, context.payload.issue.title)
.replace(/%source_pr_number%/g, context.payload.issue.number)
.replace(/%cc_users%/g, cc_users);


- name: Unlock comments if PR is locked
uses: actions/github-script@v7
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
if: ${{ github.event.issue.locked == true }}
with:
script: |
Expand All @@ -112,7 +155,7 @@ jobs:
repo: context.repo.repo,
});
- name: Post backport started comment to pull request
uses: actions/github-script@v7
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const target_branch = '${{ steps.target-branch-extractor.outputs.result }}';
Expand All @@ -124,14 +167,11 @@ jobs:
body: backport_start_body
});
- name: Checkout repo
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- name: Run backport
uses: actions/github-script@v7
env:
BACKPORT_PR_TITLE_TEMPLATE: ${{ inputs.pr_title_template }}
BACKPORT_PR_DESCRIPTION_TEMPLATE: ${{ inputs.pr_description_template }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const target_branch = '${{ steps.target-branch-extractor.outputs.result }}';
Expand Down Expand Up @@ -165,10 +205,6 @@ jobs:
// download and apply patch
await exec.exec(`curl -sSL "${context.payload.issue.pull_request.patch_url}" --output changes.patch`);

// create temporary backport branch
// const temp_branch = `backport/pr-${pr_number}-to-${target_branch}`;
// await exec.exec(`git checkout -b ${temp_branch}`);

// configure git
await exec.exec(`git config user.name "github-actions"`);
await exec.exec(`git config user.email "[email protected]"`);
Expand Down Expand Up @@ -229,39 +265,6 @@ jobs:
}

await exec.exec(`rm changes.patch`);

// prepare the GitHub PR details

// get users to cc (append PR author if different from user who issued the backport command)
// let cc_users = `@${comment_user}`;
// if (comment_user != context.payload.issue.user.login) cc_users += ` @${context.payload.issue.user.login}`;

// replace the special placeholder tokens with values
// const { BACKPORT_PR_TITLE_TEMPLATE, BACKPORT_PR_DESCRIPTION_TEMPLATE } = process.env

// const backport_pr_title = BACKPORT_PR_TITLE_TEMPLATE
// .replace(/%target_branch%/g, target_branch)
// .replace(/%source_pr_title%/g, context.payload.issue.title)
// .replace(/%source_pr_number%/g, context.payload.issue.number)
// .replace(/%cc_users%/g, cc_users);

// const backport_pr_description = BACKPORT_PR_DESCRIPTION_TEMPLATE
// .replace(/%target_branch%/g, target_branch)
// .replace(/%source_pr_title%/g, context.payload.issue.title)
// .replace(/%source_pr_number%/g, context.payload.issue.number)
// .replace(/%cc_users%/g, cc_users);

// open the GitHub PR
// await github.rest.pulls.create({
// owner: repo_owner,
// repo: repo_name,
// title: backport_pr_title,
// body: backport_pr_description,
// head: temp_branch,
// base: target_branch
// });

// console.log("Successfully opened the GitHub PR.");
} catch (error) {

core.setFailed(error);
Expand All @@ -281,9 +284,11 @@ jobs:
token: ${{ secrets.BACKPORT_MACHINE_USER_PAT }}
push-to-fork: youssef-backport-bot/testfx
branch: ${{ steps.backport-branch-name-extractor.outputs.result }}
title: ${{ steps.backport-pr-title-extractor.outputs.result }}
body: ${{ steps.backport-pr-description-extractor.outputs.result }}

- name: Re-lock PR comments
uses: actions/github-script@v7
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
if: ${{ github.event.issue.locked == true && (success() || failure()) }}
with:
script: |
Expand Down