Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add contributing guidelines #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Contributing Guidelines

## Environment Setup

Everything is built and tested using Java 8 so please make sure that you are using that version (e.g. `echo $JAVA_HOME` should print something like `/usr/lib/jvm/java-8-openjdk-amd64`).

## Directory Structure

```
├── build/ # gitignored - build artifacts are put here
├── build.gradle # Gradle build file - https://docs.gradle.org/current/userguide/build_file_basics.html
├── CONTRIBUTING.md # This file :)
├── docs/ # gitignored - generated javadocs are stored here by the CD process
├── gradle/ # autogenerated - contains the gradle wrapper jar and properties
├── gradlew # autogenerated - gradle wrapper file for Unix/macOS
├── gradlew.bat # autogenerated - gradle wrapper file for Windows
├── gradle.properties # config file that contains the name of the repo and the version number
├── LICENSE.md # autogenerated - use ./gradlew markdown to create it
├── LICENSE.mdt # template for the LICENCE
├── README.md # autogenerated - use ./gradlew markdown to create it
├── README.mdt # template for the README
└── src
├── integration # end to end tests that run the source code against the production API
├── main # source code for the SDK itself
└── test # unit tests for various portions of the SDK
```

## Tests

### Unit

Running the unit tests is as simple as running `./gradlew test`

### Integration

Running the integration tests requires some set up since we're actually hitting the production API.

1. Create a / Sign into your developer account at https://dashboard.smartcar.com/login
2. Reach out to Smartcar to get webhooks enabled for your account
3. Add the following redirect URI to your application: `https://example.com/auth`
4. Set the following environment variables

- `E2E_SMARTCAR_AMT` (fetch from the "Configuration" page)
- `E2E_SMARTCAR_CLIENT_ID` (fetch from the "Configuration" page)
- `E2E_SMARTCAR_CLIENT_SECRET` (fetch from the "Configuration" page)
- `E2E_SMARTCAR_WEBHOOK_ID` (fetch from "Webhooks" page, webhook does not have to be verified for the tests)

5. Run the tests using `./gradlew integration`

### Both

You can run the entire test suite by running `./gradlew check`

## Local Publishing

If you would like to use the SDK the same way that a consumer would, you can actually publish it to a local Maven repository and then use it in another project for testing. This is great for making sure the experience for SDK consumers works as you want it to.

### Setup

1. Create a PGP key pair that can be used to sign the artifact (you only need to do this once)

```bash
gpg --batch --generate-key <<EOF
Key-Type: RSA
Key-Length: 2048
Name-Real: Smartcar Testing
Name-Comment: use only for testing
Name-Email: [email protected]
Expire-Date: 0
Passphrase: testpass1
%commit
%echo done
EOF
```

2. Set the following environment variables so Gradle knows what key to use for signing your release

```bash
export ORG_GRADLE_PROJECT_signingKey="$(gpg --armor --export-secret-key)"
export ORG_GRADLE_PROJECT_signingPassword='testpass1'
```

3. Run `./gradlew publishToMavenLocal` to publish the changes to your local Maven repository (located at `~/.m2/repository`).

4. You can now use your locally published version of the SDK in a project (e.g. [getting-started-java-sdk](http://github.com/smartcar/getting-started-java-sdk)) to test out the changes or view the actually files that will be published by navigating to the `~/.m2` directory. To use the SDK make the following edits to `build.gradle` where you would like to use the SDK (i.e. don't make these edits in the `build.gradle` file in this repository itself)

1. Add `mavenLocal` before all other repositories

```groovy
repositories {
mavenLocal()
mavenCentral()
}
```

2. Update the version of the package used to the version that you published locally
```groovy
dependencies {
compile 'com.smartcar.sdk:java-sdk:<the version you have locally>'
}
```

## Workflow

1. Set up your development environment
2. Make changes to main / test / integration as needed to implement your changes
3. Run unit and integration tests
4. Iterate on your changes
5. Publish the SDK locally and verify your changes with some sample code
6. Iterate on your changes further if needed
7. Generate and review the JavaDoc (e.g. `./gradlew javadoc && python -m http.server --directory docs`) (note: This is for local verification only and does not need to be committed, the CD process will generate the ones that are published).
8. Bump the version number in `gradle.properties` and regenerate the README by running `./gradlew markdown`)
9. Commit the version number and README changes and open a PR :tada: