Limit for Object Filter or join in expression syntax

I’m currently using the Object Filter as documented here

and use something like this in my GitHub workflow

${{ join(github.event.commits.*.message, '\n') }}

Unfortunately this could be too long some times and was wondering if there are is a way to limit the number of entries rather than picking all of them?

I think the workaround is to feed the output in bash and filter it there using head/tail depending on the need.

GitHub actions expressions are pretty limited. There are no functions to get a slice of an array or a language construct to iterate over an array.

While a shell script would be possible, I would rather use or write an action for that. Should be much easier with JavaScript to manipulate. You may even use an inline action using github-script.

Another option – if you only want let’s say the first 5 commits – might be to hardcode it like below (haven’t tested it)

${{ join(fromJSON(format('[{0},{1},{2},{3},{4}]',
  toJSON(github.event.commits[0].message),
  toJSON(github.event.commits[1].message),
  toJSON(github.event.commits[2].message),
  toJSON(github.event.commits[3].message),
  toJSON(github.event.commits[4].message)
)), '\n') }}