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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extensions to be compiled from GitHub sources #399

Merged

Conversation

alcaeus
Copy link
Contributor

@alcaeus alcaeus commented Jan 21, 2021


name: 馃帀 New Feature
about: Allow extensions to be compiled from GitHub sources
labels: enhancement


A Pull Request should be associated with a Discussion.

Note: no discussion available as I built this for my own needs and want to start a discussion based on the changes I made.

Description

This PR allows installing extensions from source. This is done by using a special extension format of the form <extension>-<org>/<repo>@<version>. Currently, only GitHub is supported and the repository is checked out using git clone --recurse-submodules -b <version> https://github.com/<org>/<repo>. This is supported on Linux and OSX, but not on Windows environments.

The rationale for adding this was that I didn't want to have separate steps depending on what extension version to install. This way, I can provide the repository URL and branch name as version string, allowing installing stable versions and compiling from source in a single step in a matrix. This was inspired by the leftover install_extension_from_source, which this PR also removes as it's unused (and replaced by this PR).

  • I have written test cases for the changes in this pull request
  • I have run npm run format before the commit.
  • I have run npm run lint before the commit.
  • I have run npm run release before the commit.
  • npm test returns with no unit test errors and all code covered.
  • I have checked the edited scripts for syntax.
  • I have tested the changes in an integration test (linux only, can run on OSX separately): https://github.com/alcaeus/mongo-php-library/runs/1741774149 (also, please ignore the PHPUnit failure - that is unrelated).

Further discussion

  • Should we allow passing commit hashes as well? This is not supported due to using git clone but could be supported as well.
  • Should we provide way for users to customise the build, e.g. arguments to pass to configure? If so, this might require more changes to the action (including potentially changing the format of the extensions input)
  • I have yet to figure out whether this will play nice with shivammathur/cache-extensions. I assume there will be issues if somebody installed ext-org/repo@master and the commit hash changes before the cache is invalidated. This needs documentation at the very least. This can be worked around by supporting commit hashes (see above).

Let me know if you have any concerns about adding this, I'm happy to talk about potential alternatives.

@shivammathur shivammathur added the enhancement New feature or request label Jan 21, 2021
src/scripts/darwin.sh Outdated Show resolved Hide resolved
dist/index.js Outdated Show resolved Hide resolved
src/extensions.ts Outdated Show resolved Hide resolved
@shivammathur
Copy link
Owner

shivammathur commented Jan 21, 2021

@alcaeus Thanks for working on this. Installing extensions from source was on the roadmap. 馃殌

  • Yes, it would be a good idea to support commit hashes as well.
  • I do not think it would be a good API if in extensions input, users are allowed to pass configuration arguments. An alternative would be checking for an env variable say MONGODB_CONFIGURE_ARGS for mongodb extension.
  • Another improvement can be checking for required libraries in env variable MONGODB_LIBS.
  • As there is no check in add_extension_from_github to see if extension is already in extension_dir, extensions cached by extensions-cache will be overwritten by new compiled one.

@jmikola
Copy link

jmikola commented Jan 22, 2021

An alternative would be checking for an env variable say MONGODB_CONFIGURE_ARGS for mongodb extension.

@shivammathur that sounds like a great idea, as it presumably makes it much easier to customize configure args via the build matrix. Granted, we're more likely to want to do that for the extension's own builds than a consuming library, but still nice to have the option.

@shivammathur shivammathur added this to In progress in setup-php-tasks Jan 22, 2021
@alcaeus
Copy link
Contributor Author

alcaeus commented Jan 25, 2021

@shivammathur thanks for your feedback. I've applied the suggestions from code review. Please let me know if the checks in extensions.ts can be simplified - I'm not entirely happy with the duplicate regex evaluation, especially since that code can't be covered.

  • I've changed add_extension_from_github to accept a commit hash as well. Anything accepted by git checkout is now fair game as a version.
  • I've played around with supporting <ext_name>_CONFIGURE_ARGS - this isn't a lot of effort but the question remains whether we want a common solution for all extensions or whether extensions should take care of this themselves.
  • An optional LIBS env var is possible, but I wonder if it would be more sensible for users to fill build dependencies themselves
  • Skipping the cache is fine for now. I checked how this is handled for pecl, and since the only "version" we can reliably use is a commit hash which is lost after installing, extensions are always rebuilt from source, even if the cache restored them. I can revisit this separately if we want the cache to pick up source builds as well.

@shivammathur
Copy link
Owner

shivammathur commented Jan 25, 2021

@alcaeus Awesome,

  • You can remove the if(matches == null) blocks in extension.ts as those are unreachable. That should fix the coverage.
  • Support for args and libs is not required and can be added in future. I'm happy to merge this PR without that.
  • Support for cache can be added, since the cache key depends on the extensions input, it would invalidate when commit sha or version changes in the workflow. (https://github.com/shivammathur/cache-extensions/blob/master/src/extensions.sh#L95)

@alcaeus
Copy link
Contributor Author

alcaeus commented Jan 31, 2021

@shivammathur Just a heads up, it will be a few days before I can return to this. I haven't forgotten but have to rest for a few days.

@shivammathur
Copy link
Owner

@alcaeus Take your time. Hope you are feeling well.

@alcaeus alcaeus force-pushed the allow-github-extension-installs branch from 8173e70 to 19593b9 Compare February 8, 2021 12:35
@alcaeus
Copy link
Contributor Author

alcaeus commented Feb 8, 2021

@shivammathur thanks! I've rebased on develop and removed the superfluous if statements. I'll take a look at cache next, but believe that the PR can be merged as-is.

@shivammathur shivammathur merged commit c6d8f7d into shivammathur:develop Feb 8, 2021
@shivammathur shivammathur moved this from In progress to Done in setup-php-tasks Feb 11, 2021
@shivammathur shivammathur added this to the 2.10.0 milestone Feb 16, 2021
shivammathur added a commit that referenced this pull request Feb 19, 2021
Allow extensions to be compiled from GitHub sources
shivammathur added a commit that referenced this pull request Feb 19, 2021
Allow extensions to be compiled from GitHub sources
shivammathur added a commit that referenced this pull request Feb 19, 2021
Allow extensions to be compiled from GitHub sources
@alcaeus alcaeus deleted the allow-github-extension-installs branch April 13, 2021 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants