Skip to content

Manually Cherry-Pick to Release Branches #5

Manually Cherry-Pick to Release Branches

Manually Cherry-Pick to Release Branches #5

name: 'Manually Cherry-Pick to Release Branches'
on:
workflow_dispatch:
inputs:
merge_commit_sha:
description: 'The sha of the merge commit from the main PR.'
required: true
env :
TERRAFORM_MAINTAINERS: ${{ vars.TERRAFORM_MAINTAINERS }} # eg. ["matttrach"]
jobs:
create-cherry-pick-prs:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
actions: write
steps:
- name: 'Wait for merge to settle'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 https://github.com/actions/github-script
env:
MERGE_COMMIT_SHA: ${{ inputs.merge_commit_sha }}
TERRAFORM_MAINTAINERS: ${{ env.TERRAFORM_MAINTAINERS }}
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const mergeCommitSha = process.env.MERGE_COMMIT_SHA;
// wait 10 seconds to allow GitHub to index the commit and associated PRs
await new Promise(resolve => setTimeout(resolve, 10000));
// just in case the GitHub API is still having trouble, try to fetch associated PRs
let response;
try {
response = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha: mergeCommitSha
});
} catch (error) {
core.setFailed(`Failed to retrieve PRs associated with commit ${mergeCommitSha}: ${error.message}`);
}
- name: 'Checkout Repository'
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 https://github.com/actions/checkout
with:
fetch-depth: 0
- name: 'Find Issues and Create Cherry-Pick PRs'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 https://github.com/actions/github-script
env:
MERGE_COMMIT_SHA: ${{ inputs.merge_commit_sha }}
TERRAFORM_MAINTAINERS: ${{ env.TERRAFORM_MAINTAINERS }}
with:
script: |
const scriptPath = `${process.env.GITHUB_WORKSPACE}/.github/workflows/scripts/backport-pr.js`;
const { default: script } = await import(scriptPath);
await script({github, core, process});