Skip to content

Commit f974050

Browse files
committed
Add docs contribution guide
Signed-off-by: Timo Sand <[email protected]>
1 parent d9de79c commit f974050

2 files changed

Lines changed: 76 additions & 62 deletions

File tree

CONTRIBUTING.md

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ Before submitting an issue or a pull request, please search the repository for e
1010

1111
## Submitting a pull request
1212

13-
0. Fork and clone the repository.
14-
0. Create a new branch: `git switch -c my-branch-name`.
15-
0. Make your change, add tests, and make sure the tests still pass.
16-
0. Push to your fork and submit a pull request.
17-
0. Pat yourself on the back and wait for your pull request to be reviewed and merged.
13+
1. Fork and clone the repository.
14+
2. Create a new branch: `git switch -c my-branch-name`.
15+
3. Make your change, add tests, and make sure the tests still pass.
16+
4. Run `make docs-lint` to check if the documentation is up to date.
17+
5. Update the documentation templates if needed.
18+
6. Run `make docs-generate` to generate changes to the documentation.
19+
7. Push to your fork and submit a pull request.
20+
8. Pat yourself on the back and wait for your pull request to be reviewed and merged.
1821

1922
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
2023

@@ -33,26 +36,31 @@ This section describes a typical sequence performed when developing locally. Ful
3336
Once you have the repository cloned, there's a couple of additional steps you'll need to take. Since most of the testing is acceptance or integration testing, we need to manipulate real GitHub resources in order to run it. Useful setup steps are listed below:
3437

