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

use git submodules for bats-* instead of globally installed brew packages #36

Closed
hanoii opened this issue Oct 11, 2024 · 22 comments
Closed

Comments

@hanoii
Copy link

hanoii commented Oct 11, 2024

In working on ddev/ddev-drupal-contrib#85 I wanted to use bats-support and bats-assert.

I started wondering how to use them.

I am on mac and with brew info kaos/shell/bats-assert

I get

To load the bats-assert lib in your bats test:

    load '/opt/homebrew/lib/bats-support/load.bash'
    load '/opt/homebrew/lib/bats-assert/load.bash'

Ok there. Because this action uses homebrew for linux as well, I'd assume this might work, however, it is still a bit dependent on the system, and a bit cryptic, so I was thinking on a potentially better alternative:

Use git submodules: https://bats-core.readthedocs.io/en/stable/tutorial.html#quick-installation

I am not 100% sure of the implications, but I think very little, from what I gather:

  • the documentation for setting up tests on https://github.com/ddev/ddev-addon-template needs to be updated, namely one would have to manually run git submodules init
  • This action needs to add submodules: true to the checkout action
  • In order to provide backwards compatibility, bats should still be installed globally by this action, but maybe check for a bats-core submodule somehow, this can be as simple as adding ./tests/bats/bin to the path or something more complex using git submodule commands or parsing of .gitmodules

Thoughts?

@rfay
Copy link
Member

rfay commented Oct 11, 2024

I haven't ever seen anything but pain from git submodules, but have been avoiding them for a long time. If this would mean adding these as submodules of the project under test, I really really wouldn't like it.

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

If this would mean adding these as submodules of the project under test, I really really wouldn't like it.

That exactly what this means.

I am not a fan of git submodules either, and also avoid it at all costs, but this being just for tests, I figured it wasn't too bad.

I can also maybe rely on BATS_LIB_PATH and bats_load_library. But in that case, this action should also set it, and this also will mean adjusting docs.

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

I like the fact that this can be locally and would make this action pretty independent.

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

BATS_LIB_PATH=/opt/homebrew/lib bats -x --show-output-of-passing-tests --verbose-run tests/full.bats

this works with

bats_load_library 'bats-support'
bats_load_library 'bats-assert'

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

I can add that to test_command but I think the action should probably set it.

AND.. I still think we should add submodules: true to the checkout action. or at least provide a configuration option so if one decide to do this, we can

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

Although I think this makes it harder to document and onboard others for running tests locally

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

Just saw disable_checkout_action, I think I can just manage with that, will give submodules a try 🤷🏻

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

See https://github.com/ddev/ddev-drupal-contrib/actions/runs/11296006345/job/31419956642?pr=85

This exemplifies the potential issues:

/home/linuxbrew/.linuxbrew/lib is what need to use on the action instead of /opt/homebrew/lib locally

@rfay
Copy link
Member

rfay commented Oct 11, 2024

This is super easy:

  TEST_BREW_PREFIX="$(brew --prefix)"
  load "${TEST_BREW_PREFIX}/lib/bats-support/load.bash"
  load "${TEST_BREW_PREFIX}/lib/bats-assert/load.bash"
  load "${TEST_BREW_PREFIX}/lib/bats-file/load.bash"

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

what if someone didn't setup bats with homebrew? I guess unlikely

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

You'll know more than me how unlikely that can be, thoughts?

@rfay
Copy link
Member

rfay commented Oct 11, 2024

It's not unlikely for local. It's easy on macOS, easy on Linux amd64. Impossible on Linux arm64. But the other instructions are still there in https://github.com/ztombol/bats-docs?tab=readme-ov-file#installation

Maybe npm is the best way?

I've always been hoping to become more of an expert and more of a fan of bats and these assert libraries, but they still frustrate me also.

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

I still believe for this particular use case, gitsubmodules is the way to go, I will give it a try and see if the maintainer likes it and let you test drive it.

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

I don't like having to relay for npm just for running tests

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

This worked though: ddev/ddev-drupal-contrib@b2ba34c

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

I don't like having to relay for npm just for running tests

Just for running bash tests

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

Well, I actually do like git submodules for this:

https://github.com/ddev/ddev-drupal-contrib/pull/85/checks (not using your homebrew installation at all, even bats-core is a
submodule)

ddev/ddev-drupal-contrib@ee13990

Instructions for running tests locally anywhere are:

  • git submodule init
  • git submodule update
  • ./tests/bats/bin/bats tests

Uses bats-assert

@stasadev
Copy link
Member

This looks good when used for just one repo, but not for many, it increases the maintenance burden, and you need to update them periodically to new commits, which is not needed now.

BTW, submodules can be initialized with one command git submodule update --init --recursive

@hanoii
Copy link
Author

hanoii commented Oct 11, 2024

This looks good when used for just one repo, but not for many, it increases the maintenance burden, and you need to update them periodically to new commits, which is not needed now.

Not sure I understood this, and it's the same as updating any other dependency through any other means (composer, npm, etc..)

BTW, submodules can be initialized with one command git submodule update --init --recursive

Thanks! Will update, I don't need the the recursive part.

@julienloizelet
Copy link
Collaborator

Hi @hanoii,

I saw that you had found it but, reading this:

or at least provide a configuration option so if one decide to do this, we can

this is exactly why the disable_checkout_action input has been added.

I hope that's enough to solve your issue.

Thanks

@hanoii
Copy link
Author

hanoii commented Oct 14, 2024

@julienloizelet yes, I saw it looking at the code, and yes, I am using it and works as expected!

@julienloizelet
Copy link
Collaborator

Thanks @hanoii, I’m closing this issue. Happy to continue the conversation here or elsewhere.

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

No branches or pull requests

4 participants