Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.

Commit c6781cc

Browse files
yoshi-automationchingor13
authored andcommitted
chore: update common templates (#117)
1 parent 0f33360 commit c6781cc

File tree

6 files changed

+405
-149
lines changed

6 files changed

+405
-149
lines changed

.kokoro/build.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,26 @@ test)
4444
bash .kokoro/coerce_logs.sh
4545
;;
4646
lint)
47-
mvn com.coveo:fmt-maven-plugin:check
47+
mvn \
48+
-Penable-samples \
49+
com.coveo:fmt-maven-plugin:check
4850
;;
4951
javadoc)
5052
mvn javadoc:javadoc javadoc:test-javadoc
5153
;;
5254
integration)
5355
mvn -B ${INTEGRATION_TEST_ARGS} \
56+
-Penable-integration-tests \
57+
-DtrimStackTrace=false \
58+
-Dclirr.skip=true \
59+
-Denforcer.skip=true \
60+
-fae \
61+
verify
62+
bash .kokoro/coerce_logs.sh
63+
;;
64+
samples)
65+
mvn -B \
66+
-Penable-samples \
5467
-DtrimStackTrace=false \
5568
-Dclirr.skip=true \
5669
-Denforcer.skip=true \

.kokoro/continuous/samples.cfg

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}
8+
9+
env_vars: {
10+
key: "JOB_TYPE"
11+
value: "samples"
12+
}
13+
14+
env_vars: {
15+
key: "GCLOUD_PROJECT"
16+
value: "gcloud-devel"
17+
}
18+
19+
env_vars: {
20+
key: "GOOGLE_APPLICATION_CREDENTIALS"
21+
value: "keystore/73713_java_it_service_account"
22+
}
23+
24+
before_action {
25+
fetch_keystore {
26+
keystore_resource {
27+
keystore_config_id: 73713
28+
keyname: "java_it_service_account"
29+
}
30+
}
31+
}

.kokoro/nightly/samples.cfg

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}
8+
9+
env_vars: {
10+
key: "JOB_TYPE"
11+
value: "samples"
12+
}
13+
14+
env_vars: {
15+
key: "GCLOUD_PROJECT"
16+
value: "gcloud-devel"
17+
}
18+
19+
env_vars: {
20+
key: "GOOGLE_APPLICATION_CREDENTIALS"
21+
value: "keystore/73713_java_it_service_account"
22+
}
23+
24+
before_action {
25+
fetch_keystore {
26+
keystore_resource {
27+
keystore_config_id: 73713
28+
keyname: "java_it_service_account"
29+
}
30+
}
31+
}

.kokoro/presubmit/samples.cfg

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}
8+
9+
env_vars: {
10+
key: "JOB_TYPE"
11+
value: "samples"
12+
}
13+
14+
env_vars: {
15+
key: "GCLOUD_PROJECT"
16+
value: "gcloud-devel"
17+
}
18+
19+
env_vars: {
20+
key: "GOOGLE_APPLICATION_CREDENTIALS"
21+
value: "keystore/73713_java_it_service_account"
22+
}
23+
24+
before_action {
25+
fetch_keystore {
26+
keystore_resource {
27+
keystore_config_id: 73713
28+
keyname: "java_it_service_account"
29+
}
30+
}
31+
}

CONTRIBUTING.md

+103-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,106 @@ information on using pull requests.
2525
## Community Guidelines
2626

2727
This project follows
28-
[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/).
28+
[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/).
29+
30+
## Building the project
31+
32+
To build, package, and run all unit tests run the command
33+
34+
```
35+
mvn clean verify
36+
```
37+
38+
### Running Integration tests
39+
40+
To include integration tests when building the project, you need access to
41+
a GCP Project with a valid service account.
42+
43+
For instructions on how to generate a service account and corresponding
44+
credentials JSON see: [Creating a Service Account][1].
45+
46+
Then run the following to build, package, run all unit tests and run all
47+
integration tests.
48+
49+
```bash
50+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account.json
51+
mvn -Penable-integration-tests clean verify
52+
```
53+
54+
## Code Samples
55+
56+
Code Samples must be bundled in separate Maven modules, and guarded by a
57+
Maven profile with the name `enable-samples`.
58+
59+
The samples must be separate from the primary project for a few reasons:
60+
1. Primary projects have a minimum Java version of Java 7 whereas samples have
61+
a minimum Java version of Java 8. Due to this we need the ability to
62+
selectively exclude samples from a build run.
63+
2. Many code samples depend on external GCP services and need
64+
credentials to access the service.
65+
3. Code samples are not released as Maven artifacts and must be excluded from
66+
release builds.
67+
68+
### Building
69+
70+
```bash
71+
mvn -Penable-samples clean verify
72+
```
73+
74+
Some samples require access to GCP services and require a service account:
75+
76+
```bash
77+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account.json
78+
mvn -Penable-samples clean verify
79+
```
80+
81+
### Profile Config
82+
83+
1. To add samples in a profile to your Maven project, add the following to your
84+
`pom.xml`
85+
86+
```xml
87+
<project>
88+
[...]
89+
<profiles>
90+
<profile>
91+
<id>enable-samples</id>
92+
<modules>
93+
<module>sample</module>
94+
</modules>
95+
</profile>
96+
</profiles>
97+
[...]
98+
</project>
99+
```
100+
101+
2. [Activate](#profile-activation) the profile.
102+
3. Define your samples in a normal Maven project in the `samples/` directory
103+
104+
### Profile Activation
105+
106+
To include code samples when building and testing the project, enable the
107+
`enable-samples` Maven profile.
108+
109+
#### Command line
110+
111+
To activate the Maven profile on the command line add `-Penable-samples` to your
112+
Maven command.
113+
114+
#### Maven `settings.xml`
115+
116+
To activate the Maven profile in your `~/.m2/settings.xml` add an entry of
117+
`enable-samples` following the instructions in [Active Profiles][2].
118+
119+
This method has the benefit of applying to all projects you build (and is
120+
respected by IntelliJ IDEA) and is recommended if you are going to be
121+
contributing samples to several projects.
122+
123+
#### IntelliJ IDEA
124+
125+
To activate the Maven Profile inside IntelliJ IDEA, follow the instructions in
126+
[Activate Maven profiles][3] to activate `enable-samples`.
127+
128+
[1]: https://cloud.google.com/docs/authentication/getting-started#creating_a_service_account
129+
[2]: https://maven.apache.org/settings.html#Active_Profiles
130+
[3]: https://www.jetbrains.com/help/idea/work-with-maven-profiles.html#activate_maven_profiles

0 commit comments

Comments
 (0)