Skip to content

Commit 97e8ad2

Browse files
committed
feat: add ability to output candidate releases
In order to enable this new feature, I've added a new input called `only` that allows running only the desired functionality (`'create-github-releases' | 'list-candidate-releases' | 'update-pull-requests'`). It is backwards compatible with the `skipGitHubRelease` and `skipGitHubPullRequest` inputs.
1 parent d1a8f22 commit 97e8ad2

File tree

3 files changed

+69
-14
lines changed

3 files changed

+69
-14
lines changed

README.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ steps:
8181
| `fork` | If `true`, send the PR from a fork. This requires the `token` to be a user that can create forks (e.g. not the default `GITHUB_TOKEN`) |
8282
| `include-component-in-tag` | If true, add prefix to tags and branches, allowing multiple libraries to be released from the same repository |
8383
| `proxy-server` | Configure a proxy servier in the form of `<host>:<port>` e.g. `proxy-host.com:8080` |
84-
| `skip-github-release` | If `true`, do not attempt to create releases. This is useful if splitting release tagging from PR creation. |
85-
| `skip-github-pull-request` | If `true`, do not attempt to create release pull requests. This is useful if splitting release tagging from PR creation. |
84+
| `only` | If `create-github-releases`, only attempt to create releases. This is useful if splitting release tagging from PR creation. If `update-pull-requests` only attempt to create release pull requests. If `list-candidate-releases`, only output information about which packages would be released. |
8685

8786
## GitHub Credentials
8887

