@@ -2,10 +2,11 @@ name: Acceptance Tests (github.com)
22
33on :
44 workflow_dispatch :
5- # push:
6- # branches:
7- # - main
8- # - release-v*
5+ push :
6+ branches :
7+ - main
8+ - release-v*
9+ # pull_request_target:
910 pull_request :
1011 types :
1112 - opened
@@ -23,17 +24,70 @@ concurrency:
2324permissions : read-all
2425
2526jobs :
27+ setup :
28+ name : Setup
29+ runs-on : ubuntu-latest
30+ defaults :
31+ run :
32+ shell : bash
33+ outputs :
34+ fork : ${{ steps.check.outputs.fork }}
35+ test : ${{ steps.check.outputs.test }}
36+ environment : ${{ steps.check.outputs.environment }}
37+ steps :
38+ - name : Check
39+ id : check
40+ env :
41+ GITHUB_HEAD_REPO : ${{ case(github.event_name == 'pull_request' || github.event_name == 'pull_request_target', github.event.pull_request.head.repo.full_name, github.repository) }}
42+ GITHUB_BASE_REPO : ${{ case(github.event_name == 'pull_request' || github.event_name == 'pull_request_target', github.event.pull_request.base.repo.full_name, github.repository) }}
43+ ACCTEST_LABEL_SET : ${{ contains(github.event.pull_request.labels.*.name, 'acctest') }}
44+ run : |
45+ set -euo pipefail
46+
47+ fork="true"
48+ test="false"
49+ environment="acctest-dotcom-untrusted"
50+
51+ if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]] || [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
52+ fork="false"
53+ test="true"
54+ environment="acctest-dotcom"
55+ echo "::notice::Running in ${GITHUB_EVENT_NAME} context, proceeding with tests"
56+ else
57+ if [[ "${GITHUB_HEAD_REPO}" == "${GITHUB_BASE_REPO}" ]]; then
58+ fork="false"
59+ test="true"
60+ environment="acctest-dotcom"
61+ echo "::notice::Running in ${GITHUB_EVENT_NAME} context from the base repository, proceeding with tests"
62+ else
63+ if [[ "${ACCTEST_LABEL_SET}" == "true" ]]; then
64+ test="true"
65+ echo "::warning::Running in ${GITHUB_EVENT_NAME} context from a fork, proceeding with tests as acctest label is set"
66+ else
67+ echo "::warning::Running in ${GITHUB_EVENT_NAME} context from a fork, skipping tests as acctest label is not set"
68+ fi
69+ fi
70+ fi
71+
72+ {
73+ echo "test=${test}"
74+ echo "environment=${environment}"
75+ echo "fork=${fork}"
76+ } >> "${GITHUB_OUTPUT}"
77+
2678 test :
27- 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')
79+ name : Test ${{ matrix.mode || 'Skipped' }}
80+ needs :
81+ - setup
82+ if : needs.setup.outputs.test == 'true'
2983 runs-on : ubuntu-latest
3084 permissions :
3185 contents : read
3286 environment :
33- name : acctest-dotcom
87+ name : ${{ needs.setup.outputs.environment }}
3488 strategy :
3589 matrix :
36- mode : [anonymous, individual, organization] # team, enterprise
90+ mode : [organization] # anonymous, individual, team, enterprise
3791 fail-fast : true
3892 max-parallel : 1
3993 defaults :
@@ -44,33 +98,75 @@ jobs:
4498 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4599
46100 - name : Check secrets
47- if : github.event_name == 'pull_request_target'
101+ if : github.event_name == 'pull_request' || github.event_name == ' pull_request_target'
48102 env :
49- INPUT_ALLOWED_SECRETS : ${{ vars.DOTCOM_ACCEPTANCE_TESTS_ALLOWED_SECRETS || 'GH_TEST_TOKEN' }}
50103 INPUT_SECRETS : ${{ toJSON(secrets) }}
104+ INPUT_ALLOWED_SECRETS : ${{ vars.GH_TEST_ALLOWED_SECRETS }}
51105 run : |
52106 set -eou pipefail
53107
54- secret_keys="$(jq --raw-output --compact-output '[. | keys[] | select(test("^(?:(?:ACTIONS)|(?:actions)|(?:GITHUB)|(?:github)|(?:TEST)|(?:test))_") | not)] | sort | join(",")' <<<"${INPUT_SECRETS}")"
55- if [[ "${secret_keys}" != "${INPUT_ALLOWED_SECRETS}" ]]; then
56- echo "::error::Too many or too few secrets configured: ${secret_keys}"
108+ allowed_secrets="$(jq --raw-input --raw-output --compact-output 'split(",")' <<<"${INPUT_ALLOWED_SECRETS}")"
109+
110+ secret_keys="$(jq --raw-output --compact-output --argjson allowed "${allowed_secrets}" '[[. | to_entries[] | select(.value != "" and .value != "!NOSECRET!")] | from_entries | keys[] | ascii_upcase | select(test("^(?:(?:ACTIONS)|(?:GITHUB)|(?:TEST)|(?:GH_TEST))_") | not) | select((IN($allowed[]) | not))] | sort | join(",")' <<<"${INPUT_SECRETS}")"
111+ if [[ -n "${secret_keys}" ]]; then
112+ echo "::error::Unexpected secrets: ${secret_keys}"
57113 exit 1
58114 fi
59115
60116 - name : Check credentials
61117 id : credentials
62118 if : matrix.mode != 'anonymous'
63119 env :
120+ MATRIX_MODE : ${{ matrix.mode }}
121+ GH_TEST_APP_ID : ${{ vars.GH_TEST_APP_ID }}
122+ GH_TEST_APP_INSTALLATION_ID : ${{ vars.GH_TEST_APP_INSTALLATION_ID }}
123+ GH_TEST_APP_PEM : ${{ secrets.GH_TEST_APP_PEM }}
64124 GH_TEST_TOKEN : ${{ secrets.GH_TEST_TOKEN }}
65125 run : |
66126 set -eou pipefail
67127
68- if [[ -z "${GH_TEST_TOKEN}" ]]; then
69- echo "::error::Missing credentials"
70- exit 1
128+ app_id=""
129+ app_installation_id=""
130+ app_pem=""
131+ token=""
132+
133+ if [[ "${MATRIX_MODE}" == "individual" ]]; then
134+ if [[ -z "${GH_TEST_TOKEN}" ]]; then
135+ echo "::error::Missing token"
136+ exit 1
137+ fi
138+
139+ token="${GH_TEST_TOKEN}"
140+ else
141+ if [[ -z "${GH_TEST_APP_ID}" ]]; then
142+ echo "::error::Missing app id"
143+ exit 1
144+ fi
145+
146+ if [[ -z "${GH_TEST_APP_INSTALLATION_ID}" ]]; then
147+ echo "::error::Missing app installation id"
148+ exit 1
149+ fi
150+
151+ if [[ -z "${GH_TEST_APP_PEM}" ]]; then
152+ echo "::error::Missing app pem"
153+ exit 1
154+ fi
155+
156+ app_id="${GH_TEST_APP_ID}"
157+ app_installation_id="${GH_TEST_APP_INSTALLATION_ID}"
158+ app_pem="${GH_TEST_APP_PEM}"
71159 fi
72160
73- echo "token=${GH_TEST_TOKEN}" >> "${GITHUB_OUTPUT}"
161+ {
162+ echo "app_id=${app_id}"
163+ echo "app_installation_id=${app_installation_id}"
164+ printf 'app_pem<<EOF
165+ %s
166+ EOF
167+ ' "${app_pem}"
168+ echo "token=${token}"
169+ } >> "${GITHUB_OUTPUT}"
74170
75171 - name : Set-up Go
76172 uses : actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
@@ -101,11 +197,14 @@ jobs:
101197 TF_ACC_TERRAFORM_PATH : ${{ steps.tf.outputs.path }}
102198 TF_ACC : " 1"
103199 TF_LOG : WARN
200+ GITHUB_APP_ID : ${{ steps.credentials.outputs.app_id }}
201+ GITHUB_APP_INSTALLATION_ID : ${{ steps.credentials.outputs.app_installation_id }}
202+ GITHUB_APP_PEM_FILE : ${{ steps.credentials.outputs.app_pem }}
104203 GITHUB_TOKEN : ${{ steps.credentials.outputs.token }}
105204 GITHUB_BASE_URL : https://api.github.com/
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 }}
205+ GITHUB_OWNER : ${{ case (matrix.mode == 'anonymous', '', matrix.mode == 'individual', vars.GH_TEST_LOGIN, vars.GH_TEST_ORG_NAME) }}
206+ GITHUB_USERNAME : ${{ case(matrix.mode == 'individual', vars.GH_TEST_LOGIN, '') }}
207+ GITHUB_ENTERPRISE_SLUG : ${{ case(matrix.mode == 'enterprise', vars.GH_TEST_ENTERPRISE_SLUG, '') }}
109208 GH_TEST_AUTH_MODE : ${{ matrix.mode }}
110209 GH_TEST_USER_REPOSITORY : ${{ vars.GH_TEST_USER_REPOSITORY }}
111210 GH_TEST_ORG_USER : ${{ vars.GH_TEST_ORG_USER }}
@@ -128,7 +227,7 @@ jobs:
128227
129228 check :
130229 name : Check DotCom Acceptance Tests
131- if : always() && github.event_name == 'pull_request'
230+ if : always() && ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target')
132231 needs :
133232 - test
134233 runs-on : ubuntu-latest
0 commit comments