Skip to content

Commit 86c88d6

Browse files
committed
chore: Refactor integration tests
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
1 parent a3b39ed commit 86c88d6

File tree

180 files changed

+7544
-12609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+7544
-12609
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ jobs:
2424
defaults:
2525
run:
2626
shell: bash
27-
env:
28-
GITHUB_TEST_ORGANIZATION: kfcampbell-terraform-provider
2927
steps:
3028
- name: Checkout
3129
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0

.github/workflows/dotcom-acceptance-tests.yaml

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@ name: Acceptance Tests (github.com)
22

33
on:
44
workflow_dispatch:
5-
# push:
6-
# branches:
7-
# - main
8-
# - release-v*
9-
# pull_request_target:
10-
# types:
11-
# - opened
12-
# - synchronize
13-
# - reopened
14-
# - labeled
15-
# branches:
16-
# - main
17-
# - release-v*
5+
push:
6+
branches:
7+
- main
8+
- release-v*
9+
pull_request:
10+
types:
11+
- opened
12+
- synchronize
13+
- reopened
14+
- labeled
15+
branches:
16+
- main
17+
- release-v*
18+
19+
concurrency:
20+
group: acctest-dotcom-${{ github.ref }}
21+
cancel-in-progress: true
1822

1923
permissions: read-all
2024

2125
jobs:
2226
test:
2327
name: Test ${{ matrix.mode }}
28+
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || contains(github.event.pull_request.labels.*.name, 'acctest')
2429
runs-on: ubuntu-latest
2530
permissions:
2631
contents: read
@@ -38,8 +43,9 @@ jobs:
3843
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
3944

4045
- name: Check secrets
46+
if: github.event_name == 'pull_request_target'
4147
env:
42-
INPUT_ALLOWED_SECRETS: ${{ vars.DOTCOM_ACCEPTANCE_TESTS_ALLOWED_SECRETS || 'DOTCOM_TEST_USER_TOKEN' }}
48+
INPUT_ALLOWED_SECRETS: ${{ vars.DOTCOM_ACCEPTANCE_TESTS_ALLOWED_SECRETS || 'GH_TEST_TOKEN' }}
4349
INPUT_SECRETS: ${{ toJSON(secrets) }}
4450
run: |
4551
set -eou pipefail
@@ -54,36 +60,70 @@ jobs:
5460
id: credentials
5561
if: matrix.mode != 'anonymous'
5662
env:
57-
TEST_USER_TOKEN: ${{ secrets.DOTCOM_TEST_USER_TOKEN }}
63+
GH_TEST_TOKEN: ${{ secrets.GH_TEST_TOKEN }}
5864
run: |
5965
set -eou pipefail
6066
61-
if [[ -z "${TEST_USER_TOKEN}" ]]; then
67+
if [[ -z "${GH_TEST_TOKEN}" ]]; then
6268
echo "::error::Missing credentials"
6369
exit 1
6470
fi
6571
66-
echo "token=${TEST_USER_TOKEN}" >> "${GITHUB_OUTPUT}"
72+
echo "token=${GH_TEST_TOKEN}" >> "${GITHUB_OUTPUT}"
6773
6874
- name: Set-up Go
6975
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
7076
with:
7177
go-version-file: go.mod
7278
cache: true
7379