@@ -167,6 +166,13 @@ New types of releases can be [added here](https://github.com/googleapis/release-
167166
| `pr` | A JSON string of the [PullRequest object](https://github.com/googleapis/release-please/blob/main/src/pull-request.ts#L15) (unset if no release created) |
168167
| `prs` | A JSON string of the array of [PullRequest objects](https://github.com/googleapis/release-please/blob/main/src/pull-request.ts#L15) (unset if no release created) |
169168

169+
> When used with `only: 'list-candidate-releases'`, the following properties are available.
170+
171+
| output | description |
172+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
173+
| `releases_pending` | `true` if any release is pending, `false` otherwise |
174+
| `paths_to_release` | A JSON string of the array of paths that have releases pending (`[]` if ) |
175+
170176
### Root component outputs
171177

172178
If you have a root component (path is `.` or unset), then the action will also output:
@@ -381,10 +387,10 @@ If you were setting the `command` option, you will likely need to modify your co
381387

382388
| Command | New Configuration | Description |
383389
| ---------------- | ---------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
384-
| `github-release` | `skip-github-pull-request: true` | This command was used for only tagging releases. Now we tell release-please to skip opening release PRs. |
385-
| `release-pr` | `skip-github-release: true` | This command was used for only opening release PRs. Now we tell release-please to skip tagging releases. |
386-
| `manifest` | do not set `release-type` option | This command told release-please to use a manifest config file. This is now the default behavior unless you explicitly set a `release-type`. |
387-
| `manifest-pr` | `skip-github-release: true` and do not set `release-type` option | This command told release-please to use a manifest config file and only open the pull reuqest. |
390+
| `github-release` | `only: 'create-github-releases'` | This command was used for only tagging releases. Now we tell release-please to skip opening release PRs. |
391+
| `release-pr` | `only: 'update-pull-requests'` | This command was used for only opening release PRs. Now we tell release-please to skip tagging releases. |
392+
| `manifest` | do not set `release-type` option | This command told release-please to use a manifest config file. This is now the default behavior unless you explicitly set a `release-type`. |
393+
| `manifest-pr` | `only: 'update-pull-requests'` and do not set `release-type` option | This command told release-please to use a manifest config file and only open the pull reuqest. |
388394

389395
### Package options
390396

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,15 @@ inputs:
5454
description: 'if set to true, then do not try to tag releases'
5555
required: false
5656
default: false
57+
deprecationMessage: 'Use only=update-pull-requests instead.'
5758
skip-github-pull-request:
5859
description: 'if set to true, then do not try to open pull requests'
5960
required: false
6061
default: false
62+
deprecationMessage: 'Use only=create-github-releases instead.'
63+
only:
64+
description: "one of 'create-github-releases' | 'list-candidate-releases' | 'update-pull-requests' or empty to run all"
65+
required: false
6166
changelog-host:
6267
description: 'The proto://host where commits live. Default `https://github.com`'
6368
required: false

src/index.ts

+52-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as core from '@actions/core';
16-
import {GitHub, Manifest, CreatedRelease, PullRequest, VERSION} from 'release-please';
16+
import {GitHub, Manifest, CreatedRelease, PullRequest, VERSION, type CandidateRelease} from 'release-please';
1717

1818
const DEFAULT_CONFIG_FILE = 'release-please-config.json';
1919
const DEFAULT_MANIFEST_FILE = '.release-please-manifest.json';
@@ -39,12 +39,15 @@ interface ActionInputs {
3939
targetBranch?: string;
4040
skipGitHubRelease?: boolean;
4141
skipGitHubPullRequest?: boolean;
42+
only?: 'create-github-releases' | 'list-candidate-releases' | 'update-pull-requests';
4243
fork?: boolean;
4344
includeComponentInTag?: boolean;
4445
changelogHost: string;
4546
}
4647

4748
function parseInputs(): ActionInputs {
49+
const skipGitHubRelease = getOptionalBooleanInput('skip-github-release');
50+
const skipGitHubPullRequest = getOptionalBooleanInput('skip-github-pull-request');
4851
const inputs: ActionInputs = {
4952
token: core.getInput('token', {required: true}),
5053
releaseType: getOptionalInput('release-type'),
@@ -58,8 +61,15 @@ function parseInputs(): ActionInputs {
5861
(core.getInput('github-graphql-url') || '').replace(/\/graphql$/, '') ||
5962
DEFAULT_GITHUB_GRAPHQL_URL,
6063
proxyServer: getOptionalInput('proxy-server'),
61-
skipGitHubRelease: getOptionalBooleanInput('skip-github-release'),
62-
skipGitHubPullRequest: getOptionalBooleanInput('skip-github-pull-request'),
64+
only:
65+
(core.getInput('only') as ActionInputs['only']) ||
66+
(skipGitHubRelease && !skipGitHubPullRequest
67+
? 'update-pull-requests'
68+
: !skipGitHubRelease && skipGitHubPullRequest
69+
? 'create-github-releases'
70+
: skipGitHubRelease && skipGitHubPullRequest
71+
? 'list-candidate-releases'
72+
: undefined),
6373
fork: getOptionalBooleanInput('fork'),
6474
includeComponentInTag: getOptionalBooleanInput('include-component-in-tag'),
6575
changelogHost: core.getInput('changelog-host') || DEFAULT_GITHUB_SERVER_URL,
@@ -119,14 +129,19 @@ export async function main() {
119129
const inputs = parseInputs();
120130
const github = await getGitHubInstance(inputs);
121131

122-
if (!inputs.skipGitHubRelease) {
123-
const manifest = await loadOrBuildManifest(github, inputs);
124-
core.debug('Creating releases');
132+
const manifest = await loadOrBuildManifest(github, inputs);
133+
134+
if (inputs.only === 'list-candidate-releases') {
135+
core.debug('Listing pending releases');
136+
outputCandidateReleases(await manifest.buildReleases());
137+
}
138+
139+
if (inputs.only === 'create-github-releases' || !inputs.only) {
140+
core.debug('Creating github releases');
125141
outputReleases(await manifest.createReleases());
126142
}
127143

128-
if (!inputs.skipGitHubPullRequest) {
129-
const manifest = await loadOrBuildManifest(github, inputs);
144+
if (inputs.only === 'update-pull-requests' || !inputs.only) {
130145
core.debug('Creating pull requests');
131146
outputPRs(await manifest.createPullRequests());
132147
}
@@ -196,6 +211,35 @@ function outputReleases(releases: (CreatedRelease | undefined)[]) {
196211
core.setOutput('paths_released', JSON.stringify(pathsReleased));
197212
}
198213

214+
function outputCandidateReleases(releases: CandidateRelease[]) {
215+
releases = releases.filter(release => release !== undefined);
216+
const pathsReleased = [];
217+
core.setOutput('releases_pending', releases.length > 0);
218+
if (releases.length) {
219+
for (const release of releases) {
220+
if (!release) {
221+
continue;
222+
}
223+
const path = release.path || '.';
224+
if (path) {
225+
pathsReleased.push(path);
226+
// If the special root release is set (representing project root)
227+
// and this is explicitly a manifest release, set the release_created boolean.
228+
setPathOutput(path, 'release_pending', true);
229+
}
230+
if (release.tag) {
231+
// Historically tagName was output as tag_name, keep this
232+
// consistent to avoid breaking change:
233+
setPathOutput(path, 'tag_name', release.tag.toString());
234+
setPathOutput(path, 'body', release.notes)
235+
}
236+
}
237+
}
238+
// Paths of all releases that were created, so that they can be passed
239+
// to matrix in next step:
240+
core.setOutput('paths_to_release', JSON.stringify(pathsReleased));
241+
}
242+
199243
function outputPRs(prs: (PullRequest | undefined)[]) {
200244
prs = prs.filter(pr => pr !== undefined);
201245
core.setOutput('prs_created', prs.length > 0);

0 commit comments

Comments
 (0)