You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+54-33Lines changed: 54 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,11 @@ Before submitting an issue or a pull request, please search the repository for e
10
10
11
11
## Submitting a pull request
12
12
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. Push to your fork and submit a pull request.
17
+
5. Pat yourself on the back and wait for your pull request to be reviewed and merged.
18
18
19
19
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
20
20
@@ -38,21 +38,28 @@ Once you have the repository cloned, there's a couple of additional steps you'll
38
38
- You _must_ make sure that the "Template Repository" item in Settings is checked for this repo.
39
39
- If you haven't already, generate a Personal Access Token (PAT) for authenticating your test runs.
40
40
- Export the necessary configuration for authenticating your provider with GitHub
41
+
41
42
```sh
42
-
export GITHUB_TOKEN=<token of a user with an organization account>
43
-
export GITHUB_ORGANIZATION=<name of an organization>
43
+
export GITHUB_TEST_AUTH_MODE="organization"
44
+
export GITHUB_OWNER="<name of an organization>"
45
+
export GITHUB_USERNAME="<username of the user who created the token>"
46
+
export GITHUB_TOKEN="<token of a user with an organization account>"
44
47
```
48
+
45
49
- Build the project with `make build`
46
50
- 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.
47
51
48
52
### Local Development Iteration
49
53
50
54
1. Write a test describing what you will fix. See [`github_label`](./github/resource_github_issue_label_test.go) for an example format.
51
55
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
+
52
57
```sh
53
58
TF_LOG=DEBUG TF_ACC=1 go test -v ./... -run ^TestAccGithubIssueLabel
54
59
```
60
+
55
61
1. Align the resource's implementation to your test case and observe it pass:
62
+
56
63
```sh
57
64
TF_ACC=1 go test -v ./... -run ^TestAccGithubIssueLabel
58
65
```
@@ -67,7 +74,8 @@ Println debugging can easily be used to obtain information about how code change
67
74
68
75
If a full debugger is desired, VSCode may be used. In order to do so,
69
76
70
-
0. Create a launch.json file with this configuration:
77
+
1. Create a launch.json file with this configuration:
78
+
71
79
```json
72
80
{
73
81
"name": "Attach to Process",
@@ -77,18 +85,18 @@ If a full debugger is desired, VSCode may be used. In order to do so,
77
85
"processId": 0,
78
86
}
79
87
```
80
-
Setting a `processId` of 0 allows a dropdown to select the process of the provider.
81
88
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.
89
+
Setting a `processId` of 0 allows a dropdown to select the process of the provider.
83
90
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/`.
91
+
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.
85
92
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.
93
+
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/`.
87
94
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.
95
+
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.
89
96
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.
97
+
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.
91
98
99
+
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.
92
100
93
101
## Manual Testing
94
102
@@ -99,7 +107,7 @@ Manual testing should be performed on each PR opened in order to validate the pr
99
107
Build the provider and specify the output directory:
100
108
101
109
```sh
102
-
$ go build -gcflags="all=-N -l" -o ~/go/bin/
110
+
go build -gcflags="all=-N -l" -o ~/go/bin/
103
111
```
104
112
105
113
This enables verifying your locally built provider using examples available in the `examples/` directory.
@@ -121,7 +129,7 @@ provider_installation {
121
129
}
122
130
```
123
131
124
-
See https://www.terraform.io/docs/cli/config/config-file.html for more details.
132
+
See <https://www.terraform.io/docs/cli/config/config-file.html> for more details.
125
133
126
134
When running examples, you should spot the following warning to confirm you are using a local build:
127
135
@@ -137,37 +145,50 @@ The following provider development overrides are set in the CLI configuration:
137
145
Commonly required environment variables are listed below:
138
146
139
147
```sh
140
-
#enable debug logging
148
+
#Enable debug logging
141
149
export TF_LOG=DEBUG
142
150
143
-
# enable testing of organization scenarios instead of individual or anonymous
144
-
export GITHUB_ORGANIZATION=
145
-
146
-
# enable testing of individual scenarios instead of organization or anonymous
147
-
export GITHUB_OWNER=
151
+
# Enables acceptance tests
152
+
export TF_ACC="1"
148
153
149
-
#enable testing of enterprise appliances
154
+
#Configure the URL override for GHES.
150
155
export GITHUB_BASE_URL=
151
156
152
157
# enable testing of GitHub Paid features, these normally also require an organization e.g. repository push rulesets
153
158
export GITHUB_PAID_FEATURES=true
154
159
155
-
# leverage helper accounts for tests requiring them
156
-
# examples include:
157
-
# - https://github.com/github-terraform-test-user
158
-
# - https://github.com/terraformtesting
159
-
export GITHUB_TEST_OWNER=
160
-
export GITHUB_TEST_ORGANIZATION=
161
-
export GITHUB_TEST_USER_TOKEN=
162
-
```
160
+
# Configure acceptance testing mode; one of anonymous, individual, organization, team or enterprise. If not set will default to anonymous
161
+
export GITHUB_TEST_AUTH_MODE=
163
162
164
-
See [this project](https://github.com/terraformtesting/acceptance-tests) for more information on our old system for automated testing.
163
+
# Configure authentication for testing
164
+
export GITHUB_OWNER=
165
+
export GITHUB_USERNAME=
166
+
export GITHUB_TOKEN=
167
+
168
+
# Configure user level values
169
+
export GITHUB_TEST_USER_REPOSITORY=
170
+
171
+
# Configure for the org under test
172
+
export GITHUB_TEST_ORG_USER=
173
+
export GITHUB_TEST_ORG_SECRET_NAME=
174
+
export GITHUB_TEST_ORG_REPOSITORY=
175
+
export GITHUB_TEST_ORG_TEMPLATE_REPOSITORY=
176
+
export GITHUB_TEST_ORG_APP_INSTALLATION_ID=
177
+
178
+
# Configure external (non-org) users
179
+
export GITHUB_TEST_EXTERNAL_USER=
180
+
export GITHUB_TEST_EXTERNAL_USER_TOKEN=
181
+
export GITHUB_TEST_EXTERNAL_USER2=
182
+
183
+
# Configure test options
184
+
export GITHUB_TEST_ADVANCED_SECURITY=
185
+
```
165
186
166
187
There are also a small amount of unit tests in the provider. Due to the nature of the provider, such tests are currently only recommended for exercising functionality completely internal to the provider. These may be executed by running `make test`.
167
188
168
189
### GitHub Organization
169
190
170
-
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`.
191
+
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`.
171
192
172
193
Make sure that your organization has a `terraform-template-module` repository ([terraformtesting/terraform-template-module](https://github.com/terraformtesting/terraform-template-module) is an example you can clone) and that its "Template repository" item in Settings is checked.
0 commit comments