80+
- name: Setup Terraform
81+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
82+
with:
83+
terraform_version: latest
84+
terraform_wrapper: false
85+
86+
- name: Terraform lookup
87+
id: tf
88+
run: |
89+
set -euo pipefail
90+
91+
{
92+
echo "version=$(terraform version -json | jq --raw-output '.terraform_version')"
93+
echo "path=$(command -v terraform || true)"
94+
} >> "${GITHUB_OUTPUT}"
95+
7496
- name: Run tests
7597
env:
98+
TF_ACC_PROVIDER_NAMESPACE: ""
99+
TF_ACC_TERRAFORM_VERSION: ${{ steps.tf.outputs.version }}
100+
TF_ACC_TERRAFORM_PATH: ${{ steps.tf.outputs.path }}
76101
TF_ACC: "1"
77-
TF_LOG: INFO
102+
TF_LOG: WARN
78103
GITHUB_TOKEN: ${{ steps.credentials.outputs.token }}
79104
GITHUB_BASE_URL: https://api.github.com/
80-
GITHUB_TEST_TYPE: ${{ matrix.mode }}
81-
GITHUB_OWNER: ${{ (matrix.mode == 'individual' && 'github-terraform-test-user') || (matrix.mode == 'organization' && 'terraformtesting') || '' }}
82-
GITHUB_ORGANIZATION: ${{ (matrix.mode == 'organization' && 'terraformtesting') || '' }}
83-
GITHUB_TEST_ORGANIZATION: ${{ (matrix.mode == 'individual' && 'terraformtesting') || '' }}
84-
GITHUB_TEST_OWNER: ${{ (matrix.mode == 'organization' && 'github-terraform-test-user') || '' }}
85-
GITHUB_TEST_USER_TOKEN: ${{ steps.credentials.outputs.token }}
86-
run: go test -run "^TestAcc*" ./github -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 120m -count=1
105+
GITHUB_OWNER: ${{ (matrix.mode == 'individual' && vars.GH_TEST_LOGIN) || (matrix.mode == 'organization' && vars.GH_TEST_ORG_NAME) || '' }}
106+
GITHUB_USERNAME: ${{ vars.GH_TEST_LOGIN }}
107+
GITHUB_ENTERPRISE_SLUG: ${{ vars.GH_TEST_ENTERPRISE_SLUG }}
108+
GH_TEST_AUTH_MODE: ${{ matrix.mode }}
109+
GH_TEST_USER_REPOSITORY: ${{ vars.GH_TEST_USER_REPOSITORY }}
110+
GH_TEST_ORG_USER: ${{ vars.GH_TEST_ORG_USER }}
111+
GH_TEST_ORG_SECRET_NAME: ${{ vars.GH_TEST_ORG_SECRET_NAME }}
112+
GH_TEST_ORG_REPOSITORY: ${{ vars.GH_TEST_ORG_REPOSITORY }}
113+
GH_TEST_ORG_TEMPLATE_REPOSITORY: ${{ vars.GH_TEST_ORG_TEMPLATE_REPOSITORY }}
114+
GH_TEST_ORG_APP_INSTALLATION_ID: ${{ vars.GH_TEST_ORG_APP_INSTALLATION_ID }}
115+
GH_TEST_EXTERNAL_USER: ${{ vars.GH_TEST_EXTERNAL_USER }}
116+
GH_TEST_EXTERNAL_USER_TOKEN: ${{ secrets.GH_TEST_EXTERNAL_USER_TOKEN }}
117+
GH_TEST_EXTERNAL_USER2: ${{ vars.GH_TEST_EXTERNAL_USER2 }}
118+
GH_TEST_ADVANCED_SECURITY: ${{ vars.GH_TEST_ADVANCED_SECURITY || 'false' }}
119+
run: |
120+
set -eou pipefail
121+
122+
if [[ "${GH_TEST_AUTH_MODE}" != "anonymous" ]]; then
123+
go test ./github -v -sweep=all
124+
fi
125+
126+
go test -run "^TestAcc*" ./github -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 120m -count=1
87127
88128
check:
89129
name: Check DotCom Acceptance Tests

.github/workflows/ghes-acceptance-tests.yaml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
# - main
1313
# - release-v*
1414

15+
concurrency:
16+
group: acctest-ghes-${{ github.ref }}
17+
cancel-in-progress: true
18+
1519
permissions: read-all
1620

1721
jobs:
@@ -30,6 +34,7 @@ jobs:
3034
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
3135

3236
- name: Check secrets
37+
if: github.event_name == 'pull_request_target'
3338
env:
3439
INPUT_ALLOWED_SECRETS: ${{ vars.GHES_ACCEPTANCE_TESTS_ALLOWED_SECRETS || 'GHES_TEST_USER_TOKEN' }}
3540
INPUT_SECRETS: ${{ toJSON(secrets) }}
@@ -85,17 +90,40 @@ jobs:
8590
go-version-file: go.mod
8691
cache: true
8792

93+
- name: Setup Terraform
94+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
95+
with:
96+
terraform_version: latest
97+
terraform_wrapper: false
98+
99+
- name: Terraform lookup
100+
id: tf
101+
run: |
102+
set -euo pipefail
103+
104+
{
105+
echo "version=$(terraform version -json | jq --raw-output '.terraform_version')"
106+
echo "path=$(command -v terraform || true)"
107+
} >> "${GITHUB_OUTPUT}"
108+
88109
- name: Run tests
89110
env:
111+
TF_ACC_PROVIDER_NAMESPACE: ""
112+
TF_ACC_TERRAFORM_VERSION: ${{ steps.tf.outputs.version }}
113+
TF_ACC_TERRAFORM_PATH: ${{ steps.tf.outputs.path }}
90114
TF_ACC: "1"
91-
TF_LOG: INFO
115+
TF_LOG: WARN
92116
GITHUB_TOKEN: ${{ steps.credentials.outputs.token }}
93117
GITHUB_BASE_URL: ${{ steps.server.outputs.address }}
94-
GITHUB_TEST_TYPE: enterprise
95-
GITHUB_OWNER: terraformtesting
96-
GITHUB_ORGANIZATION: terraformtesting
97-
GITHUB_TEST_USER_TOKEN: ${{ steps.credentials.outputs.token }}
98-
run: go test -run "^TestAcc*" ./github -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 120m -count=1
118+
GITHUB_OWNER: ""
119+
GITHUB_USERNAME: ""
120+
GITHUB_ENTERPRISE_SLUG: ""
121+
GH_TEST_AUTH_MODE: enterprise
122+
run: |
123+
set -eou pipefail
124+
125+
go test ./github -v -sweep=all
126+
go test -run "^TestAcc*" ./github -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 120m -count=1
99127
100128
check:
101129
name: Check GHES Acceptance Tests

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ terraform-provider-github
3636

3737
# do not commit secrets
3838
.env
39+
*_rsa
40+
*_rsa.pub

0 commit comments

Comments
 (0)