@@ -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,71 @@ 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 }}
88+ deployment : false
3489 strategy :
3590 matrix :
36- mode : [anonymous, individual, organization] # team, enterprise
91+ mode : [organization] # anonymous, individual, team, enterprise
3792 fail-fast : true
3893 max-parallel : 1
3994 defaults :
@@ -44,33 +99,75 @@ jobs:
4499 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
45100
46101 - name : Check secrets
47- if : github.event_name == 'pull_request_target'
102+ if : github.event_name == 'pull_request' || github.event_name == ' pull_request_target'
48103 env :
49- INPUT_ALLOWED_SECRETS : ${{ vars.DOTCOM_ACCEPTANCE_TESTS_ALLOWED_SECRETS || 'GH_TEST_TOKEN' }}
50104 INPUT_SECRETS : ${{ toJSON(secrets) }}
105+ INPUT_ALLOWED_SECRETS : ${{ vars.GH_TEST_ALLOWED_SECRETS }}
51106 run : |
52107 set -eou pipefail
53108
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}"
109+ allowed_secrets="$(jq --raw-input --raw-output --compact-output 'split(",")' <<<"${INPUT_ALLOWED_SECRETS}")"
110+
111+ 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}")"
112+ if [[ -n "${secret_keys}" ]]; then
113+ echo "::error::Unexpected secrets: ${secret_keys}"
57114 exit 1
58115 fi
59116
60117 - name : Check credentials
61118 id : credentials
62119 if : matrix.mode != 'anonymous'
63120 env :
121+ MATRIX_MODE : ${{ matrix.mode }}
122+ GH_TEST_APP_ID : ${{ vars.GH_TEST_APP_ID }}
123+ GH_TEST_APP_INSTALLATION_ID : ${{ vars.GH_TEST_APP_INSTALLATION_ID }}
124+ GH_TEST_APP_PEM : ${{ secrets.GH_TEST_APP_PEM }}
64125 GH_TEST_TOKEN : ${{ secrets.GH_TEST_TOKEN }}
65126 run : |
66127 set -eou pipefail
67128
68- if [[ -z "${GH_TEST_TOKEN}" ]]; then
69- echo "::error::Missing credentials"
70- exit 1
129+ app_id=""
130+ app_installation_id=""
131+ app_pem=""
132+ token=""
133+
134+ if [[ "${MATRIX_MODE}" == "individual" ]]; then
135+ if [[ -z "${GH_TEST_TOKEN}" ]]; then
136+ echo "::error::Missing token"
137+ exit 1
138+ fi
139+
140+ token="${GH_TEST_TOKEN}"
141+ else
142+ if [[ -z "${GH_TEST_APP_ID}" ]]; then
143+ echo "::error::Missing app id"
144+ exit 1
145+ fi
146+
147+ if [[ -z "${GH_TEST_APP_INSTALLATION_ID}" ]]; then
148+ echo "::error::Missing app installation id"
149+ exit 1
150+ fi
151+
152+ if [[ -z "${GH_TEST_APP_PEM}" ]]; then
153+ echo "::error::Missing app pem"
154+ exit 1
155+ fi
156+
157+ app_id="${GH_TEST_APP_ID}"
158+ app_installation_id="${GH_TEST_APP_INSTALLATION_ID}"
159+ app_pem="${GH_TEST_APP_PEM}"
71160 fi
72161
73- echo "token=${GH_TEST_TOKEN}" >> "${GITHUB_OUTPUT}"
162+ {
163+ echo "app_id=${app_id}"
164+ echo "app_installation_id=${app_installation_id}"
165+ printf 'app_pem<<EOF
166+ %s
167+ EOF
168+ ' "${app_pem}"
169+ echo "token=${token}"
170+ } >> "${GITHUB_OUTPUT}"
74171
75172 - name : Set-up Go
76173 uses : actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
@@ -101,11 +198,16 @@ jobs:
101198 TF_ACC_TERRAFORM_PATH : ${{ steps.tf.outputs.path }}
102199 TF_ACC : " 1"
103200 TF_LOG : WARN
201+ GITHUB_WRITE_DELAY_MS : " 0"
202+ GITHUB_PARALLEL_REQUESTS : " true"
203+ GITHUB_APP_ID : ${{ steps.credentials.outputs.app_id }}
204+ GITHUB_APP_INSTALLATION_ID : ${{ steps.credentials.outputs.app_installation_id }}
205+ GITHUB_APP_PEM_FILE : ${{ steps.credentials.outputs.app_pem }}
104206 GITHUB_TOKEN : ${{ steps.credentials.outputs.token }}
105207 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 }}
208+ GITHUB_OWNER : ${{ case (matrix.mode == 'anonymous', '', matrix.mode == 'individual', vars.GH_TEST_LOGIN, vars.GH_TEST_ORG_NAME) }}
209+ GITHUB_USERNAME : ${{ case(matrix.mode == 'individual', vars.GH_TEST_LOGIN, '') }}
210+ GITHUB_ENTERPRISE_SLUG : ${{ case(matrix.mode == 'enterprise', vars.GH_TEST_ENTERPRISE_SLUG, '') }}
109211 GH_TEST_AUTH_MODE : ${{ matrix.mode }}
110212 GH_TEST_USER_REPOSITORY : ${{ vars.GH_TEST_USER_REPOSITORY }}
111213 GH_TEST_ORG_USER : ${{ vars.GH_TEST_ORG_USER }}
@@ -128,7 +230,7 @@ jobs:
128230
129231 check :
130232 name : Check DotCom Acceptance Tests
131- if : always() && github.event_name == 'pull_request'
233+ if : always() && ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target')
132234 needs :
133235 - test
134236 runs-on : ubuntu-latest
0 commit comments