Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make hooks bash 3.2 compatible #339

Merged
merged 1 commit into from
Mar 31, 2022
Merged

Conversation

MaxymVlasov
Copy link
Collaborator

@MaxymVlasov MaxymVlasov commented Feb 10, 2022

Put an x into the box if that apply:

  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • This PR enhances existing functionality.

Description of your changes

In new versions, macOS use zsh by default and include bash 3.2 for compatibility reasons.
That OS will never upgrade bash to 4+, during license issues.
theverge.com/2019/6/4/18651872/apple-macos-catalina-zsh-bash-shell-replacement-features

So looks like we need to maintain compatibility with bash 3.2 🙄
Or require bash 4.2+ as deps.

Fixes #337

How can we test changes

Run on macOS:

repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
  rev: 48bc03ca3f0f2f782d2f430069868019a6892062
  hooks:
    - id: terraform_fmt

@yermulnik
Copy link
Collaborator

yermulnik commented Feb 10, 2022

ℹ️ IMHO: we EITHER officially declare support for Bash 3 and hence test every change using Bash 3 as well as modern Bash OR we set Bash >= 4 as a requirement for pre-commit-terraform and don't add more toil.

@antonbabenko
Copy link
Owner

@yermulnik I agree that toil is bad here but I am also not sure how hard it is for users to install Bash 4+ on various systems where pre-commit is executed.

@MaxymVlasov MaxymVlasov force-pushed the GH-337/bash3.2_compatible branch from 48bc03c to 42d04a1 Compare February 10, 2022 20:52
@yermulnik
Copy link
Collaborator

yermulnik commented Feb 10, 2022

@antonbabenko From my knowledge it's either very old and outdated version of existing distros, or MacOS only. The latter has at least four more or less easy and more or less user friendly and/or widely used ways to upgrade to a modern version of Bash.
I also would like to mention there are OSes where Bash is not installed by default either. Should we support these OSes as well relying only on fully POSIX-compatible shell features and utilities?

If we'd support outdated version of Bash for only one "brand" of OS, someone may also ask us to provide support for e.g. non-Bash shells (there are a plenty of and zsh and fish are only a few of them which are widely used) or for embedded systems where the base system misses a lot of OS or shell tools and features.

@yermulnik
Copy link
Collaborator

Also those systems which lack modern Bash (and any other tool used by pre-commit and pre-commit-terraform to bring the best UX and functionality) should probably consider looking into using pre-commit-terraform as Docker container — it seems the only sensible meaning for maintaining this Docker image, eh?

@pshamus
Copy link

pshamus commented Feb 11, 2022

Also those systems which lack modern Bash (and any other tool used by pre-commit and pre-commit-terraform to bring the best UX and functionality) should probably consider looking into using pre-commit-terraform as Docker container — it seems the only sensible meaning for maintaining this Docker image, eh?

@yermulnik That isn't going to scale well in organizations where not everyone has Docker installed.

I understand the sentiment not wanting to have to support old versions of bash. However, this should be introduced as a breaking change. We have hundreds of projects using these hooks and to all of the sudden now require them to install an updated version of bash (and hope they got it right) is a big burden.

@yermulnik
Copy link
Collaborator

@pshamus

(apologies for long-read)

We have hundreds of projects using these hooks and to all of the sudden now require them to install an updated version of bash

It is not about the number of projects, but about the number of engineers.
If you have hundreds engineers who work with at least one repository with pre-commit enabled and who use company-managed macos-based laptops, you may want to leverage packaging automation and mass-installing (e.g. https://github.com/scriptingosx/GNU-bash-mac-installer).
If this is about a dozen of engineers working with hundreds of projects, they most probably already use Homebrew or MacPorts. Or at least they may be interested to start using it, as it's a one of the 1st things engineers would want on the freshly installed macos since macos ships with a plenty of quite old tools in base.

And yep, I fully agree such a change should have been announced in advance along with proper semantic versioning for changes with backward incompatibility.

As I already stated before, my personal opinion (I'm not founder or owner, I'm collaborator) is we either revisit this entire repo and convert it to become fully POSIX-compliant so that we rely upon /bin/sh on every single POSIX-compliant system (what to do with those which are not? 🤔), or we drop support for ancient versions (not old, but ancient) of required tools and continue developing this project and comply with modern toolset.

ps: one of the main reasons against bash3 support would be the need to maintain and test every single change and release with bash3 which is not impossible, but, you know, «That isn't going to scale well in organizations where not everyone has Docker installed» — I see Docker as the only sensible approach to run bash3 w/o littering our workstations with ancient software and quirks to temporarily fool local environment about which bash version should come up via /usr/bin/env bash 😉

@MaxymVlasov MaxymVlasov marked this pull request as ready for review February 23, 2022 14:49
@MaxymVlasov
Copy link
Collaborator Author

MaxymVlasov commented Feb 23, 2022

@antonbabenko let's fix breaking changes introduced in v1.63 for some Mac users, by merging that PR.
Got confirmation in #337 (comment) that the code works fine.

@yermulnik could you please check in a week, how much effort need to make code POSIX-compatible?
If it needs from us to rewrite too much stuff or make code unreadable, I suppose to officially break support for bash <4.2 in v2.0.0

@yermulnik
Copy link
Collaborator

yermulnik commented Feb 23, 2022

@yermulnik could you please check in a week, how much effort need to make code POSIX-compatible?

Do we have any plans to switch to /bin/sh instead of relying on bash?
Otherwise it doesn't make any sense to even look into making in strictly POSIX-compatible/compliant.

What's needed to make code compatible with Bash v3 I (by a surprising coincident) already described in #337 (comment) today 😃 Let me know if that's what you mean.

I suppose to officially break support for bash <4.2 in v2.0.0

That's definitely the way to go w/o any constraints: we should drop support of ancient Bash in whichever major release of pre-commit-terraform 👍🏻

@MaxymVlasov
Copy link
Collaborator Author

Do we have any plans to switch to /bin/sh instead of relying on bash?

If it is not too difficult - why not

@yermulnik
Copy link
Collaborator

Do we have any plans to switch to /bin/sh instead of relying on bash?

If it is not too difficult - why not

This may make sense, btw. Though we need to inspect our code and ensure it complies to POSIX standard and rip off any bashisms including those that belong to bash 3.
We can start with leveraging e.g. https://github.com/duggan/shlint (or any other alike tool) to test compatibility and (if possible) create GH action to run this tool on PRs/commits in container with most common /bin/sh implementations installed (zsh ksh bash dash sh).

@antonbabenko antonbabenko merged commit 4ad825d into master Mar 31, 2022
@antonbabenko antonbabenko deleted the GH-337/bash3.2_compatible branch March 31, 2022 12:38
antonbabenko pushed a commit that referenced this pull request Mar 31, 2022
## [1.64.1](v1.64.0...v1.64.1) (2022-03-31)

### Bug Fixes

* Make hooks bash 3.2 compatible ([#339](#339)) ([4ad825d](4ad825d))
@antonbabenko
Copy link
Owner

This PR is included in version 1.64.1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v1.63.0 broken on Mac (bash 3.2)
4 participants