fix: undo breaking change in releases_created output #915
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The issue this fixes
An undocumented breaking change slipped into the v4 release which causes the conditional in actions to stop working as documented. I encountered it when migrating some of my projects and an issue has already been opened (#912).
In v3 the following step would only run if releases were created. In v4 the action will always run:
This is because the
@actions/core
npm packagecore.setOutput
method always casts values to a string, so when we call the following:The output of the action will always either be
"true"
or"false"
as a string. This is a problem because ourif
statement above will always evaluate this totrue
and run the conditional step.The only reason this worked in v3 is because the
core.setOutput
was called only ifreleases.length
was greater than zero rather than being passed the condition.Relevant v3 code
Equivalent v4 code
So in v3 the possible values for
releases_created
was actually"true"
orundefined
. This was never an issue because"true"
is truthy andundefined
is falsy so the conditions in our actions worked as expected.Approach
I've moved the
releases_created
output back inside the conditional to switch the behaviour to matchv3
.Alternatives
If you're not happy with this change then I think the documentation should be updated to highlight this gotcha and the changelog for v4 should include it.
Potential additional work
core.setOutput
casting to a string has been noted in issues in the@actions/core
repo before, but all the documentation on this action indicates that outputs are set totrue
orfalse
. It might be worth changing this documentation to explain that the values are all strings rather than booleans.