|
| 1 | +## Contributing |
| 2 | + |
| 3 | +Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. |
| 4 | + |
| 5 | +Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.md). |
| 6 | + |
| 7 | +Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. |
| 8 | + |
| 9 | +## Submitting a pull request |
| 10 | + |
| 11 | +0. Fork and clone the repository |
| 12 | +0. Create a new branch: `git checkout -b my-branch-name` |
| 13 | +0. Make your change, add tests, and make sure the tests still pass |
| 14 | +0. Push to your fork and submit a pull request |
| 15 | +0. Pat your self on the back and wait for your pull request to be reviewed and merged. |
| 16 | + |
| 17 | +Here are a few things you can do that will increase the likelihood of your pull request being accepted: |
| 18 | + |
| 19 | +- Discuss your changes with the community in an issue. |
| 20 | +- Allow your pull request to receive edits by maintainers. |
| 21 | +- Write tests. |
| 22 | +- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. |
| 23 | +- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). |
| 24 | + |
| 25 | +## Automated And Manual Testing |
| 26 | + |
| 27 | +### Overview |
| 28 | + |
| 29 | +When raising a pull request against this project, automated tests will be launched to run our test suite. |
| 30 | + |
| 31 | +In line with Terraform Provider testing best practices, these tests exercise against a live, public GitHub deployment (referred to as `dotcom`). Tests may also run against an Enterprise GitHub deployment (referred to as `ghes`), which is sometimes available during parts of a month. If your change requires testing against a specific version of GitHub, please let a maintainer know and this may be arranged. |
| 32 | + |
| 33 | + |
| 34 | +### Building The Provider |
| 35 | + |
| 36 | +Clone the provider |
| 37 | +```sh |
| 38 | +$ git clone [email protected]:terraform-providers/terraform-provider-github.git |
| 39 | +``` |
| 40 | + |
| 41 | +Enter the provider directory and build the provider |
| 42 | + |
| 43 | +```sh |
| 44 | +$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-github |
| 45 | +$ make build |
| 46 | +# or if you're on a mac: |
| 47 | +$ gnumake build |
| 48 | +``` |
| 49 | + |
| 50 | +### Developing The Provider |
| 51 | + |
| 52 | +If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`. |
| 53 | + |
| 54 | +To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory. |
| 55 | + |
| 56 | +```sh |
| 57 | +$ make build |
| 58 | +... |
| 59 | +$ $GOPATH/bin/terraform-provider-github |
| 60 | +... |
| 61 | +``` |
| 62 | + |
| 63 | +In order to test the provider, you can simply run `make test`. |
| 64 | + |
| 65 | +```sh |
| 66 | +$ make test |
| 67 | +``` |
| 68 | + |
| 69 | +In order to run the full suite of Acceptance tests, run `make testacc`. |
| 70 | + |
| 71 | +*Note:* Acceptance tests create real resources, and often cost money to run. |
| 72 | + |
| 73 | +```sh |
| 74 | +# run all tests through `make` |
| 75 | +$ make testacc |
| 76 | +# run all tests directly |
| 77 | +$ go test -v ./... |
| 78 | +# run specific test |
| 79 | +$ go test -v ./... -run TestAccProviderConfigure |
| 80 | +``` |
| 81 | + |
| 82 | +Commonly required environment variables are listed below: |
| 83 | + |
| 84 | +```console |
| 85 | +export TF_LOG=DEBUG |
| 86 | +export GITHUB_ORGANIZATION= |
| 87 | +export GITHUB_BASE_URL= |
| 88 | +export GITHUB_OWNER= |
| 89 | +export GITHUB_TEST_OWNER= |
| 90 | +export GITHUB_TEST_ORGANIZATION= |
| 91 | +export GITHUB_TEST_USER_TOKEN= |
| 92 | +``` |
| 93 | + |
| 94 | +See [this project](https://github.com/terraformtesting/acceptance-tests) for more information on how tests are run automatically. |
| 95 | + |
| 96 | +### GitHub Personal Access Token |
| 97 | + |
| 98 | +You will need to create a [personal access token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) for |
| 99 | +testing. It will need to have the following scopes selected: |
| 100 | +* repo |
| 101 | +* admin:org |
| 102 | +* admin:public_key |
| 103 | +* admin:repo_hook |
| 104 | +* admin:org_hook |
| 105 | +* user |
| 106 | +* delete_repo |
| 107 | +* admin:gpg_key |
| 108 | + |
| 109 | +Once the token has been created, it must be exported in your environment as `GITHUB_TOKEN`. |
| 110 | + |
| 111 | +### GitHub Organization |
| 112 | + |
| 113 | +If you do not have an organization already that you are comfortable running tests against, you will need to [create one](https://help.github.com/en/articles/creating-a-new-organization-from-scratch). The free "Team for Open Source" org type is fine for these tests. The name of the organization must then be exported in your environment as `GITHUB_OWNER`. |
| 114 | + |
| 115 | +If you are interested in using and/or testing Github's [Team synchronization](https://help.github.com/en/github/setting-up-and-managing-organizations-and-teams/synchronizing-teams-between-your-identity-provider-and-github) feature, please contact a maintainer as special arrangements can be made for your convenience. |
| 116 | + |
| 117 | +### Test Repositories |
| 118 | + |
| 119 | +In the pasts, tests required pre-existing repositories. The current test suite has been refreshed to have less dependencies like this. Developers would previously have had to set up the following fixtures manually: |
| 120 | + |
| 121 | +In the organization you are using above, create the following test repositories: |
| 122 | + |
| 123 | +* `test-repo` |
| 124 | + * The description should be `Test description, used in GitHub Terraform provider acceptance test.` |
| 125 | + * The website url should be `http://www.example.com` |
| 126 | + * Create two topics within the repo named `test-topic` and `second-test-topic` |
| 127 | + * In the repo settings, make sure all features and merge button options are enabled. |
| 128 | + * Create a `test-branch` branch |
| 129 | +* `test-repo-template` |
| 130 | + * Configure the repository to be a [Template repository](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-template-repository) |
| 131 | + * Create a release on the repository with `tag = v1.0` |
| 132 | + |
| 133 | +Export an environment variable corresponding to `GITHUB_TEMPLATE_REPOSITORY=test-repo-template`. |
| 134 | + |
| 135 | +### GitHub Users |
| 136 | + |
| 137 | +Export your github username (the one you used to create the personal access token above) as `GITHUB_TEST_USER`. You may need to export a different github username as `GITHUB_TEST_COLLABORATOR`. Please note that these usernames cannot be the same as each other, and both of them must be real github usernames. The collaborator user does not need to be added as a collaborator to your test repo or organization, but as the acceptance tests do real things (and will trigger some notifications for this user), you should probably make sure the person you specify knows that you're doing this just to be nice. You can also export `GITHUB_TEST_COLLABORATOR_TOKEN` in order to test the invitation acceptance. |
| 138 | + |
| 139 | +Additionally the user exported as `GITHUB_TEST_USER` should have a public email address configured in their profile; this should be exported as `GITHUB_TEST_USER_EMAIL` and the Github name exported as `GITHUB_TEST_USER_NAME` (this could be different to your GitHub login). |
| 140 | + |
| 141 | +Finally, export the ID of the release created in the template repository as `GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID` |
| 142 | + |
| 143 | +## Resources |
| 144 | + |
| 145 | +- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) |
| 146 | +- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) |
| 147 | +- [GitHub Help](https://help.github.com) |
0 commit comments