Skip to content

Commit 450176c

Browse files
committed
chore: Refactor integration tests
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
1 parent 972ef3b commit 450176c

File tree

199 files changed

+8326
-12792
lines changed

Some content is hidden

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

199 files changed

+8326
-12792
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ concurrency:
1414
group: ci-${{ github.ref }}
1515
cancel-in-progress: true
1616

17-
permissions:
18-
contents: read # for actions/checkout
17+
permissions: read-all
1918

2019
jobs:
2120
ci:

.github/workflows/codeql.yaml

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
11
name: CodeQL
22

33
on:
4-
workflow_dispatch:
5-
push:
6-
branches: ["main"]
7-
pull_request:
8-
# The branches below must be a subset of the branches above
9-
branches: ["main"]
10-
schedule:
11-
- cron: "16 7 * * 5"
4+
workflow_dispatch:
5+
push:
6+
branches: ["main"]
7+
pull_request:
8+
# The branches below must be a subset of the branches above
9+
branches: ["main"]
10+
schedule:
11+
- cron: "16 7 * * 5"
1212

1313
concurrency:
14-
group: codeql-${{ github.ref }}
15-
cancel-in-progress: true
14+
group: codeql-${{ github.ref }}
15+
cancel-in-progress: true
1616

1717
permissions: read-all
1818

1919
jobs:
20-
analyze:
21-
name: Analyze (${{ matrix.language }})
22-
runs-on: ubuntu-latest
23-
permissions:
24-
actions: read
25-
contents: read
26-
security-events: write
27-
strategy:
28-
fail-fast: false
29-
matrix:
30-
include:
31-
- language: actions
32-
build-mode: none
33-
queries: security-extended # can be 'default' (use empty for 'default'), 'security-and-quality', 'security-extended'
34-
- language: go
35-
build-mode: manual
36-
queries: "" # will be used 'default' queries
37-
defaults:
38-
run:
39-
shell: bash
40-
steps:
41-
- name: Checkout
42-
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
20+
analyze:
21+
name: Analyze (${{ matrix.language }})
22+
runs-on: ubuntu-latest
23+
permissions:
24+
actions: read
25+
contents: read
26+
security-events: write
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
include:
31+
- language: actions
32+
build-mode: none
33+
queries: security-extended # can be 'default' (use empty for 'default'), 'security-and-quality', 'security-extended'
34+
- language: go
35+
build-mode: manual
36+
queries: "" # will be used 'default' queries
37+
defaults:
38+
run:
39+
shell: bash
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
4343

44-
- name: Set-up Go
45-
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
46-
if: matrix.language == 'go'
47-
with:
48-
go-version-file: go.mod
49-
cache: true
44+
- name: Set-up Go
45+
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
46+
if: matrix.language == 'go'
47+
with:
48+
go-version-file: go.mod
49+
cache: true
5050

51-
- name: Initialize CodeQL
52-
uses: github/codeql-action/init@fdbfb4d2750291e159f0156def62b853c2798ca2 # v4.31.5
53-
with:
54-
languages: ${{ matrix.language }}
55-
build-mode: ${{ matrix.build-mode }}
56-
queries: ${{ matrix.queries }}
51+
- name: Initialize CodeQL
52+
uses: github/codeql-action/init@fdbfb4d2750291e159f0156def62b853c2798ca2 # v4.31.5
53+
with:
54+
languages: ${{ matrix.language }}
55+
build-mode: ${{ matrix.build-mode }}
56+
queries: ${{ matrix.queries }}
5757

58-
- name: Build Go
59-
if: ${{ matrix.language == 'go' }}
60-
run: go build ./...
58+
- name: Build Go
59+
if: ${{ matrix.language == 'go' }}
60+
run: go build ./...
6161

62-
- name: Perform CodeQL Analysis
63-
uses: github/codeql-action/analyze@fdbfb4d2750291e159f0156def62b853c2798ca2 # v4.31.5
64-
with:
65-
category: "/language:${{matrix.language}}"
62+
- name: Perform CodeQL Analysis
63+
uses: github/codeql-action/analyze@fdbfb4d2750291e159f0156def62b853c2798ca2 # v4.31.5
64+
with:
65+
category: "/language:${{matrix.language}}"
6666

67-
check:
68-
name: Check CodeQL Analysis
69-
if: always() && github.event_name == 'pull_request'
70-
needs:
71-
- analyze
72-
runs-on: ubuntu-latest
73-
defaults:
74-
run:
75-
shell: bash
76-
steps:
77-
- name: Check
78-
env:
79-
INPUT_RESULTS: ${{ join(needs.*.result, ' ') }}
80-
run: |
81-
set -euo pipefail
82-
read -a results <<< "${INPUT_RESULTS}"
83-
for result in "${results[@]}"; do
84-
if [[ "${result}" == "failure" ]] || [[ "${result}" == "cancelled" ]]; then
85-
echo "::error::Workflow failed!"
86-
exit 1
87-
fi
88-
done
67+
check:
68+
name: Check CodeQL Analysis
69+
if: always() && github.event_name == 'pull_request'
70+
needs:
71+
- analyze
72+
runs-on: ubuntu-latest
73+
defaults:
74+
run:
75+
shell: bash
76+
steps:
77+
- name: Check
78+
env:
79+
INPUT_RESULTS: ${{ join(needs.*.result, ' ') }}
80+
run: |
81+
set -euo pipefail
82+
read -a results <<< "${INPUT_RESULTS}"
83+
for result in "${results[@]}"; do
84+
if [[ "${result}" == "failure" ]] || [[ "${result}" == "cancelled" ]]; then
85+
echo "::error::Workflow failed!"
86+
exit 1
87+
fi
88+
done

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

