Skip to content

Commit

Permalink
change post release
Browse files Browse the repository at this point in the history
  • Loading branch information
yeager-eren committed Dec 30, 2023
1 parent 36a5443 commit 8121dc0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
33 changes: 33 additions & 0 deletions scripts/common/git.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,39 @@ export async function merge(branch) {
return output;
}

export async function createAndSwitch(branch) {
const output = await execa('git', ['checkout', '-b', branch])
.then(({ stdout }) => stdout)
.catch((error) => {
throw new GitError(`git checkout -b failed. \n ${error.stderr}`);
});

return output;
}

export async function del(branch) {
const remote = 'origin';
const deleteRemoteBranch = execa('git', ['push', '-d', remote, branch])
.then(({ stdout }) => stdout)
.catch((error) => {
throw new GitError(`git push -d failed. \n ${error.stderr}`);
});
const deleteLocalBranch = execa('git', ['branch', '-d', branch])
.then(({ stdout }) => stdout)
.catch((error) => {
throw new GitError(`git branch failed. \n ${error.stderr}`);
});

const output = await Promise.allSettled([
deleteRemoteBranch,
deleteLocalBranch,
]).then((values) =>
values.map((item) => `[${item.status}]:\n${item.value}`).join('\n\n')
);

return output;
}

export async function getLastCommitId() {
const commitId = await execa('git', ['log', '--format=%s', '-n', 1])
.then(({ stdout }) => stdout)
Expand Down
17 changes: 11 additions & 6 deletions scripts/post-release/command.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { checkout, merge, pull, push } from '../common/git.mjs';
import { checkout, del, merge, pull, push } from '../common/git.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');
await pull();

await checkCommitAndGetPkgs();

// Merge phase
await checkout('next');
await pull();
await merge('main');
await push();
// Making sure we are deleting the branch then create a new one.
await del(tempBranch);
await createAndSwitch(tempBranch);
}

run().catch((e) => {
Expand Down
7 changes: 5 additions & 2 deletions scripts/post-release/tag.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getLastCommitMessage, getLastCommitSubject } from '../common/git.mjs';
import { tagNameToPkgName } from '../common/utils.mjs';

/**
* Checking last commit to be a release commit/tag.
*
* @returns {Promise<pkg[]>}
* @typedef {Object} pkg
Expand All @@ -14,7 +15,9 @@ export async function checkCommitAndGetPkgs() {
const lastCommitMessage = await getLastCommitMessage();

if (lastCommitSubject !== PUBLISH_COMMIT_SUBJECT) {
throw new Error('Can not proceed');
throw new Error(
'Can not proceed since the last commit should be release commit.'
);
}

const lines = lastCommitMessage.split('\n');
Expand All @@ -23,7 +26,7 @@ export async function checkCommitAndGetPkgs() {
);

if (!affectedPackagesList) {
throw new Error("Commit message isn't valid");
throw new Error("Commit message isn't valid.");
}

const [, affectedPackages] = affectedPackagesList.split(
Expand Down

0 comments on commit 8121dc0

Please sign in to comment.