|
1 | | -# How to become a contributor and submit your own code |
| 1 | +# How to Contribute |
2 | 2 |
|
3 | | -* [Contributor License Agreements](#Contributor-License-Agreements) |
4 | | -* [Contributing a Patch or New Sample](#Contributing-a-Patch) |
5 | | -* [Build Tools](#build-tools) |
6 | | -* [Integration Testing](#testing) |
7 | | -* [Style](#Style) |
| 3 | +We'd love to accept your patches and contributions to this project. There are |
| 4 | +just a few small guidelines you need to follow. |
8 | 5 |
|
9 | | -## Contributor License Agreements |
| 6 | +## Contributor License Agreement |
10 | 7 |
|
11 | | -We'd love to accept your sample apps and patches! Before we can take them, we |
12 | | -have to jump a couple of legal hurdles. |
| 8 | +Contributions to this project must be accompanied by a Contributor License |
| 9 | +Agreement. You (or your employer) retain the copyright to your contribution; |
| 10 | +this simply gives us permission to use and redistribute your contributions as |
| 11 | +part of the project. Head over to <https://cla.developers.google.com/> to see |
| 12 | +your current agreements on file or to sign a new one. |
13 | 13 |
|
14 | | -Please fill out either the individual or corporate Contributor License Agreement |
15 | | -(CLA). |
16 | | - |
17 | | - * If you are an individual writing original source code and you're sure you |
18 | | - own the intellectual property, then you'll need to sign an [individual |
19 | | - CLA](https://developers.google.com/open-source/cla/individual). |
20 | | - * If you work for a company that wants to allow you to contribute your work, |
21 | | - then you'll need to sign a [corporate |
22 | | - CLA](https://developers.google.com/open-source/cla/corporate). |
23 | | - |
24 | | -Follow either of the two links above to access the appropriate CLA and |
25 | | -instructions for how to sign and return it. Once we receive it, we'll be able to |
26 | | -accept your pull requests. |
27 | | - |
28 | | -## Contributing a Patch or New Sample |
29 | | - |
30 | | -1. Sign a [Contributor License Agreement](#Contributor-License-Agreements). |
31 | | -1. Set up your [Java Developer Environment](https://cloud.google.com/java/docs/setup). |
32 | | -1. Fork the repo. |
33 | | -1. Develop and test your code. |
34 | | -1. Ensure that your code adheres to the [SAMPLE_FORMAT.md](SAMPLE_FORMAT.md) |
35 | | -guidelines. |
36 | | -1. Ensure that your code has an appropriate set of unit tests which all pass. |
37 | | -1. Submit a pull request. |
38 | | -1. A maintainer will review the pull request and make comments. |
39 | | - |
40 | | -## Build Tools |
41 | | - |
42 | | -All new samples should build and run integration tests with both [Maven](https://maven.apache.org/) and [Gradle](https://gradle.org/). |
43 | | - |
44 | | -## Integration Testing |
45 | | - |
46 | | -All samples must have integration tests that run with Maven and Gradle |
47 | | - |
48 | | -* Test Library: [JUnit4](https://junit.org/junit4/) |
49 | | -* Test Runner: [Maven Failsafe plugin](https://maven.apache.org/surefire/maven-failsafe-plugin/) and [Maven Surefire plugin](https://maven.apache.org/surefire/maven-surefire-plugin/). |
50 | | - |
51 | | -### Running Tests Locally |
52 | | - |
53 | | -Run tests locally with commands: |
54 | | - |
55 | | -* Maven: `mvn verify` |
56 | | -* Gradle: `gradle build test` |
57 | | - |
58 | | -### Gradle Specifcs |
59 | | -Your `build.gradle` should have the following section: |
60 | | - |
61 | | -```groovy |
62 | | -
|
63 | | -test { |
64 | | - useJUnit() |
65 | | - testLogging.showStandardStreams = true |
66 | | - beforeTest { descriptor -> |
67 | | - logger.lifecycle("test: " + descriptor + " Running") |
68 | | - } |
69 | | -
|
70 | | - onOutput { descriptor, event -> |
71 | | - logger.lifecycle("test: " + descriptor + ": " + event.message ) |
72 | | - } |
73 | | - afterTest { descriptor, result -> |
74 | | - logger.lifecycle("test: " + descriptor + ": " + result ) |
75 | | - } |
76 | | -} |
77 | | -``` |
78 | | - |
79 | | -### Other Testing Set Up |
80 | | - |
81 | | -Most samples require a GCP project and billing account. Keep the following in |
82 | | -mind when setting up tests. |
83 | | - |
84 | | -* **Environment variables** |
85 | | - Minimize additional environment variables that need to be set to run the tests. |
86 | | - If you do require additional environment variables, they should be added to |
87 | | - `run_tests.sh`. |
88 | | - |
89 | | - Existing environment variables include: |
90 | | - * `GOOGLE_APPLICATION_CREDENTIALS` |
91 | | - * `GOOGLE_CLOUD_PROJECT` |
92 | | - * `PROJECT_ID` |
93 | | - |
94 | | -* **API library** |
95 | | - If an API needs to be enabled in the testing project, add this information to the |
96 | | - directory's CONTRIBUTING.md file. If there is no CONTRIBUTING.md file, add one in your PR. |
97 | | - |
98 | | -* **Cloud resources** |
99 | | - Most Java samples create the Cloud resources that they need to run. If this |
100 | | - is resource intensive or not possible, add instructions to the directory's CONTRIBUTING.md file |
101 | | - to add the resource to the testing project. |
102 | | - |
103 | | -* **Keys and Secrets** |
104 | | - Add a note in the pull request, in order for a Java maintainer to assist you |
105 | | - in adding keys and secrets to the testing project. |
| 14 | +You generally only need to submit a CLA once, so if you've already submitted one |
| 15 | +(even if it was for a different project), you probably don't need to do it |
| 16 | +again. |
106 | 17 |
|
107 | 18 | ## Style |
108 | 19 |
|
109 | | -Samples in this repository follow the [Google Java Style Guide][java-style]. |
110 | | -This is enforced using the [Maven Checkstyle Plugin][checkstyle-plugin]. |
111 | | - |
112 | | -[java-style]: https://google.github.io/styleguide/javaguide.html |
113 | | -[checkstyle-plugin]: https://maven.apache.org/plugins/maven-checkstyle-plugin/ |
114 | | - |
115 | | -Use the [google-java-format][google-java-format] tool to automatically reformat |
116 | | -your source code to adhere to the style guide. It is available as a command-line |
117 | | -tool or IntelliJ plugin. |
118 | | - |
119 | | -[google-java-format]: https://github.com/google/google-java-format |
120 | | - |
121 | | -### Adding the Checkstyle Plugin to New Samples |
122 | | - |
123 | | -The samples in this repository use a common parent POM to define plugins used |
124 | | -for linting and testing. Add the following to your sample POM to ensure that it |
125 | | -uses the common Checkstyle configuration. For more information, see the |
126 | | -[java-repo-tools](https://github.com/GoogleCloudPlatform/java-repo-tools) |
127 | | -repository. |
128 | | - |
129 | | -```xml |
130 | | -<!-- |
131 | | - The parent pom defines common style checks and testing strategies for our samples. |
132 | | - Removing or replacing it should not affect the execution of the samples in anyway. |
133 | | - --> |
134 | | -<parent> |
135 | | - <groupId>com.google.cloud.samples</groupId> |
136 | | - <artifactId>shared-configuration</artifactId> |
137 | | - <version>1.0.13</version> |
138 | | -</parent> |
139 | | -``` |
140 | | - |
141 | | -### Running the Linter |
| 20 | +All code should follow the [Sample Format Guidelines](/java-docs-samples/blob/master/SAMPLE_FORMAT.md) |
142 | 21 |
|
143 | | -To run the checkstyle & ErrorProne plugins on an existing sample, run |
| 22 | +## Code reviews |
144 | 23 |
|
145 | | -```shell |
146 | | -mvn clean verify -DskipTests |
147 | | -``` |
| 24 | +Change to samples should be reviewed by both a product stakeholder for accuracy as well as a member |
| 25 | +of java-samples-reviewers@ to ensure the sample format and best practices for Java are used. |
148 | 26 |
|
149 | | -The `-DskipTests` is optional. It is useful if you want to verify that your code |
150 | | -builds and adheres to the style guide without waiting for tests to complete. |
| 27 | +All submissions, including submissions by project members, require review. We |
| 28 | +use GitHub pull requests for this purpose. Consult |
| 29 | +[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more |
| 30 | +information on using pull requests. |
151 | 31 |
|
| 32 | +## Community Guidelines |
152 | 33 |
|
153 | | -### Parsing Command-Line Arguments in Samples |
| 34 | +This project follows |
| 35 | +[Google's Open Source Community Guidelines](https://opensource.google/conduct/). |
154 | 36 |
|
155 | | -Simple command-line samples with only positional arguments should use the |
156 | | -`args` argument to `main(String... args)` directly. A command-line sample |
157 | | -which has optional parameters should use the [Apache Commons |
158 | | -CLI](https://commons.apache.org/proper/commons-cli/index.html) library. |
159 | 37 |
|
160 | | -Dataflow samples are an exception to this rule, since Dataflow has [its own |
161 | | -method for setting custom |
162 | | -options](https://cloud.google.com/dataflow/pipelines/specifying-exec-params). |
0 commit comments