|
44 | 44 | $overrides = array_merge($overrides, json_decode($repoMap, true)); |
45 | 45 | } |
46 | 46 |
|
47 | | -// Determine bump type |
| 47 | +// Determine bump type and PR info |
48 | 48 | $bump = getenv('RELEASE_BUMP') ?: null; |
| 49 | +$pr = null; |
49 | 50 |
|
50 | 51 | if (! $bump) { |
51 | 52 | $response = $http->get(sprintf('/repos/%s/commits/%s/pulls', $repository, $commitSha)); |
|
56 | 57 | } |
57 | 58 |
|
58 | 59 | $pr = $response->json()[0]; |
59 | | - $bump = collect($pr['labels'] ?? []) |
60 | | - ->pluck('name') |
| 60 | + $labels = collect($pr['labels'] ?? [])->pluck('name'); |
| 61 | + |
| 62 | + $bump = $labels |
61 | 63 | ->filter(fn (string $label) => str_starts_with($label, 'release:')) |
62 | 64 | ->map(fn (string $label) => str_replace('release:', '', $label)) |
63 | 65 | ->first(); |
| 66 | + |
| 67 | + // new-provider label triggers an initial release |
| 68 | + if (! $bump && $labels->contains('new-provider')) { |
| 69 | + $bump = 'new-provider'; |
| 70 | + } |
64 | 71 | } |
65 | 72 |
|
66 | | -if (! $bump || ! in_array($bump, ['major', 'minor', 'patch'])) { |
| 73 | +if (! $bump || ! in_array($bump, ['major', 'minor', 'patch', 'new-provider'])) { |
67 | 74 | echo "No release label found on PR, skipping\n"; |
68 | 75 | exit(0); |
69 | 76 | } |
|
103 | 110 | $response = $http->get(sprintf('/repos/%s/%s/releases/latest', $org, $repo)); |
104 | 111 | $latest = $response->successful() ? $response->json('tag_name') : null; |
105 | 112 |
|
106 | | - if (! $latest) { |
107 | | - echo sprintf("[release] No existing release for %s, starting at 1.0.0\n", $repo); |
| 113 | + if ($bump === 'new-provider' || ! $latest) { |
108 | 114 | $newVersion = '1.0.0'; |
| 115 | + echo sprintf("[release] Initial release for %s at %s\n", $repo, $newVersion); |
109 | 116 | } else { |
110 | 117 | $newVersion = bumpVersion(ltrim($latest, 'v'), $bump, $parser); |
111 | 118 | } |
112 | 119 |
|
113 | 120 | echo sprintf("[release] %s: %s -> %s\n", $repo, $latest ?? 'none', $newVersion); |
114 | 121 |
|
| 122 | + $body = generateReleaseBody($newVersion, $latest, $pr, $repository); |
| 123 | + |
115 | 124 | $response = $http->post(sprintf('/repos/%s/%s/releases', $org, $repo), [ |
116 | 125 | 'tag_name' => $newVersion, |
117 | 126 | 'target_commitish' => 'master', |
118 | 127 | 'name' => $newVersion, |
119 | | - 'body' => sprintf('Release %s', $newVersion), |
| 128 | + 'body' => $body, |
120 | 129 | ]); |
121 | 130 |
|
122 | 131 | if ($response->failed()) { |
|
130 | 139 |
|
131 | 140 | echo "All releases complete.\n"; |
132 | 141 |
|
| 142 | +function generateReleaseBody(string $newVersion, ?string $previousVersion, ?array $pr, string $repository): string |
| 143 | +{ |
| 144 | + $lines = ["## What's Changed"]; |
| 145 | + |
| 146 | + if ($pr) { |
| 147 | + $lines[] = sprintf( |
| 148 | + '* %s by @%s in https://github.com/%s/pull/%d', |
| 149 | + $pr['title'], |
| 150 | + $pr['user']['login'], |
| 151 | + $repository, |
| 152 | + $pr['number'] |
| 153 | + ); |
| 154 | + } |
| 155 | + |
| 156 | + if ($previousVersion) { |
| 157 | + $lines[] = ''; |
| 158 | + $lines[] = sprintf('**Full Changelog**: https://github.com/%s/compare/%s...%s', $repository, $previousVersion, $newVersion); |
| 159 | + } |
| 160 | + |
| 161 | + return implode("\n", $lines); |
| 162 | +} |
| 163 | + |
133 | 164 | function bumpVersion(string $version, string $type, VersionParser $parser): string |
134 | 165 | { |
135 | 166 | $normalized = $parser->normalize($version); |
|
0 commit comments