Skip to content

Commit 59a019e

Browse files
committed
Merge branch 'develop' into 4.8
2 parents 2c5057b + ef9f864 commit 59a019e

21 files changed

Lines changed: 692 additions & 37 deletions

File tree

‎admin/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ are used as part of that process:
5454
version references in the framework source, the user guide, and the
5555
distribution build script.
5656
Usage: `php admin/prepare-release.php 4.x.x`
57+
- **create-release.php** publishes the GitHub release for a new version,
58+
crediting every PR author since the previous release except bots.
59+
Usage: `php admin/create-release.php 4.x.x [--previous=v4.x.w] [--dry-run]`
5760
- **create-new-changelog.php** creates the changelog and upgrade guide
5861
stubs for the next version and adds them to their index files.
5962
Usage: `php admin/create-new-changelog.php <current_version> <new_version>`

‎admin/RELEASE.md‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,15 @@ existing content.
150150
* Title: `4.x.x Ready code`
151151
* Description: blank
152152
* [ ] Merge the PR and wait for all tests.
153-
* [ ] Create a new Release:
154-
* Choose a tag: `v4.x.x` (Create new tag: v4.x.x on publish)
155-
* Target: `master`
156-
* Title: `CodeIgniter 4.x.x`
157-
* Description:
158-
```
159-
CodeIgniter 4.x.x release.
160-
161-
See the changelog: https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md
162-
163-
## New Contributors
164-
*
165-
166-
**Full Changelog**: https://github.com/codeigniter4/CodeIgniter4/compare/v4.x.w...v4.x.x
167-
```
168-
Click the "Generate release notes" button, and get the "New Contributors".
153+
* [ ] Create the new Release:
154+
* Run `php admin/create-release.php 4.x.x --dry-run` and check the output.
155+
* Run `php admin/create-release.php 4.x.x` to publish it.
156+
* The above command does the following:
157+
* Fetch GitHub's auto-generated release notes for `master` since the latest
158+
release (override with `--previous=v4.x.w`)
159+
* Credit every PR author except bots, marking first-time contributors
160+
* Publish the release `CodeIgniter 4.x.x` with the tag `v4.x.x` on `master`,
161+
linking to **CHANGELOG.md** and the full comparison
169162
* [ ] Watch the "[Verify Release](https://github.com/codeigniter4/CodeIgniter4/actions/workflows/verify-release.yml)"
170163
workflow and make sure it passes. It does the following:
171164
* Wait for the "[Deploy Distributable Repos](https://github.com/codeigniter4/CodeIgniter4/actions/workflows/deploy-distributables.yml)"

