Skip to content

Commit

Permalink
add pr step
Browse files Browse the repository at this point in the history
  • Loading branch information
yeager-eren committed Dec 31, 2023
1 parent 096bd74 commit 85c9216
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/PUBLISH_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Checklist

- [ ] Item 1
- [ ] Item 2
7 changes: 7 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
7 changes: 7 additions & 0 deletions scripts/common/errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
41 changes: 41 additions & 0 deletions scripts/common/github.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { execa } from 'execa';
import { generateChangelog } from './changelog.mjs';
import {
GithubCommandError,
GithubCreateReleaseFailedError,
GithubGetReleaseError,
GithubReleaseNotFoundError,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions scripts/post-release/command.mjs
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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) => {
Expand Down

0 comments on commit 85c9216

Please sign in to comment.