diff --git a/.github/PUBLISH_TEMPLATE.md b/.github/PUBLISH_TEMPLATE.md new file mode 100644 index 0000000000..79854da3b8 --- /dev/null +++ b/.github/PUBLISH_TEMPLATE.md @@ -0,0 +1,4 @@ +# Checklist + +- [ ] Item 1 +- [ ] Item 2 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ab5eccaaef..911c143a5a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -43,3 +43,10 @@ jobs: REF: ${{ github.ref }} BASE_REF: ${{ github.event.pull_request.base.ref }} GH_TOKEN: ${{ github.token }} + + - name: Creating PR on next + run: yarn run post-release-prod + env: + REF: ${{ github.ref }} + BASE_REF: ${{ github.event.pull_request.base.ref }} + GH_TOKEN: ${{ github.token }} diff --git a/scripts/common/errors.mjs b/scripts/common/errors.mjs index ebac66a5d1..ca5f8a8de1 100644 --- a/scripts/common/errors.mjs +++ b/scripts/common/errors.mjs @@ -19,6 +19,13 @@ export class GithubCreateReleaseFailedError extends Error { } } +export class GithubCommandError extends Error { + name = 'GithubCommandError'; + constructor(msg) { + super(msg); + } +} + export class NpmPackageNotFoundError extends Error { name = 'NpmPackageNotFoundError'; constructor(packageName) { diff --git a/scripts/common/github.mjs b/scripts/common/github.mjs index 4fbbf32116..a4e77e606f 100644 --- a/scripts/common/github.mjs +++ b/scripts/common/github.mjs @@ -1,6 +1,7 @@ import { execa } from 'execa'; import { generateChangelog } from './changelog.mjs'; import { + GithubCommandError, GithubCreateReleaseFailedError, GithubGetReleaseError, GithubReleaseNotFoundError, @@ -82,6 +83,46 @@ export async function githubReleaseFor(pkg) { } } +/** + * + * @param {PullRequestInfo} pr + * + * @typedef {Object} PullRequestInfo + * @property {string} title PR title + * @property {string} branch your current branch + * @property {string} baseBranch PR will be merge into base branch. + * @property {string} templatePath template path for PR + * + */ +export async function createPullRequest(pr) { + const { title, baseBranch, branch, templatePath } = pr; + + if (!title || !baseBranch || !branch || !templatePath) { + throw new GithubCommandError( + 'Creating pull request can not be proceed without required parameters. \n', + JSON.stringify({ title, baseBranch, branch, templatePath }) + ); + } + + const ghCreateParams = [ + '--title', + title, + '--base', + baseBranch, + '--head', + branch, + '--templatePath', + templatePath, + ]; + const output = await execa('gh', ['pr', 'create', ...ghCreateParams]) + .then(({ stdout }) => stdout) + .catch((err) => { + throw new GithubCommandError(err.stdout); + }); + + return output; +} + export function checkEnvironments() { const envs = { NPM_TOKEN: !!process.env.NPM_TOKEN, diff --git a/scripts/post-release/command.mjs b/scripts/post-release/command.mjs index ea15a3a2c6..f7b7fa009f 100644 --- a/scripts/post-release/command.mjs +++ b/scripts/post-release/command.mjs @@ -1,13 +1,10 @@ import { checkout, createAndSwitch, del, pull, push } from '../common/git.mjs'; +import { createPullRequest } from '../common/github.mjs'; import { checkCommitAndGetPkgs } from './tag.mjs'; async function run() { const tempBranch = 'ci/post-release'; const targetBranch = 'next'; - const prTitle = '🤖 Post Release'; - const prTemplatePath = '...'; - - // gh --titile // Make sure we are on main and having latest changes await checkout('main'); @@ -23,6 +20,13 @@ async function run() { setupRemote: true, branch: tempBranch, }); + + await createPullRequest({ + title: '🤖 Post Release', + branch: tempBranch, + baseBranch: targetBranch, + templatePath: '.github/PUBLISH_TEMPLATE.md', + }); } run().catch((e) => {