conventional-changelog / conventional-changelog/commitlint-orb

exit code 141 for PRs with many commits due to `pipefail`

Open
#10 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Shell
Stars
4
Forks
2
PR merge metrics
No merged PRs in 30d

Description

## Orb version: 1.0.0

## What happened:

When opening a PR with many commits (~400, in my case, due to importing another repo), the orb fails more or less silently with an exit code 141.
The underlying reason for this is that CircleCI runs `/bin/bash -eo pipefail` as the default shell, with which the [lint script](https://github.com/conventional-changelog/commitlint-orb/blob/main/src/scripts/lint.sh) is being invoked.

Then, [this command](https://github.com/conventional-changelog/commitlint-orb/blob/1f52133864cf68554f8abc973c5c2f35849fd7dc/src/scripts/lint.sh#L22) fails because it's using `head`, which closes the (reading end of) the pipe before `git cherry` returned all the data, which makes the whole pipeline fail.

This only happens for PRs with many commits, as otherwise `git cherry` returns before `head` closes the pipe.

There's a couple of different options to mitigate the issue:
- The orb could specify the `shell` parameter in it's [`run` block](https://github.com/conventional-changelog/commitlint-orb/blob/1f52133864cf68554f8abc973c5c2f35849fd7dc/src/jobs/lint.yml#L31) and set it to something like `/bin/bash` only. This will turn off `pipefail` globally.
- The script itself could turn off `pipefail` with a `set +o pipefail` anywhere within the script, potentially even right before the [offending line](https://github.com/conventional-changelog/commitlint-orb/blob/1f52133864cf68554f8abc973c5c2f35849fd7dc/src/scripts/lint.sh#L22), and potentially also turn it on again directly afterwards with a `set -o pipefail`
- The script could use a different command than `head`, one that doesn't close the pipe before all data is read. For example, [`sed` could be used](https://stackoverflow.com/questions/62322597/how-to-use-head-in-a-script-with-pipefail-enabled).

I'm happy to open a PR for any of these, but wanted to inquire as to if there's any preference for the solution!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.