‎admin/create-release.php‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Creates the GitHub release for a new version, crediting every contributor
7+
* except bots.
8+
*
9+
* Requires the authenticated GitHub CLI (`gh`). Run it after the
10+
* "4.x.x Ready code" PR is merged into `master`.
11+
*
12+
* Usage: php admin/create-release.php <version> [--previous=<tag>] [--dry-run]
13+
*/
14+
chdir(__DIR__ . '/..');
15+
16+
$args = array_slice($argv, 1);
17+
$options = array_values(array_filter($args, static fn (string $arg): bool => str_starts_with($arg, '--')));
18+
$params = array_values(array_diff($args, $options));
19+
20+
if (count($params) !== 1 || preg_match('/\Av?(\d+\.\d+\.\d+)\z/', $params[0], $matches) !== 1) {
21+
echo sprintf("Usage: php %s <version> [--previous=<tag>] [--dry-run]\n", $argv[0]);
22+
echo sprintf("E.g.,: php %s 4.7.6\n", $argv[0]);
23+
24+
exit(1);
25+
}
26+
27+
$version = $matches[1];
28+
$tag = sprintf('v%s', $version);
29+
$dryRun = in_array('--dry-run', $options, true);
30+
$repo = 'codeigniter4/CodeIgniter4';
31+
32+
exec(sprintf('gh release view %s --repo %s 2>&1', escapeshellarg($tag), $repo), $output, $exitCode);
33+
34+
if ($exitCode === 0) {
35+
echo sprintf("The release %s already exists.\n", $tag);
36+
37+
exit(1);
38+
}
39+
40+
$previousTag = null;
41+
42+
foreach ($options as $option) {
43+
if (str_starts_with($option, '--previous=')) {
44+
$previousTag = sprintf('v%s', ltrim(substr($option, strlen('--previous=')), 'v'));
45+
}
46+
}
47+
48+
if ($previousTag === null) {
49+
$output = [];
50+
exec(sprintf('gh release view --repo %s --json tagName --jq .tagName 2>&1', $repo), $output, $exitCode);
51+
52+
if ($exitCode !== 0) {
53+
echo "Failed to fetch the latest release from GitHub:\n";
54+
echo implode("\n", $output) . "\n";
55+
56+
exit(1);
57+
}
58+
59+
$previousTag = trim(implode('', $output));
60+
}
61+
62+
$output = [];
63+
exec(sprintf(
64+
'gh api repos/%s/releases/generate-notes -f tag_name=%s -f target_commitish=master -f previous_tag_name=%s 2>&1',
65+
$repo,
66+
escapeshellarg($tag),
67+
escapeshellarg($previousTag),
68+
), $output, $exitCode);
69+
70+
if ($exitCode !== 0) {
71+
echo "Failed to fetch the release notes from GitHub:\n";
72+
echo implode("\n", $output) . "\n";
73+
74+
exit(1);
75+
}
76+
77+
$notes = json_decode(implode("\n", $output), true)['body'] ?? '';
78+
79+
$contributors = [];
80+
$firstPulls = [];
81+
$fullChangelog = null;
82+
83+
foreach (preg_split('/\R/', $notes) as $line) {
84+
if (preg_match('~ by @(\S+) in https://github\.com/\S+/pull/\d+$~', $line, $matches) === 1) {
85+
$contributors[$matches[1]] = true;
86+
87+
continue;
88+
}
89+
90+
if (preg_match('~^\* @(\S+) made their first contribution in (\S+)$~', $line, $matches) === 1) {
91+
$firstPulls[$matches[1]] = $matches[2];
92+
93+
continue;
94+
}
95+
96+
if (str_starts_with($line, '**Full Changelog**: ')) {
97+
$fullChangelog = $line;
98+
}
99+
}
100+
101+
if ($fullChangelog === null) {
102+
echo "Could not find the Full Changelog link in the release notes.\n";
103+
104+
exit(1);
105+
}
106+
107+
$contributors = array_filter(
108+
array_keys($contributors),
109+
static fn (string $login): bool => ! str_ends_with($login, '[bot]'),
110+
);
111+
natcasesort($contributors);
112+
113+
$credits = array_map(
114+
static fn (string $login): string => isset($firstPulls[$login])
115+
? sprintf('* @%s made their first contribution in %s', $login, $firstPulls[$login])
116+
: sprintf('* @%s', $login),
117+
$contributors,
118+
);
119+
120+
$body = sprintf("CodeIgniter %s release.\n\n", $version);
121+
$body .= sprintf("See the changelog: https://github.com/%s/blob/develop/CHANGELOG.md\n\n", $repo);
122+
123+
if ($credits !== []) {
124+
$body .= sprintf("## Contributors\n\n%s\n\n", implode("\n", $credits));
125+
}
126+
127+
$body .= $fullChangelog . "\n";
128+
129+
if ($dryRun) {
130+
echo $body;
131+
132+
exit(0);
133+
}
134+
135+
$notesFile = tempnam(sys_get_temp_dir(), 'ci4-release-');
136+
file_put_contents($notesFile, $body);
137+
138+
passthru(sprintf(
139+
'gh release create %s --repo %s --target master --title %s --notes-file %s',
140+
escapeshellarg($tag),
141+
$repo,
142+
escapeshellarg(sprintf('CodeIgniter %s', $version)),
143+
escapeshellarg($notesFile),
144+
), $exitCode);
145+
146+
unlink($notesFile);
147+
148+
exit($exitCode);

‎system/Database/BaseConnection.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,16 +664,40 @@ public function close()
664664
* Keep or establish the connection if no queries have been sent for
665665
* a length of time exceeding the server's idle timeout.
666666
*
667+
* A replaced socket is not in the transaction that was open on the old
668+
* one. The server has already rolled that work back. Clear the depth and
669+
* mark the transaction failed before opening the new connection, so a
670+
* failed reconnect cannot still report success.
671+
*
667672
* @return void
668673
*/
669674
public function reconnect()
670675
{
671676
if ($this->ping() === false) {
677+
$lostTransaction = $this->transDepth > 0;
678+
672679
$this->close();
680+
681+
if ($lostTransaction) {
682+
$this->abandonLostTransaction();
683+
}
684+
673685
$this->initialize();
674686
}
675687
}
676688

689+
/**
690+
* The socket that owned the transaction is already closed.
691+
*
692+
* Drivers that keep transaction state in PHP, rather than only on the
693+
* server, must override this.
694+
*/
695+
protected function abandonLostTransaction(): void
696+
{
697+
$this->transDepth = 0;
698+
$this->transStatus = false;
699+
}
700+
677701
/**
678702
* Platform dependent way method for closing the connection.
679703
*

‎system/Database/OCI8/Connection.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,17 @@ protected function _transRollback(): bool
795795
return oci_rollback($this->connID);
796796
}
797797

798+
/**
799+
* Restore OCI_COMMIT_ON_SUCCESS. close() does not, and
800+
* OCI_NO_AUTO_COMMIT would leave later writes uncommitted.
801+
*/
802+
protected function abandonLostTransaction(): void
803+
{
804+
$this->commitMode = OCI_COMMIT_ON_SUCCESS;
805+
806+
parent::abandonLostTransaction();
807+
}
808+
798809
/**
799810
* Returns the name of the current database being used.
800811
*/

0 commit comments

Comments
 (0)