Skip to content
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

[misc] release process refactor #360

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
docker-compose.yml export-ignore
phpstan.neon export-ignore
phpunit.xml export-ignore
bin/ export-ignore
tests/ export-ignore
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
paths:
- .php-cs-fixer.dist.php
- autoload.php
- bin/**
- lib/**
- data/**
- tests/**
Expand All @@ -13,6 +14,7 @@ on:
paths:
- .php-cs-fixer.dist.php
- autoload.php
- bin/**
- lib/**
- data/**
- tests/**
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
push:
tags:
- "**"

name: Release

jobs:
release:
name: Release

runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: none
extensions: none
tools: none

- name: Determine tag
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Parse ChangeLog
run: bin/extract-release-notes.php ${{ env.RELEASE_TAG }} > release-notes.md

- name: Create release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.RELEASE_TAG }}
name: Symfony1 ${{ env.RELEASE_TAG }}
bodyFile: release-notes.md
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$finder = PhpCsFixer\Finder::create()
->ignoreVCSIgnored(true)
->in(__DIR__.'/lib')
->in(__DIR__.'/bin')
->in(__DIR__.'/data/bin')
->in(__DIR__.'/test')
->append([__FILE__])
Expand Down
61 changes: 61 additions & 0 deletions bin/extract-release-notes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

/*
* This file is part of the Symfony1 package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

if (2 !== $_SERVER['argc']) {
echo sprintf('Usage: %s version', basename(__FILE__)).PHP_EOL;
exit(1);
}

$version = $_SERVER['argv'][1];
$rawVersion = str_starts_with($version, 'v') ? substr($version, 1) : $version;

$changelogFilePath = __DIR__.'/../CHANGELOG.md';

if (!is_file($changelogFilePath) || !is_readable($changelogFilePath)) {
echo 'Changelog file cannot read.'.PHP_EOL;
exit(1);
}

$buffer = '';
$state = 'not_release_note';

foreach (file($changelogFilePath) as $line) {
if (str_contains($line, 'Version '.$rawVersion)) {
$state = 'note_header';
continue;
}

if ('note_header' === $state) {
$state = 'note';
continue;
}

if ('note' === $state && str_contains($line, 'Version ')) {
break;
}

if ('note' === $state) {
$buffer .= $line;
}
}

$buffer = trim($buffer);

if ('' === $buffer) {
echo 'Release note not found for the specified version.'.PHP_EOL;
exit(1);
}

echo $buffer.PHP_EOL;
exit(0);
146 changes: 146 additions & 0 deletions bin/release.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

/*
* This file is part of the Symfony1 package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

if (PHP_VERSION_ID < 80300) {
echo 'PHP 8.3 required'.PHP_EOL;
exit(1);
}

if (!isset($argv[1])) {
throw new InvalidArgumentException('You must specify the version: v1.x.x or next.');
}

$version = $argv[1];

exec('git tag -l', $tags, $resultCode);

if ($resultCode > 0 || 0 === count($tags)) {
throw new RuntimeException('Reading tag failed.');
}

$latestVersionNumber = $tags[0];
foreach ($tags as $tag) {
if (version_compare($latestVersionNumber, $tag) < 0) {
$latestVersionNumber = $tag;
}
}

if ('next' !== $version) {
if (!preg_match('/^v1\.([5-9]|\d{2,})\.\d+$/', $version)) {
throw new InvalidArgumentException(sprintf('The format of the specified version number is incorrect: "%s"', $version));
}

if (in_array($version, $tags)) {
throw new InvalidArgumentException(sprintf('The specified version number already exists: "%s"', $version));
}

[$latestMajorPart, $latestMinorPart, $latestPatchPart] = explode('.', $latestVersionNumber);
[$versionMajorPart, $versionMinorPart, $versionPatchPart] = explode('.', $version);

// This cannot be due to regexp. Just double check.
if ($latestMajorPart !== $versionMajorPart) {
throw new InvalidArgumentException(sprintf('The specified version number can\'t change major: "%s"', $version));
}

// changed minor or patch
if ($latestMinorPart !== $versionMinorPart) {
if ('0' !== $versionPatchPart) {
throw new InvalidArgumentException(sprintf('The specified version number should be: "%s.%s.0"', $versionMajorPart, $versionMinorPart));
}
} elseif ($latestPatchPart !== $versionPatchPart) {
$latestPatchPartInt = (int) $latestPatchPart;
$versionPatchPartInt = (int) $versionPatchPart;

$nextPatchPartInt = $latestPatchPartInt + 1;

if ($nextPatchPartInt !== $versionPatchPartInt) {
throw new InvalidArgumentException(sprintf('Don\'t skip patch version. The specified version number should be: "%s.%s.%d"', $versionMajorPart, $versionMinorPart, $nextPatchPartInt));
}
}
} else {
[$latestMajorPart, $latestMinorPart, $latestPatchPart] = explode('.', $latestVersionNumber);
$nextPatchPart = (int) $latestPatchPart + 1;
$version = sprintf('%s.%s.%d', $latestMajorPart, $latestMinorPart, $nextPatchPart);
}

$rawVersion = substr($version, 1);

echo sprintf("Prepare symfony version \"%s\".\n", $rawVersion);

/**
* prepare sfCoreAutoload class.
*/
$file = __DIR__.'/../lib/autoload/sfCoreAutoload.class.php';
$content = file_get_contents($file);

$content = preg_replace('/^define\(.*SYMFONY_VERSION.*$/m', 'define(\'SYMFONY_VERSION\', \''.$rawVersion.'\');', $content, -1, $count);

if (1 !== $count) {
throw new RuntimeException('Preparing sfCoreAutoload failed, SYMFONY_VERSION constant not found.');
}

file_put_contents($file, $content);

/**
* prepare CHANGELOG.md.
*/
$file = __DIR__.'/../CHANGELOG.md';
$content = file_get_contents($file);

$nextVersionHeader = <<<'EOL'
xx/xx/xxxx: Version 1.5.xx
--------------------------




EOL;

$changelogHeader = sprintf('%s: Version %s', date('d/m/Y'), $rawVersion);
$content = preg_replace('/^xx\/xx\/xxxx.*$/m', $nextVersionHeader.$changelogHeader, $content, -1, $count);

if (1 !== $count) {
throw new RuntimeException('Preparing CHANGELOG.md failed. Template line not found.');
}

file_put_contents($file, $content);

/*
* content prepare end
*/

echo "Please check the changes before commit and tagging.\n";

passthru('git diff');

echo "Is everything ok? (y/N)\n";

$answer = readline();

if ('y' !== strtolower($answer)) {
echo "Revert changes.\n";
exec('git checkout lib/autoload/sfCoreAutoload.class.php');
exec('git checkout CHANGELOG.md');
echo "Stopped.\n";
exit(1);
}

chdir(__DIR__.'/..');
exec('git add lib/autoload/sfCoreAutoload.class.php');
exec('git add CHANGELOG.md');
exec('git commit -m "Prepare release '.$rawVersion.'"');
exec('git tag -a '.$version.' -m "Release '.$rawVersion.'"');
exec('git push origin '.$version);

exit(0);
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"friendsofsymfony1/swiftmailer": "^5.4.13 || ^6.2.5"
},
"require-dev": {
"psr/log": "*"
"psr/log": "*",
"ext-readline": "*"
},
"autoload": {
"files": ["autoload.php"]
Expand Down
48 changes: 0 additions & 48 deletions data/bin/changelog.php

This file was deleted.

Loading