Skip to content

Commit ddfb742

Browse files
author
Jeremy Udit
authored
Refresh CONTRIBUTING Documentation (#682)
* refresh contributing docs * add quick instructions * add updates for newer versions of terraform
1 parent 3ab313b commit ddfb742

File tree

2 files changed

+87
-38
lines changed

2 files changed

+87
-38
lines changed

CONTRIBUTING.md

+80-38
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Contributing
1+
# Contributing
22

33
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
44

@@ -22,14 +22,38 @@ Here are a few things you can do that will increase the likelihood of your pull
2222
- 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.
2323
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
2424

25+
## Quick End-To-End Example
26+
27+
This section describes a typical sequence performed when developing locally. Full details of available tooling are available in the next section on [Automated And Manual Testing](#automated-and-manual-testing).
28+
29+
1. Export necessary configuration for authenticating your provider with GitHub
30+
```sh
31+
export GITHUB_TOKEN=<token of a user with an organization account>
32+
export GITHUB_ORGANIZATION=<name of an organization>
33+
```
34+
1. Write a test describing what you will fix. See [`github_label`](./github/resource_github_issue_label_test.go) for an example format.
35+
1. Run your test and observe it fail. Enabling debug output allows for observing the underlying requests and responses made as well as viewing state (search `STATE:`) generated during the acceptance test run.
36+
```sh
37+
TF_LOG=DEBUG TF_ACC=1 go test -v ./... -run ^TestAccGithubIssueLabel
38+
```
39+
1. Align the resource's implementation to your test case and observe it pass:
40+
```sh
41+
TF_ACC=1 go test -v ./... -run ^TestAccGithubIssueLabel
42+
```
43+
44+
Note that some resources still use a previous format that is incompatible with automated test runs, which depend on using the `skipUnlessMode` helper. When encountering these resources, tests are rewritten to the latest format.
45+
46+
Also note that there is no build / `terraform init` / `terraform plan` sequence here. It is uncommon to run into a bug or feature that requires iteration without using tests. When these cases arise, the `examples/` directory is used to approach the problem, which is detailed in the next section.
47+
2548
## Automated And Manual Testing
2649

2750
### Overview
2851

29-
When raising a pull request against this project, automated tests will be launched to run our test suite.
52+
When raising a pull request against this project, automated tests will be launched to run a subset of our test suite.
3053

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.
54+
Full acceptance testing is run [daily][acc-daily]. 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.
3255

56+
Partial acceptance testing can be run manually by creating a branch prefixed with `test/`. Simple detection of changes and related test files is performed and a subset of acceptance tests are run against commits to these branches. This is a useful workflow for reviewing PRs submitted by the community, but local testing is preferred for contributors while iterating towards publishing a PR.
3357

3458
### Building The Provider
3559

@@ -38,18 +62,47 @@ Clone the provider
3862
$ git clone [email protected]:integrations/terraform-provider-github.git
3963
```
4064

41-
Enter the provider directory and build the provider
65+
Enter the provider directory and build the provider while specifying an output directory:
4266

4367
```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
68+
$ go build -o ~/go/bin/
69+
```
70+
71+
This enables verifying your locally built provider using examples available in the `examples/` directory.
72+
Note that you will first need to configure your shell to map our provider to the local build:
73+
74+
```sh
75+
export TF_CLI_CONFIG_FILE=path/to/project/examples/dev.tfrc
76+
```
77+
78+
An example file is available in our `examples` directory and resembles:
79+
80+
```hcl
81+
provider_installation {
82+
dev_overrides {
83+
"integrations/github" = "~/go/bin/"
84+
}
85+
86+
direct {}
87+
}
88+
```
89+
90+
See https://www.terraform.io/docs/cli/config/config-file.html for more details.
91+
92+
When running examples, you should spot the following warning to confirm you are using a local build:
93+
94+
```console
95+
Warning: Provider development overrides are in effect
96+
97+
The following provider development overrides are set in the CLI configuration:
98+
- integrations/github in /Users/jcudit/go/bin
4899
```
49100

50101
### Developing The Provider
51102

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`.
103+
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*).
104+
105+
You may also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`. Recent Go releases may have removed the need for this step however.
53106

54107
To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
55108

@@ -81,11 +134,23 @@ $ go test -v ./... -run TestAccProviderConfigure
81134

82135
Commonly required environment variables are listed below:
83136

84-
```console
137+
```sh
138+
# enable debug logging
85139
export TF_LOG=DEBUG
140+
141+
# enable testing of organization scenarios instead of individual or anonymous
86142
export GITHUB_ORGANIZATION=
87-
export GITHUB_BASE_URL=
143+
144+
# enable testing of individual scenarios instead of organizaiton or anonymous
88145
export GITHUB_OWNER=
146+
147+
# enable testing of enterprise appliances
148+
export GITHUB_BASE_URL=
149+
150+
# leverage helper accounts for tests requiring them
151+
# examples include:
152+
# - https://github.com/github-terraform-test-user
153+
# - https://github.com/terraformtesting
89154
export GITHUB_TEST_OWNER=
90155
export GITHUB_TEST_ORGANIZATION=
91156
export GITHUB_TEST_USER_TOKEN=
@@ -110,38 +175,15 @@ Once the token has been created, it must be exported in your environment as `GIT
110175

111176
### GitHub Organization
112177

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`.
178+
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_ORGANIZATION`.
114179

115180
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.
116181

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-
143182
## Resources
144183

145184
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
146185
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
147186
- [GitHub Help](https://help.github.com)
187+
188+
189+
[acc-daily]: https://github.com/integrations/terraform-provider-github/actions?query=workflow%3A%22Acceptance+Tests+%28All%29%22

examples/dev.tfrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
provider_installation {
2+
dev_overrides {
3+
"integrations/github" = "~/go/bin/"
4+
}
5+
6+
direct {}
7+
}

0 commit comments

Comments
 (0)