1# Contributing 2 31. [File an issue](https://github.com/googleapis/google-cloud-go/issues/new/choose). 4 The issue will be used to discuss the bug or feature and should be created 5 before sending a CL. 6 71. [Install Go](https://golang.org/dl/). 8 1. Ensure that your `GOBIN` directory (by default `$(go env GOPATH)/bin`) 9 is in your `PATH`. 10 1. Check it's working by running `go version`. 11 * If it doesn't work, check the install location, usually 12 `/usr/local/go`, is on your `PATH`. 13 141. Sign one of the 15[contributor license agreements](#contributor-license-agreements) below. 16 171. Clone the repo: 18 `git clone https://github.com/googleapis/google-cloud-go` 19 201. Change into the checked out source: 21 `cd google-cloud-go` 22 231. Fork the repo. 24 251. Set your fork as a remote: 26 `git remote add fork git@github.com:GITHUB_USERNAME/google-cloud-go.git` 27 281. Make changes, commit to your fork. 29 30 Commit messages should follow the 31 [Conventional Commits Style](https://www.conventionalcommits.org). The scope 32 portion should always be filled with the name of the package affected by the 33 changes being made. For example: 34 ``` 35 feat(functions): add gophers codelab 36 ``` 37 381. Send a pull request with your changes. 39 40 To minimize friction, consider setting `Allow edits from maintainers` on the 41 PR, which will enable project committers and automation to update your PR. 42 431. A maintainer will review the pull request and make comments. 44 45 Prefer adding additional commits over amending and force-pushing since it can 46 be difficult to follow code reviews when the commit history changes. 47 48 Commits will be squashed when they're merged. 49 50## Testing 51 52We test code against two versions of Go, the minimum and maximum versions 53supported by our clients. To see which versions these are checkout our 54[README](README.md#supported-versions). 55 56### Integration Tests 57 58In addition to the unit tests, you may run the integration test suite. These 59directions describe setting up your environment to run integration tests for 60_all_ packages: note that many of these instructions may be redundant if you 61intend only to run integration tests on a single package. 62 63#### GCP Setup 64 65To run the integrations tests, creation and configuration of two projects in 66the Google Developers Console is required: one specifically for Firestore 67integration tests, and another for all other integration tests. We'll refer to 68these projects as "general project" and "Firestore project". 69 70After creating each project, you must [create a service account](https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount) 71for each project. Ensure the project-level **Owner** 72[IAM role](console.cloud.google.com/iam-admin/iam/project) role is added to 73each service account. During the creation of the service account, you should 74download the JSON credential file for use later. 75 76Next, ensure the following APIs are enabled in the general project: 77 78- BigQuery API 79- BigQuery Data Transfer API 80- Cloud Dataproc API 81- Cloud Dataproc Control API Private 82- Cloud Datastore API 83- Cloud Firestore API 84- Cloud Key Management Service (KMS) API 85- Cloud Natural Language API 86- Cloud OS Login API 87- Cloud Pub/Sub API 88- Cloud Resource Manager API 89- Cloud Spanner API 90- Cloud Speech API 91- Cloud Translation API 92- Cloud Video Intelligence API 93- Cloud Vision API 94- Compute Engine API 95- Compute Engine Instance Group Manager API 96- Container Registry API 97- Firebase Rules API 98- Google Cloud APIs 99- Google Cloud Deployment Manager V2 API 100- Google Cloud SQL 101- Google Cloud Storage 102- Google Cloud Storage JSON API 103- Google Compute Engine Instance Group Updater API 104- Google Compute Engine Instance Groups API 105- Kubernetes Engine API 106- Cloud Error Reporting API 107- Pub/Sub Lite API 108 109Next, create a Datastore database in the general project, and a Firestore 110database in the Firestore project. 111 112Finally, in the general project, create an API key for the translate API: 113 114- Go to GCP Developer Console. 115- Navigate to APIs & Services > Credentials. 116- Click Create Credentials > API Key. 117- Save this key for use in `GCLOUD_TESTS_API_KEY` as described below. 118 119#### Local Setup 120 121Once the two projects are created and configured, set the following environment 122variables: 123 124- `GCLOUD_TESTS_GOLANG_PROJECT_ID`: Developers Console project's ID (e.g. 125bamboo-shift-455) for the general project. 126- `GCLOUD_TESTS_GOLANG_KEY`: The path to the JSON key file of the general 127project's service account. 128- `GCLOUD_TESTS_GOLANG_FIRESTORE_PROJECT_ID`: Developers Console project's ID 129(e.g. doorway-cliff-677) for the Firestore project. 130- `GCLOUD_TESTS_GOLANG_FIRESTORE_KEY`: The path to the JSON key file of the 131Firestore project's service account. 132- `GCLOUD_TESTS_GOLANG_KEYRING`: The full name of the keyring for the tests, 133in the form 134"projects/P/locations/L/keyRings/R". The creation of this is described below. 135- `GCLOUD_TESTS_API_KEY`: API key for using the Translate API. 136- `GCLOUD_TESTS_GOLANG_ZONE`: Compute Engine zone. 137 138Install the [gcloud command-line tool][gcloudcli] to your machine and use it to 139create some resources used in integration tests. 140 141From the project's root directory: 142 143``` sh 144# Sets the default project in your env. 145$ gcloud config set project $GCLOUD_TESTS_GOLANG_PROJECT_ID 146 147# Authenticates the gcloud tool with your account. 148$ gcloud auth login 149 150# Create the indexes used in the datastore integration tests. 151$ gcloud datastore indexes create datastore/testdata/index.yaml 152 153# Creates a Google Cloud storage bucket with the same name as your test project, 154# and with the Cloud Logging service account as owner, for the sink 155# integration tests in logging. 156$ gsutil mb gs://$GCLOUD_TESTS_GOLANG_PROJECT_ID 157$ gsutil acl ch -g cloud-logs@google.com:O gs://$GCLOUD_TESTS_GOLANG_PROJECT_ID 158 159# Creates a PubSub topic for integration tests of storage notifications. 160$ gcloud beta pubsub topics create go-storage-notification-test 161# Next, go to the Pub/Sub dashboard in GCP console. Authorize the user 162# "service-<numberic project id>@gs-project-accounts.iam.gserviceaccount.com" 163# as a publisher to that topic. 164 165# Creates a Spanner instance for the spanner integration tests. 166$ gcloud beta spanner instances create go-integration-test --config regional-us-central1 --nodes 10 --description 'Instance for go client test' 167# NOTE: Spanner instances are priced by the node-hour, so you may want to 168# delete the instance after testing with 'gcloud beta spanner instances delete'. 169 170$ export MY_KEYRING=some-keyring-name 171$ export MY_LOCATION=global 172# Creates a KMS keyring, in the same location as the default location for your 173# project's buckets. 174$ gcloud kms keyrings create $MY_KEYRING --location $MY_LOCATION 175# Creates two keys in the keyring, named key1 and key2. 176$ gcloud kms keys create key1 --keyring $MY_KEYRING --location $MY_LOCATION --purpose encryption 177$ gcloud kms keys create key2 --keyring $MY_KEYRING --location $MY_LOCATION --purpose encryption 178# Sets the GCLOUD_TESTS_GOLANG_KEYRING environment variable. 179$ export GCLOUD_TESTS_GOLANG_KEYRING=projects/$GCLOUD_TESTS_GOLANG_PROJECT_ID/locations/$MY_LOCATION/keyRings/$MY_KEYRING 180# Authorizes Google Cloud Storage to encrypt and decrypt using key1. 181gsutil kms authorize -p $GCLOUD_TESTS_GOLANG_PROJECT_ID -k $GCLOUD_TESTS_GOLANG_KEYRING/cryptoKeys/key1 182``` 183 184#### Running 185 186Once you've done the necessary setup, you can run the integration tests by 187running: 188 189``` sh 190$ go test -v cloud.google.com/go/... 191``` 192 193#### Replay 194 195Some packages can record the RPCs during integration tests to a file for 196subsequent replay. To record, pass the `-record` flag to `go test`. The 197recording will be saved to the _package_`.replay` file. To replay integration 198tests from a saved recording, the replay file must be present, the `-short` 199flag must be passed to `go test`, and the `GCLOUD_TESTS_GOLANG_ENABLE_REPLAY` 200environment variable must have a non-empty value. 201 202## Contributor License Agreements 203 204Before we can accept your pull requests you'll need to sign a Contributor 205License Agreement (CLA): 206 207- **If you are an individual writing original source code** and **you own the 208intellectual property**, then you'll need to sign an [individual CLA][indvcla]. 209- **If you work for a company that wants to allow you to contribute your 210work**, then you'll need to sign a [corporate CLA][corpcla]. 211 212You can sign these electronically (just scroll to the bottom). After that, 213we'll be able to accept your pull requests. 214 215## Contributor Code of Conduct 216 217As contributors and maintainers of this project, 218and in the interest of fostering an open and welcoming community, 219we pledge to respect all people who contribute through reporting issues, 220posting feature requests, updating documentation, 221submitting pull requests or patches, and other activities. 222 223We are committed to making participation in this project 224a harassment-free experience for everyone, 225regardless of level of experience, gender, gender identity and expression, 226sexual orientation, disability, personal appearance, 227body size, race, ethnicity, age, religion, or nationality. 228 229Examples of unacceptable behavior by participants include: 230 231* The use of sexualized language or imagery 232* Personal attacks 233* Trolling or insulting/derogatory comments 234* Public or private harassment 235* Publishing other's private information, 236such as physical or electronic 237addresses, without explicit permission 238* Other unethical or unprofessional conduct. 239 240Project maintainers have the right and responsibility to remove, edit, or reject 241comments, commits, code, wiki edits, issues, and other contributions 242that are not aligned to this Code of Conduct. 243By adopting this Code of Conduct, 244project maintainers commit themselves to fairly and consistently 245applying these principles to every aspect of managing this project. 246Project maintainers who do not follow or enforce the Code of Conduct 247may be permanently removed from the project team. 248 249This code of conduct applies both within project spaces and in public spaces 250when an individual is representing the project or its community. 251 252Instances of abusive, harassing, or otherwise unacceptable behavior 253may be reported by opening an issue 254or contacting one or more of the project maintainers. 255 256This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, 257available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) 258 259[gcloudcli]: https://developers.google.com/cloud/sdk/gcloud/ 260[indvcla]: https://developers.google.com/open-source/cla/individual 261[corpcla]: https://developers.google.com/open-source/cla/corporate 262