Skip to content

Commit

Permalink
fix: undo breaking change in releases_created output
Browse files Browse the repository at this point in the history
An undocumented breaking change slipped into the v4 release which causes
the conditional in actions to stop working as documented.

In v3 the following step would only run if no releases were created. In
v4 the action will still run:

```yml
- run: echo "releases happened"
  if: ${{ steps.release.outputs.releases_created }}
```

This is because the @actions/core npm package `core.setOutput` method
always casts values to a string, so when we call the following:

```js
core.setOutput('releases_created', releases.length > 0);
```

The output of the action will always either be `"true"` or `"false"` as
a string. This is a problem because our `if` statement above will always
evaluate this to `true` and run the conditional step.

The only reason this worked in v3 is because the `core.setOutput` was
called only if `releases.length` was greater than zero rather than being
passed the condition.

  * [Relevant v3 code](https://github.com/google-github-actions/release-please-action/blob/db8f2c60ee802b3748b512940dde88eabd7b7e01/index.js#L223-L224)

  * [Equivalent v4 code](https://github.com/google-github-actions/release-please-action/blob/cc61a07e2da466bebbc19b3a7dd01d6aecb20d1e/src/index.ts#L165)

So in v3 the possible values for `releases_created` was actually
`"true"` or `undefined`. This was never an issue because `"true"` is
truthy and `undefined` is falsy so the conditions in our actions worked
as expected.

I've moved the `releases_created` output back inside the conditional to
switch the behaviour to match `v3`.
  • Loading branch information
rowanmanning committed Dec 19, 2023
1 parent cc61a07 commit c68257e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116382,8 +116382,8 @@ function setPathOutput(path, key, value) {
function outputReleases(releases) {
releases = releases.filter(release => release !== undefined);
const pathsReleased = [];
core.setOutput('releases_created', releases.length > 0);
if (releases.length) {
core.setOutput('releases_created', true);
for (const release of releases) {
if (!release) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ function setPathOutput(path: string, key: string, value: string | boolean) {
function outputReleases(releases: (CreatedRelease | undefined)[]) {
releases = releases.filter(release => release !== undefined);
const pathsReleased = [];
core.setOutput('releases_created', releases.length > 0);
if (releases.length) {
core.setOutput('releases_created', true);
for (const release of releases) {
if (!release) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion test/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ describe('release-please-action', () => {
assert.strictEqual(Object.hasOwnProperty.call(output, 'pr'), false);
assert.deepStrictEqual(output.paths_released, '[]');
assert.deepStrictEqual(output.prs_created, false);
assert.deepStrictEqual(output.releases_created, false);
assert.deepStrictEqual(output.releases_created, undefined);
});
});
});

0 comments on commit c68257e

Please sign in to comment.