3538
- If you haven't already, [create a GitHub organization you can use for testing](#github-organization).
36-
- Optional: you may find it beneficial to create a test user as well in order to avoid potential rate-limiting issues on your main account.
37-
- Your organization _must_ have a repository called `terraform-template-module`. The [terraformtesting/terraform-template-module](https://github.com/terraformtesting/terraform-template-module) repo is a good, re-usable example.
38-
- You _must_ make sure that the "Template Repository" item in Settings is checked for this repo.
39+
- Optional: you may find it beneficial to create a test user as well in order to avoid potential rate-limiting issues on your main account.
40+
- Your organization _must_ have a repository called `terraform-template-module`. The [terraformtesting/terraform-template-module](https://github.com/terraformtesting/terraform-template-module) repo is a good, re-usable example.
41+
- You _must_ make sure that the "Template Repository" item in Settings is checked for this repo.
3942
- If you haven't already, generate a Personal Access Token (PAT) for authenticating your test runs.
4043
- Export the necessary configuration for authenticating your provider with GitHub
44+
4145
```sh
4246
export GITHUB_TOKEN=<token of a user with an organization account>
4347
export GITHUB_ORGANIZATION=<name of an organization>
4448
```
49+
4550
- Build the project with `make build`
4651
- Try an example test run from the default (`main`) branch, like `TF_LOG=DEBUG TF_ACC=1 go test -v ./... -run ^TestAccGithubRepositories`. All those tests should pass.
4752

4853
### Local Development Iteration
4954

5055
1. Write a test describing what you will fix. See [`github_label`](./github/resource_github_issue_label_test.go) for an example format.
51-
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.
56+
2. 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.
57+
5258
```sh
5359
TF_LOG=DEBUG TF_ACC=1 go test -v ./... -run ^TestAccGithubIssueLabel
5460
```
61+
5562
1. Align the resource's implementation to your test case and observe it pass:
63+
5664
```sh
5765
TF_ACC=1 go test -v ./... -run ^TestAccGithubIssueLabel
5866
```
@@ -67,27 +75,29 @@ Println debugging can easily be used to obtain information about how code change
6775

6876
If a full debugger is desired, VSCode may be used. In order to do so,
6977

70-
0. Create a launch.json file with this configuration:
78+
1. Create a launch.json file with this configuration:
79+
7180
```json
7281
{
73-
"name": "Attach to Process",
74-
"type": "go",
75-
"request": "attach",
76-
"mode": "local",
77-
"processId": 0,
82+
"name": "Attach to Process",
83+
"type": "go",
84+
"request": "attach",
85+
"mode": "local",
86+
"processId": 0,
7887
}
7988
```
89+
8090
Setting a `processId` of 0 allows a dropdown to select the process of the provider.
8191

82-
0. Add a sleep call (e.g. `time.Sleep(10 * time.Second)`) in the [`func providerConfigure(p *schema.Provider) schema.ConfigureFunc`](https://github.com/integrations/terraform-provider-github/blob/cec7e175c50bb091feecdc96ba117067c35ee351/github/provider.go#L274C1-L274C64) before the immediate `return` call. This will allow time to connect the debugger while the provider is initializing, before any critical logic happens.
92+
1. Add a sleep call (e.g. `time.Sleep(10 * time.Second)`) in the [`func providerConfigure(p *schema.Provider) schema.ConfigureFunc`](https://github.com/integrations/terraform-provider-github/blob/cec7e175c50bb091feecdc96ba117067c35ee351/github/provider.go#L274C1-L274C64) before the immediate `return` call. This will allow time to connect the debugger while the provider is initializing, before any critical logic happens.
8393

84-
0. Build the terraform provider with debug flags enabled and copy it to the appropriate bin folder with a command like `go build -gcflags="all=-N -l" -o ~/go/bin/`.
94+
2. Build the terraform provider with debug flags enabled and copy it to the appropriate bin folder with a command like `go build -gcflags="all=-N -l" -o ~/go/bin/`.
8595

86-
0. Create or edit a `dev.tfrc` that points toward the newly-built binary, and export the `TF_CLI_CONFIG_FILE` variable to point to it. Further instructions on this process may be found in the [Building the provider](#using-a-local-version-of-the-provider) section.
96+
3. Create or edit a `dev.tfrc` that points toward the newly-built binary, and export the `TF_CLI_CONFIG_FILE` variable to point to it. Further instructions on this process may be found in the [Building the provider](#using-a-local-version-of-the-provider) section.
8797

88-
0. Run a terraform command (e.g. `terraform apply`). While the provider pauses on initialization, go to VSCode and click "Attach to Process". In the search box that appears, type `terraform-provi` and select the terraform provider process.
98+
4. Run a terraform command (e.g. `terraform apply`). While the provider pauses on initialization, go to VSCode and click "Attach to Process". In the search box that appears, type `terraform-provi` and select the terraform provider process.
8999

90-
0. The debugger is now connected! During a typical terraform command, the plugin will be invoked multiple times. If the debugger disconnects and the plugin is invoked again later in the run, the developer will have to re-attach each time as the process ID changes.
100+
5. The debugger is now connected! During a typical terraform command, the plugin will be invoked multiple times. If the debugger disconnects and the plugin is invoked again later in the run, the developer will have to re-attach each time as the process ID changes.
91101

92102

93103
## Manual Testing
@@ -121,7 +131,7 @@ provider_installation {
121131
}
122132
```
123133

124-
See https://www.terraform.io/docs/cli/config/config-file.html for more details.
134+
See <https://www.terraform.io/docs/cli/config/config-file.html> for more details.
125135

126136
When running examples, you should spot the following warning to confirm you are using a local build:
127137

@@ -179,45 +189,45 @@ This may come in handy when debugging both acceptance and manual testing.
179189

180190
```json
181191
{
182-
// for information on how to debug the provider, see the CONTRIBUTING.md file
183-
"version": "0.2.0",
184-
"configurations": [
185-
{
186-
"name": "Launch test function",
187-
"type": "go",
188-
"request": "launch",
189-
"mode": "test",
190-
// note that the program file must be in the same package as the test to run,
191-
// though it does not necessarily have to be the file that contains the test.
192-
"program": "/home/kfcampbell/github/dev/terraform-provider-github/github/resource_github_team_members_test.go",
193-
"args": [
194-
"-test.v",
195-
"-test.run",
196-
"^TestAccGithubRepositoryTopics$" // ^ExactMatch$
197-
],
198-
"env": {
199-
"GITHUB_TEST_COLLABORATOR": "kfcampbell-terraform-test-user",
200-
"GITHUB_TEST_COLLABORATOR_TOKEN": "ghp_xxx",
201-
"GITHUB_TEST_USER": "kfcampbell",
202-
"GITHUB_TOKEN": "ghp_xxx",
203-
"GITHUB_TEMPLATE_REPOSITORY": "terraform-template-module",
204-
"GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID": "12345678",
205-
// "GITHUB_OWNER": "kfcampbell-terraform-provider",
206-
// "GITHUB_OWNER": "kfcampbell",
207-
"GITHUB_ORGANIZATION": "kfcampbell-terraform-provider", // GITHUB_ORGANIZATION is required for organization integration tests
208-
"TF_CLI_CONFIG_FILE": "/home/kfcampbell/github/dev/terraform-provider-github/examples/dev.tfrc",
209-
"TF_ACC": "1",
210-
"TF_LOG": "DEBUG",
211-
"APP_INSTALLATION_ID": "12345678"
212-
}
213-
},
214-
{
215-
"name": "Attach to Process",
216-
"type": "go",
217-
"request": "attach",
218-
"mode": "local",
219-
"processId": 0
220-
}
221-
]
192+
// for information on how to debug the provider, see the CONTRIBUTING.md file
193+
"version": "0.2.0",
194+
"configurations": [
195+
{
196+
"name": "Launch test function",
197+
"type": "go",
198+
"request": "launch",
199+
"mode": "test",
200+
// note that the program file must be in the same package as the test to run,
201+
// though it does not necessarily have to be the file that contains the test.
202+
"program": "/home/kfcampbell/github/dev/terraform-provider-github/github/resource_github_team_members_test.go",
203+
"args": [
204+
"-test.v",
205+
"-test.run",
206+
"^TestAccGithubRepositoryTopics$" // ^ExactMatch$
207+
],
208+
"env": {
209+
"GITHUB_TEST_COLLABORATOR": "kfcampbell-terraform-test-user",
210+
"GITHUB_TEST_COLLABORATOR_TOKEN": "ghp_xxx",
211+
"GITHUB_TEST_USER": "kfcampbell",
212+
"GITHUB_TOKEN": "ghp_xxx",
213+
"GITHUB_TEMPLATE_REPOSITORY": "terraform-template-module",
214+
"GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID": "12345678",
215+
// "GITHUB_OWNER": "kfcampbell-terraform-provider",
216+
// "GITHUB_OWNER": "kfcampbell",
217+
"GITHUB_ORGANIZATION": "kfcampbell-terraform-provider", // GITHUB_ORGANIZATION is required for organization integration tests
218+
"TF_CLI_CONFIG_FILE": "/home/kfcampbell/github/dev/terraform-provider-github/examples/dev.tfrc",
219+
"TF_ACC": "1",
220+
"TF_LOG": "DEBUG",
221+
"APP_INSTALLATION_ID": "12345678"
222+
}
223+
},
224+
{
225+
"name": "Attach to Process",
226+
"type": "go",
227+
"request": "attach",
228+
"mode": "local",
229+
"processId": 0
230+
}
231+
]
222232
}
223233
```

GNUmakefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ test-compile:
3737
fi
3838
CGO_ENABLED=0 go test -c $(TEST) $(TESTARGS)
3939

40+
docs-generate:
41+
@echo "==> Generating docs..."
42+
tfplugindocs generate
43+
4044
docs-lint:
4145
@echo "==> Checking docs against linters..."
4246
@misspell -error -source=text docs/
4347
@tfplugindocs validate
4448

4549

46-
.PHONY: build test testacc fmt fmtcheck lint tools test-compile docs-lint
50+
.PHONY: build test testacc fmt fmtcheck lint tools test-compile docs-generate docs-lint

0 commit comments

Comments
 (0)