Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
## Related Issue

If this PR will target main, please complete the below sentence.
If this PR will target main, please correct the below sentence.

Addresses #1234 (main issue)

## Releases

If this PR should be released, please add labels for each release branch it targets.
Use the 'release/v0' tags, not the 'version/v0' tags.

## Description

Expand Down
66 changes: 30 additions & 36 deletions .github/workflows/backport-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
return;
}
core.info(`Found associated PR: #${pr.number}`);

core.info(`Searching for 'internal/main' issue linked to PR #${pr.number}`);
const searchResults = await github.rest.search.issuesAndPullRequests({
q: `is:issue label:"internal/main" repo:${owner}/${repo} in:body #${pr.number}`
Expand All @@ -53,7 +53,7 @@ jobs:
}
const mainIssue = searchResults.data.items[0];
core.info(`Found main issue: #${mainIssue.number}`);

core.info(`Fetching sub-issues for main issue #${mainIssue.number}`);
const { data: subIssues } = await github.rest.issues.listSubIssues({
owner,
Expand All @@ -66,41 +66,35 @@ jobs:
return;
}
core.info(`Found ${subIssues.length} sub-issues.`);

for (const subIssue of subIssues) {
try {
const subIssueNumber = subIssue.number;

// Find the release label directly on the sub-issue object
const releaseLabel = subIssue.labels.find(label => label.name.startsWith('release/v'));
if (!releaseLabel) {
core.warning(`Sub-issue #${subIssueNumber} has no 'release/v...' label. Skipping.`);
continue;
}
const targetBranch = releaseLabel.name
core.info(`Processing sub-issue #${subIssueNumber} for target branch: ${targetBranch}`);

const newBranchName = `backport-${pr.number}-${targetBranch.replace(/\//g, '-')}`;
execSync(`git config user.name "github-actions[bot]"`);
execSync(`git config user.email "github-actions[bot]@users.noreply.github.com"`);
execSync(`git fetch origin ${targetBranch}`);
execSync(`git checkout -b ${newBranchName} origin/${targetBranch}`);

core.info(`Cherry-picking commit ${mergeCommitSha}...`);
execSync(`git cherry-pick -x ${mergeCommitSha}`);
for (const subIssue of subIssues) {
const subIssueNumber = subIssue.number;

// Find the release label directly on the sub-issue object
const releaseLabel = subIssue.labels.find(label => label.name.startsWith('release/v'));
if (!releaseLabel) {
core.warning(`Sub-issue #${subIssueNumber} has no 'release/v...' label. Skipping.`);
continue;
}
const targetBranch = releaseLabel.name
core.info(`Processing sub-issue #${subIssueNumber} for target branch: ${targetBranch}`);

core.info(`Pushing new branch ${newBranchName}...`);
execSync(`git push origin ${newBranchName}`);

core.info(`Creating pull request for branch ${newBranchName} targeting ${targetBranch}...`);
const newBranchName = `backport-${pr.number}-${targetBranch.replace(/\//g, '-')}`;
execSync(`git config user.name "github-actions[bot]"`);
execSync(`git config user.email "github-actions[bot]@users.noreply.github.com"`);
execSync(`git fetch origin ${targetBranch}`);
execSync(`git checkout -b ${newBranchName} origin/${targetBranch}`);
execSync(`git cherry-pick -x ${mergeCommitSha}`);
execSync(`git push origin ${newBranchName}`);

const { data: newPr } = await github.rest.pulls.create({
owner,
repo,
title: pr.title,
head: newBranchName,
base: targetBranch,
body: "This pull request cherry-picks the changes from #" + pr.number + " into " + targetBranch,
});
}
core.info(`Creating pull request for branch ${newBranchName} targeting ${targetBranch}...`);
const { data: newPr } = await github.rest.pulls.create({
owner,
repo,
title: pr.title,
head: newBranchName,
base: targetBranch,
body: "This pull request cherry-picks the changes from #" + pr.number + " into " + targetBranch,
assignees: ['terraform-maintainers']
});
}
1 change: 1 addition & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
title: "Backport #" + parentIssueNumber + " to release/v0",
body: "Backport #" + parentIssueNumber + " to release/v0"
labels: ['release/v0']
assignees: ['terraform-maintainers']
});

const subIssueId = newIssue.data.id;
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/main-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:
const repo = context.repo.repo;
const owner = context.repo.owner;
const pr = context.payload.pull_request;
const reviewers = pr.requested_reviewers.map(reviewer => reviewer.login)
const releaseLabel = pr.head.labels.find(label => label.name.startsWith('release/v'));
const versionLabel = releaseLabel.name.replace('release/', 'version/');

// Create the main issue
const newIssue = await github.rest.issues.create({
Expand All @@ -29,6 +30,6 @@ jobs:
"Please add labels indicating the release versions eg. 'version/v0' \n\n" +
"Please add comments for user issues which this issue addresses. \n\n" +
"Description copied from PR: \n" + pr.body,
labels: ['internal/main'],
assignees: reviewers
labels: ['internal/main', versionLabel],
assignees: ['terraform-maintainers']
});
Loading