Skip to content

Commit e12cc5c

Browse files
authored
Update Guidelines (GoogleCloudPlatform#2504)
* Update Guidelines * Update Contributing to closer match the current cononical version. * Add PULL_REQUEST_TEMPLATE * Update README to closer add the License requirement from the cononical version. * Major revision of SAMPLE_FORMAT * apply comments * Update SAMPLE_FORMAT.md * Discourage use of CLI. * Discourage use of the default package. * Dane's feedback * remove xtra stuff in test labels for Region_Tags * Fix some language and change from CONTRIBUTING to README for resources * Parallel Streams - fix language * two more from Dane * Fix path * Add a path.
1 parent 653b112 commit e12cc5c

4 files changed

Lines changed: 303 additions & 217 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Fixes #<issue_number_goes_here>
2+
3+
> It's a good idea to open an issue first for discussion.
4+
5+
- [ ] Tests pass
6+
- [ ] Appropriate changes to README are included in PR
7+
- [ ] API's need to be enabled to test (tell us)
8+
- [ ] Environment Variables need to be set (ask us to set them)
9+

CONTRIBUTING.md

Lines changed: 23 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,37 @@
1-
# How to become a contributor and submit your own code
1+
# How to Contribute
22

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.
85

9-
## Contributor License Agreements
6+
## Contributor License Agreement
107

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.
1313

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.
10617

10718
## Style
10819

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)
14221

143-
To run the checkstyle & ErrorProne plugins on an existing sample, run
22+
## Code reviews
14423

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.
14826

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.
15131

32+
## Community Guidelines
15233

153-
### Parsing Command-Line Arguments in Samples
34+
This project follows
35+
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).
15436

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.
15937

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).

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ README files for details.
4242

4343
* See [LICENSE](LICENSE)
4444

45+
## Source Code Headers
46+
47+
Every file containing source code must include copyright and license
48+
information. This includes any JS/CSS files that you might be serving out to
49+
browsers. (This is to help well-intentioned people avoid accidental copying that
50+
doesn't comply with the license.)
51+
52+
Apache header:
53+
54+
Copyright 2020 Google LLC
55+
56+
Licensed under the Apache License, Version 2.0 (the "License");
57+
you may not use this file except in compliance with the License.
58+
You may obtain a copy of the License at
59+
60+
https://www.apache.org/licenses/LICENSE-2.0
61+
62+
Unless required by applicable law or agreed to in writing, software
63+
distributed under the License is distributed on an "AS IS" BASIS,
64+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
65+
See the License for the specific language governing permissions and
66+
limitations under the License.
67+
4568
[ADC]: https://developers.google.com/identity/protocols/application-default-credentials
4669
[cred]: http://google.github.io/google-auth-library-java/releases/0.6.0/apidocs/com/google/auth/Credentials.html?is-external=true
4770
[options]: http://googlecloudplatform.github.io/google-cloud-java/0.12.0/apidocs/com/google/cloud/ServiceOptions.Builder.html#setCredentials-com.google.auth.Credentials-

0 commit comments

Comments
 (0)