|
| 1 | +# Contributing to the PHP Elasticsearch Client |
| 2 | + |
| 3 | +If you have a bugfix or new feature that you would like to contribute to |
| 4 | +elasticsearch-php, please find or open an issue about it first. Talk about what |
| 5 | +you would like to do. It may be that somebody is already working on it, or that |
| 6 | +there are particular issues that you should know about before implementing the |
| 7 | +change. |
| 8 | + |
| 9 | +We enjoy working with contributors to get their code accepted. There are many |
| 10 | +approaches to fixing a problem and it is important to find the best approach |
| 11 | +before writing too much code. |
| 12 | + |
| 13 | +## Running Elasticsearch locally |
| 14 | + |
| 15 | +We've provided a script to start an Elasticsearch cluster of a certain version |
| 16 | +found at `.buildkite/run-elasticsearch.sh`. |
| 17 | + |
| 18 | +There are several environment variables that control integration tests: |
| 19 | + |
| 20 | +- `TEST_SUITE`: `free` or `platinum` for running Elasticsearch in different |
| 21 | + versions. |
| 22 | +- `STACK_VERSION`: Version of Elasticsearch to use. These should be |
| 23 | + the same as tags of `docker.elastic.co/elasticsearch/elasticsearch` |
| 24 | + such as `8.0.0-SNAPSHOT`, `7.x-SNAPSHOT`, etc. Defaults to the |
| 25 | + same `*-SNAPSHOT` version as the branch. |
| 26 | + |
| 27 | +**NOTE: You don't need to run the live integration tests for all changes. If |
| 28 | +you don't have Elasticsearch running locally the integration tests will be skipped.** |
| 29 | + |
| 30 | +## API Code Generation |
| 31 | + |
| 32 | +All API methods in `src/Endpoints` and in `src/Traits/ClientEndpointsTrait.php` are |
| 33 | +automatically generated from the [Elasticsearch specification](https://github.com/elastic/elasticsearch-specification) |
| 34 | +and [rest-api-spec](https://github.com/elastic/elasticsearch/tree/master/rest-api-spec/src/main/resources/rest-api-spec/api). |
| 35 | + |
| 36 | +You can check if a PHP file has been generated searching for `@generated` tag |
| 37 | +in the source code (e.g. [here](https://github.com/elastic/elasticsearch-php/blob/main/src/Traits/ClientEndpointsTrait.php#L27) |
| 38 | +in the `ClientEndpointsTrait.php`). |
| 39 | + |
| 40 | +Any changes to these files should be avoid, you can submit to the Elasticsearch |
| 41 | +specification project and will be imported the next time the client will be generated. |
| 42 | +The generator itself is currently a private project. |
| 43 | + |
| 44 | +## Contributing Code Changes |
| 45 | + |
| 46 | +The process for contributing to any of the Elasticsearch repositories is similar. |
| 47 | + |
| 48 | +1. Please make sure you have signed the [Contributor License |
| 49 | + Agreement](http://www.elastic.co/contributor-agreement/). We are not |
| 50 | + asking you to assign copyright to us, but to give us the right to distribute |
| 51 | + your code without restriction. We ask this of all contributors in order to |
| 52 | + assure our users of the origin and continuing existence of the code. You only |
| 53 | + need to sign the CLA once. |
| 54 | + |
| 55 | +2. Run the linter and test suite to ensure your changes do not break existing code. |
| 56 | + Run the last optional step only if you want to test your changes with the |
| 57 | + integration tests. You need to specify the `STACK_VERSION` of Elasticsearch (e.g. |
| 58 | + `8.17.0`), you can check the Elasticsearch versions [here](https://github.com/elastic/elasticsearch/releases). |
| 59 | + |
| 60 | + ``` |
| 61 | + # Run PHPStan, see https://phpstan.org/ |
| 62 | + $ composer run-script phpstan |
| 63 | + |
| 64 | + # Run the unit tests |
| 65 | + $ composer run-script test |
| 66 | + |
| 67 | + # Run the integration tests (optional) |
| 68 | + $ STACK_VERSION="8.17.0" .buildkite/run-tests |
| 69 | + ``` |
| 70 | + |
| 71 | +3. Rebase your changes. |
| 72 | + Update your local repository with the most recent code from the main |
| 73 | + elasticsearch-php repository, and rebase your branch on top of the latest branch. |
| 74 | + If you want to propose a change in the latest version, you need to use the `main` |
| 75 | + branch. If you are proposing for `8.x` version you should use the latest |
| 76 | + minor branch (e.g. `8.17`). If want to propose a change for the oldest versions |
| 77 | + you need to use the `7.17` or `6.8.x` branches. Remember, we support only the latest |
| 78 | + minor of the previous majour. For instance, if the latest version is `8.x` we |
| 79 | + support the last minor of `7.x` (i.e. `7.17`). |
| 80 | + We prefer your changes to be squashed into a single commit for easier |
| 81 | + backporting. |
| 82 | + |
| 83 | +4. Submit a pull request. Push your local changes to your forked copy of the |
| 84 | + repository and submit a pull request. In the pull request, describe what your |
| 85 | + changes do and mention the number of the issue where discussion has taken |
| 86 | + place, eg “Closes #123″. Please consider adding or modifying tests related to |
| 87 | + your changes. |
| 88 | + |
| 89 | +Then sit back and wait. There will probably be a discussion about the pull |
| 90 | +request and, if any changes are needed, we would love to work with you to get |
| 91 | +your pull request merged into elasticsearch-php. |
| 92 | + |
| 93 | +Thanks in advance for all your future contributions! |
0 commit comments