-
-
Notifications
You must be signed in to change notification settings - Fork 22
Automatically generate changelog revision text if the changelog was not hand-crafted - do not commit if unchanged #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
93d2504
6b5b85e
4ea82d5
9b2a547
fca80b8
e5b74ae
6ef4255
7dfb68c
99877aa
46c5e5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions | ||
|
||
name: "Automatic Releases" | ||
|
||
on: | ||
milestone: | ||
types: | ||
- "closed" | ||
|
||
jobs: | ||
release: | ||
name: "GIT tag, release & create merge-up PR" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v2" | ||
|
||
- name: "Release" | ||
uses: "laminas/automatic-releases@v1" | ||
with: | ||
command-name: "laminas:automatic-releases:release" | ||
env: | ||
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} | ||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} | ||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} | ||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} | ||
|
||
- name: "Create Merge-Up Pull Request" | ||
uses: "laminas/automatic-releases@v1" | ||
with: | ||
command-name: "laminas:automatic-releases:create-merge-up-pull-request" | ||
env: | ||
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} | ||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} | ||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} | ||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} | ||
|
||
- name: "Create and/or Switch to new Release Branch" | ||
uses: "laminas/automatic-releases@v1" | ||
with: | ||
command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor" | ||
env: | ||
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} | ||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} | ||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} | ||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} | ||
|
||
- name: "Bump Changelog Version On Originating Release Branch" | ||
uses: "laminas/automatic-releases@v1" | ||
with: | ||
command-name: "laminas:automatic-releases:bump-changelog" | ||
env: | ||
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} | ||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} | ||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} | ||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,22 +84,28 @@ public function execute(InputInterface $input, OutputInterface $output): int | |
sprintf('No valid release branch found for version %s', $releaseVersion->fullReleaseName()) | ||
); | ||
|
||
($this->commitChangelog)($repositoryPath, $releaseVersion, $releaseBranch); | ||
|
||
$changelog = ($this->createChangelogText)( | ||
$changelogReleaseNotes = ($this->createChangelogText)( | ||
$milestone, | ||
$repositoryName, | ||
$releaseVersion, | ||
$releaseBranch, | ||
$repositoryPath | ||
); | ||
|
||
($this->commitChangelog)($changelogReleaseNotes, $repositoryPath, $releaseVersion, $releaseBranch); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like how this now receives a pre-computed changelog 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought you might. 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This made me happy as well. The "commit, then create" from before worked, and was necessary based on what we were doing, but this makes sooooo much more sense. |
||
|
||
$tagName = $releaseVersion->fullReleaseName(); | ||
|
||
($this->createTag)($repositoryPath, $releaseBranch, $tagName, $changelog, $this->environment->signingSecretKey()); | ||
($this->createTag)( | ||
$repositoryPath, | ||
$releaseBranch, | ||
$tagName, | ||
$changelogReleaseNotes->contents(), | ||
$this->environment->signingSecretKey() | ||
); | ||
($this->push)($repositoryPath, $tagName); | ||
($this->push)($repositoryPath, $tagName, $releaseVersion->targetReleaseBranchName()->name()); | ||
($this->createRelease)($repositoryName, $releaseVersion, $changelog); | ||
($this->createRelease)($repositoryName, $releaseVersion, $changelogReleaseNotes->contents()); | ||
|
||
return 0; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\AutomaticReleases\Changelog; | ||
|
||
use Phly\KeepAChangelog\Common\ChangelogEditor; | ||
use Phly\KeepAChangelog\Common\ChangelogEntry; | ||
use RuntimeException; | ||
use Webmozart\Assert\Assert; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
class ChangelogReleaseNotes | ||
Ocramius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
private const CONCATENATION_STRING = "\n\n-----\n\n"; | ||
|
||
private ?ChangelogEntry $changelogEntry; | ||
|
||
/** @psalm-var non-empty-string */ | ||
private string $contents; | ||
|
||
/** | ||
* @psalm-param non-empty-string $changelogFile | ||
*/ | ||
public static function writeChangelogFile(string $changelogFile, self $releaseNotes): void | ||
{ | ||
// Nothing to do | ||
if (! $releaseNotes->requiresUpdatingChangelogFile()) { | ||
return; | ||
} | ||
|
||
Assert::notNull($releaseNotes->changelogEntry); | ||
|
||
$editor = new ChangelogEditor(); | ||
$editor->update( | ||
$changelogFile, | ||
$releaseNotes->contents, | ||
$releaseNotes->changelogEntry | ||
); | ||
} | ||
|
||
/** | ||
* @psalm-param non-empty-string $contents | ||
*/ | ||
public function __construct( | ||
string $contents, | ||
?ChangelogEntry $changelogEntry = null | ||
) { | ||
if ($changelogEntry) { | ||
$changelogEntry = clone $changelogEntry; | ||
} | ||
|
||
$this->contents = $contents; | ||
|
||
/** @psalm-suppress ImpurePropertyAssignment */ | ||
$this->changelogEntry = $changelogEntry; | ||
} | ||
|
||
/** | ||
* @psalm-return non-empty-string | ||
*/ | ||
public function contents(): string | ||
{ | ||
return $this->contents; | ||
} | ||
|
||
public function merge(self $next): self | ||
{ | ||
if ($this->changelogEntry && $next->changelogEntry) { | ||
throw new RuntimeException( | ||
'Aborting: Both current release notes and next contain a ChangelogEntry;' | ||
. ' only one CreateReleaseText implementation should resolve one.' | ||
); | ||
} | ||
|
||
$changelogEntry = $this->changelogEntry ?: $next->changelogEntry; | ||
if ($changelogEntry) { | ||
$changelogEntry = clone $changelogEntry; | ||
} | ||
|
||
$merged = clone $this; | ||
$merged->contents .= self::CONCATENATION_STRING . $next->contents; | ||
/** @psalm-suppress ImpurePropertyAssignment */ | ||
$merged->changelogEntry = $changelogEntry; | ||
|
||
return $merged; | ||
} | ||
|
||
public function requiresUpdatingChangelogFile(): bool | ||
{ | ||
if ($this->changelogEntry === null) { | ||
return false; | ||
} | ||
|
||
$originalContents = (string) $this->changelogEntry->contents(); | ||
|
||
return $this->contents !== $originalContents; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example needs a better comment