Lines changed: 67 additions & 26 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
@@ -29,7 +34,8 @@ jobs:
2934
strategy:
3035
matrix:
3136
mode: [anonymous, individual, organization] # team, enterprise
32-
fail-fast: false
37+
fail-fast: true
38+
max-parallel: 1
3339
defaults:
3440
run:
3541
shell: bash
@@ -38,8 +44,9 @@ jobs:
3844
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
3945

4046
- name: Check secrets
47+
if: github.event_name == 'pull_request_target'
4148
env:
42-
INPUT_ALLOWED_SECRETS: ${{ vars.DOTCOM_ACCEPTANCE_TESTS_ALLOWED_SECRETS || 'DOTCOM_TEST_USER_TOKEN' }}
49+
INPUT_ALLOWED_SECRETS: ${{ vars.DOTCOM_ACCEPTANCE_TESTS_ALLOWED_SECRETS || 'GH_TEST_TOKEN' }}
4350
INPUT_SECRETS: ${{ toJSON(secrets) }}
4451
run: |
4552
set -eou pipefail
@@ -54,36 +61,70 @@ jobs:
5461
id: credentials
5562
if: matrix.mode != 'anonymous'
5663
env:
57-
TEST_USER_TOKEN: ${{ secrets.DOTCOM_TEST_USER_TOKEN }}
64+
GH_TEST_TOKEN: ${{ secrets.GH_TEST_TOKEN }}
5865
run: |
5966
set -eou pipefail
6067
61-
if [[ -z "${TEST_USER_TOKEN}" ]]; then
68+
if [[ -z "${GH_TEST_TOKEN}" ]]; then
6269
echo "::error::Missing credentials"
6370
exit 1
6471
fi
6572
66-
echo "token=${TEST_USER_TOKEN}" >> "${GITHUB_OUTPUT}"
73+
echo "token=${GH_TEST_TOKEN}" >> "${GITHUB_OUTPUT}"
6774
6875
- name: Set-up Go
6976
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
7077
with:
7178
go-version-file: go.mod
7279
cache: true
7380

81+
- name: Setup Terraform
82+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
83+
with:
84+
terraform_version: latest
85+
terraform_wrapper: false
86+
87+
- name: Terraform lookup
88+
id: tf
89+
run: |
90+
set -euo pipefail
91+
92+
{
93+
echo "version=$(terraform version -json | jq --raw-output '.terraform_version')"
94+
echo "path=$(command -v terraform || true)"
95+
} >> "${GITHUB_OUTPUT}"
96+
7497
- name: Run tests
7598
env:
99+
TF_ACC_PROVIDER_NAMESPACE: ""
100+
TF_ACC_TERRAFORM_VERSION: ${{ steps.tf.outputs.version }}
101+
TF_ACC_TERRAFORM_PATH: ${{ steps.tf.outputs.path }}
76102
TF_ACC: "1"
77-
TF_LOG: INFO
103+
TF_LOG: WARN
78104
GITHUB_TOKEN: ${{ steps.credentials.outputs.token }}
79105
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
106+
GITHUB_OWNER: ${{ (matrix.mode == 'individual' && vars.GH_TEST_LOGIN) || (matrix.mode == 'organization' && vars.GH_TEST_ORG_NAME) || '' }}
107+
GITHUB_USERNAME: ${{ vars.GH_TEST_LOGIN }}
108+
GITHUB_ENTERPRISE_SLUG: ${{ vars.GH_TEST_ENTERPRISE_SLUG }}
109+
GH_TEST_AUTH_MODE: ${{ matrix.mode }}
110+
GH_TEST_USER_REPOSITORY: ${{ vars.GH_TEST_USER_REPOSITORY }}
111+
GH_TEST_ORG_USER: ${{ vars.GH_TEST_ORG_USER }}
112+
GH_TEST_ORG_SECRET_NAME: ${{ vars.GH_TEST_ORG_SECRET_NAME }}
113+
GH_TEST_ORG_REPOSITORY: ${{ vars.GH_TEST_ORG_REPOSITORY }}
114+
GH_TEST_ORG_TEMPLATE_REPOSITORY: ${{ vars.GH_TEST_ORG_TEMPLATE_REPOSITORY }}
115+
GH_TEST_ORG_APP_INSTALLATION_ID: ${{ vars.GH_TEST_ORG_APP_INSTALLATION_ID }}
116+
GH_TEST_EXTERNAL_USER: ${{ vars.GH_TEST_EXTERNAL_USER }}
117+
GH_TEST_EXTERNAL_USER_TOKEN: ${{ secrets.GH_TEST_EXTERNAL_USER_TOKEN }}
118+
GH_TEST_EXTERNAL_USER2: ${{ vars.GH_TEST_EXTERNAL_USER2 }}
119+
GH_TEST_ADVANCED_SECURITY: ${{ vars.GH_TEST_ADVANCED_SECURITY || 'false' }}
120+
run: |
121+
set -eou pipefail
122+
123+
if [[ "${GH_TEST_AUTH_MODE}" != "anonymous" ]]; then
124+
go test ./github -v -sweep=all
125+
fi
126+
127+
go test -run "^TestAcc*" ./github -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 120m -count=1
87128
88129
check:
89130
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

.github/workflows/labeler.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Pull Request Labeler
1+
name: PR Labeler
22

33
on:
44
pull_request_target:

.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)