Skip to content

Commit

Permalink
feat: add auto versioning semver bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Cesarato committed Jan 21, 2021
1 parent fd7485f commit 82c8839
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function generate(InputInterface $input, SymfonyStyle $output): int
'to' => $toTag,
'date' => Git::getCommitDate($toTag),
'options' => "{$fromTag}..{$toTag}",
'autoBump' => false,
];
$previousTag = $toTag;
}
Expand All @@ -155,6 +156,7 @@ public function generate(InputInterface $input, SymfonyStyle $output): int
'to' => $newVersion,
'date' => $today->format('Y-m-d'),
'options' => "{$lastVersion}..HEAD",
'autoBump' => false,
];
}
$options = array_reverse($options);
Expand Down Expand Up @@ -186,6 +188,7 @@ public function generate(InputInterface $input, SymfonyStyle $output): int
'to' => $newVersion,
'date' => $today->format('Y-m-d'),
'options' => $additionalParams,
'autoBump' => $autoBump,
];
}

Expand Down Expand Up @@ -254,6 +257,19 @@ public function generate(InputInterface $input, SymfonyStyle $output): int
}
}

if ($params['autoBump']) {
$bumpRelease = SemanticVersion::PATCH;

if ($summary['breaking_changes'] > 0) {
$bumpRelease = SemanticVersion::MAJOR;
} elseif ($summary['feat'] > 0) {
$bumpRelease = SemanticVersion::MINOR;
}

$semver = new SemanticVersion($params['from']);
$params['to'] = $semver->bump($bumpRelease);
}

// Remote url
$url = Git::getRemoteUrl();
// Initialize changelogs
Expand Down
16 changes: 12 additions & 4 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public function fromArray(array $array)
}

$defaults = [
'headerTitle' => $this->headerTitle,
'headerDescription' => $this->headerDescription,
'path' => $this->path,
'preset' => array_merge($this->breakingPreset, $this->preset),
'headerTitle' => $this->getHeaderTitle(),
'headerDescription' => $this->getHeaderDescription(),
'path' => $this->getPath(),
'preset' => $this->getPreset(),
'types' => [],
'ignoreTypes' => ['build', 'chore', 'ci', 'docs', 'refactor', 'revert', 'style', 'test'],
];
Expand Down Expand Up @@ -253,4 +253,12 @@ public function setIgnorePatterns(array $ignorePatterns): Configuration

return $this;
}

/**
* @return string[][]
*/
public function getPreset() : array
{
return array_merge($this->breakingPreset, $this->preset);
}
}

0 comments on commit 82c8839

Please sign in to comment.