Skip to content

Commit

Permalink
fix(turbo-version): update branch name strategy
Browse files Browse the repository at this point in the history
change the approach to use date to define the last merge into the main branch
  • Loading branch information
jucian0 committed Dec 7, 2023
1 parent 394e28e commit 749c3cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 4 additions & 6 deletions packages/turbo-git/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@ export async function gitProcess({
}
}

export async function lastMergeBranchName(baseBranch: string) {
export async function lastMergeBranchName(branches: string[], baseBranch: string) {
try {
// //git log --merges --oneline --format='%s' -n 1 | grep -o -i -E "feature/(.*)|bugfix/(.*)|hotfix/(.*)|break-changes/(.*)" | awk -F'[ ]' '{print $1}'
const lastBranchName = await execAsync(
`git branch --contains $(git rev-parse $(git rev-list --merges --first-parent ${baseBranch} | tail -n 2 | head -n 1)) | grep -v "${baseBranch}" | awk '{print $NF}'`
);
const branchesRegex = branches.join("/(.*)|")+"/(.*)";
const lastBranchName = await execAsync(`git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads --merged ${baseBranch} | grep -o -i -E "${branchesRegex}" | awk -F'[ ]' '{print $1}' | head -n 1`);
return lastBranchName.stdout.trim();
} catch (error: any) {
console.error("Error while getting the last branch name:", error.message);
return null;
}
}
}Z
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export async function generateVersionByBranchName({
try {
const recommended = await genNextTagByBranchName(branchPattern, baseBranch);

console.log({ recommended });

const currentVersion =
semver.parse(latestTag.replace(tagPrefix, "")) ?? "0.0.0";

Expand All @@ -48,7 +46,7 @@ async function genNextTagByBranchName(
schema: string[],
mainBranchName = "main"
) {
const branch = await lastMergeBranchName(mainBranchName);
const branch = await lastMergeBranchName(schema,mainBranchName);

if (branch?.includes(schema[0])) {
return "major";
Expand Down

0 comments on commit 749c3cc

Please sign in to comment.