You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CONTRIBUTING.md 10 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. # Contributing
  2. 1. Sign one of the contributor license agreements below.
  3. 1. `go get golang.org/x/review/git-codereview` to install the code reviewing
  4. tool.
  5. 1. You will need to ensure that your `GOBIN` directory (by default
  6. `$GOPATH/bin`) is in your `PATH` so that git can find the command.
  7. 1. If you would like, you may want to set up aliases for git-codereview,
  8. such that `git codereview change` becomes `git change`. See the
  9. [godoc](https://godoc.org/golang.org/x/review/git-codereview) for details.
  10. 1. Should you run into issues with the git-codereview tool, please note
  11. that all error messages will assume that you have set up these aliases.
  12. 1. Get the cloud package by running `go get -d cloud.google.com/go`.
  13. 1. If you have already checked out the source, make sure that the remote
  14. git origin is https://code.googlesource.com/gocloud:
  15. ```
  16. git remote set-url origin https://code.googlesource.com/gocloud
  17. ```
  18. 1. Make sure your auth is configured correctly by visiting
  19. https://code.googlesource.com, clicking "Generate Password", and following the
  20. directions.
  21. 1. Make changes and create a change by running `git codereview change <name>`,
  22. provide a commit message, and use `git codereview mail` to create a Gerrit CL.
  23. 1. Keep amending to the change with `git codereview change` and mail as your
  24. receive feedback. Each new mailed amendment will create a new patch set for
  25. your change in Gerrit.
  26. ## Integration Tests
  27. In addition to the unit tests, you may run the integration test suite. These
  28. directions describe setting up your environment to run integration tests for
  29. _all_ packages: note that many of these instructions may be redundant if you
  30. intend only to run integration tests on a single package.
  31. #### GCP Setup
  32. To run the integrations tests, creation and configuration of two projects in
  33. the Google Developers Console is required: one specifically for Firestore
  34. integration tests, and another for all other integration tests. We'll refer to
  35. these projects as "general project" and "Firestore project".
  36. After creating each project, you must [create a service account](https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount)
  37. for each project. Ensure the project-level **Owner**
  38. [IAM role](console.cloud.google.com/iam-admin/iam/project) role is added to
  39. each service account. During the creation of the service account, you should
  40. download the JSON credential file for use later.
  41. Next, ensure the following APIs are enabled in the general project:
  42. - BigQuery API
  43. - BigQuery Data Transfer API
  44. - Cloud Dataproc API
  45. - Cloud Dataproc Control API Private
  46. - Cloud Datastore API
  47. - Cloud Firestore API
  48. - Cloud Key Management Service (KMS) API
  49. - Cloud Natural Language API
  50. - Cloud OS Login API
  51. - Cloud Pub/Sub API
  52. - Cloud Resource Manager API
  53. - Cloud Spanner API
  54. - Cloud Speech API
  55. - Cloud Translation API
  56. - Cloud Video Intelligence API
  57. - Cloud Vision API
  58. - Compute Engine API
  59. - Compute Engine Instance Group Manager API
  60. - Container Registry API
  61. - Firebase Rules API
  62. - Google Cloud APIs
  63. - Google Cloud Deployment Manager V2 API
  64. - Google Cloud SQL
  65. - Google Cloud Storage
  66. - Google Cloud Storage JSON API
  67. - Google Compute Engine Instance Group Updater API
  68. - Google Compute Engine Instance Groups API
  69. - Kubernetes Engine API
  70. - Stackdriver Error Reporting API
  71. Next, create a Datastore database in the general project, and a Firestore
  72. database in the Firestore project.
  73. Finally, in the general project, create an API key for the translate API:
  74. - Go to GCP Developer Console.
  75. - Navigate to APIs & Services > Credentials.
  76. - Click Create Credentials > API Key.
  77. - Save this key for use in `GCLOUD_TESTS_API_KEY` as described below.
  78. #### Local Setup
  79. Once the two projects are created and configured, set the following environment
  80. variables:
  81. - `GCLOUD_TESTS_GOLANG_PROJECT_ID`: Developers Console project's ID (e.g.
  82. bamboo-shift-455) for the general project.
  83. - `GCLOUD_TESTS_GOLANG_KEY`: The path to the JSON key file of the general
  84. project's service account.
  85. - `GCLOUD_TESTS_GOLANG_FIRESTORE_PROJECT_ID`: Developers Console project's ID
  86. (e.g. doorway-cliff-677) for the Firestore project.
  87. - `GCLOUD_TESTS_GOLANG_FIRESTORE_KEY`: The path to the JSON key file of the
  88. Firestore project's service account.
  89. - `GCLOUD_TESTS_GOLANG_KEYRING`: The full name of the keyring for the tests,
  90. in the form
  91. "projects/P/locations/L/keyRings/R". The creation of this is described below.
  92. - `GCLOUD_TESTS_API_KEY`: API key for using the Translate API.
  93. - `GCLOUD_TESTS_GOLANG_ZONE`: Compute Engine zone.
  94. Install the [gcloud command-line tool][gcloudcli] to your machine and use it to
  95. create some resources used in integration tests.
  96. From the project's root directory:
  97. ``` sh
  98. # Sets the default project in your env.
  99. $ gcloud config set project $GCLOUD_TESTS_GOLANG_PROJECT_ID
  100. # Authenticates the gcloud tool with your account.
  101. $ gcloud auth login
  102. # Create the indexes used in the datastore integration tests.
  103. $ gcloud datastore indexes create datastore/testdata/index.yaml
  104. # Creates a Google Cloud storage bucket with the same name as your test project,
  105. # and with the Stackdriver Logging service account as owner, for the sink
  106. # integration tests in logging.
  107. $ gsutil mb gs://$GCLOUD_TESTS_GOLANG_PROJECT_ID
  108. $ gsutil acl ch -g cloud-logs@google.com:O gs://$GCLOUD_TESTS_GOLANG_PROJECT_ID
  109. # Creates a PubSub topic for integration tests of storage notifications.
  110. $ gcloud beta pubsub topics create go-storage-notification-test
  111. # Next, go to the Pub/Sub dashboard in GCP console. Authorize the user
  112. # "service-<numberic project id>@gs-project-accounts.iam.gserviceaccount.com"
  113. # as a publisher to that topic.
  114. # Creates a Spanner instance for the spanner integration tests.
  115. $ gcloud beta spanner instances create go-integration-test --config regional-us-central1 --nodes 10 --description 'Instance for go client test'
  116. # NOTE: Spanner instances are priced by the node-hour, so you may want to
  117. # delete the instance after testing with 'gcloud beta spanner instances delete'.
  118. $ export MY_KEYRING=some-keyring-name
  119. $ export MY_LOCATION=global
  120. # Creates a KMS keyring, in the same location as the default location for your
  121. # project's buckets.
  122. $ gcloud kms keyrings create $MY_KEYRING --location $MY_LOCATION
  123. # Creates two keys in the keyring, named key1 and key2.
  124. $ gcloud kms keys create key1 --keyring $MY_KEYRING --location $MY_LOCATION --purpose encryption
  125. $ gcloud kms keys create key2 --keyring $MY_KEYRING --location $MY_LOCATION --purpose encryption
  126. # Sets the GCLOUD_TESTS_GOLANG_KEYRING environment variable.
  127. $ export GCLOUD_TESTS_GOLANG_KEYRING=projects/$GCLOUD_TESTS_GOLANG_PROJECT_ID/locations/$MY_LOCATION/keyRings/$MY_KEYRING
  128. # Authorizes Google Cloud Storage to encrypt and decrypt using key1.
  129. gsutil kms authorize -p $GCLOUD_TESTS_GOLANG_PROJECT_ID -k $GCLOUD_TESTS_GOLANG_KEYRING/cryptoKeys/key1
  130. ```
  131. #### Running
  132. Once you've done the necessary setup, you can run the integration tests by
  133. running:
  134. ``` sh
  135. $ go test -v cloud.google.com/go/...
  136. ```
  137. #### Replay
  138. Some packages can record the RPCs during integration tests to a file for
  139. subsequent replay. To record, pass the `-record` flag to `go test`. The
  140. recording will be saved to the _package_`.replay` file. To replay integration
  141. tests from a saved recording, the replay file must be present, the `-short`
  142. flag must be passed to `go test`, and the `GCLOUD_TESTS_GOLANG_ENABLE_REPLAY`
  143. environment variable must have a non-empty value.
  144. ## Contributor License Agreements
  145. Before we can accept your pull requests you'll need to sign a Contributor
  146. License Agreement (CLA):
  147. - **If you are an individual writing original source code** and **you own the
  148. intellectual property**, then you'll need to sign an [individual CLA][indvcla].
  149. - **If you work for a company that wants to allow you to contribute your
  150. work**, then you'll need to sign a [corporate CLA][corpcla].
  151. You can sign these electronically (just scroll to the bottom). After that,
  152. we'll be able to accept your pull requests.
  153. ## Contributor Code of Conduct
  154. As contributors and maintainers of this project,
  155. and in the interest of fostering an open and welcoming community,
  156. we pledge to respect all people who contribute through reporting issues,
  157. posting feature requests, updating documentation,
  158. submitting pull requests or patches, and other activities.
  159. We are committed to making participation in this project
  160. a harassment-free experience for everyone,
  161. regardless of level of experience, gender, gender identity and expression,
  162. sexual orientation, disability, personal appearance,
  163. body size, race, ethnicity, age, religion, or nationality.
  164. Examples of unacceptable behavior by participants include:
  165. * The use of sexualized language or imagery
  166. * Personal attacks
  167. * Trolling or insulting/derogatory comments
  168. * Public or private harassment
  169. * Publishing other's private information,
  170. such as physical or electronic
  171. addresses, without explicit permission
  172. * Other unethical or unprofessional conduct.
  173. Project maintainers have the right and responsibility to remove, edit, or reject
  174. comments, commits, code, wiki edits, issues, and other contributions
  175. that are not aligned to this Code of Conduct.
  176. By adopting this Code of Conduct,
  177. project maintainers commit themselves to fairly and consistently
  178. applying these principles to every aspect of managing this project.
  179. Project maintainers who do not follow or enforce the Code of Conduct
  180. may be permanently removed from the project team.
  181. This code of conduct applies both within project spaces and in public spaces
  182. when an individual is representing the project or its community.
  183. Instances of abusive, harassing, or otherwise unacceptable behavior
  184. may be reported by opening an issue
  185. or contacting one or more of the project maintainers.
  186. This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0,
  187. available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
  188. [gcloudcli]: https://developers.google.com/cloud/sdk/gcloud/
  189. [indvcla]: https://developers.google.com/open-source/cla/individual
  190. [corpcla]: https://developers.google.com/open-source/cla/corporate