@@ -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,69 @@ 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+ echo "::notice::Running in ${GITHUB_EVENT_NAME} context from the base repository, proceeding with tests"
61+ else
62+ if [[ "${ACCTEST_LABEL_SET}" == "true" ]]; then
63+ test="true"
64+ echo "::warning::Running in ${GITHUB_EVENT_NAME} context from a fork with acctest label, proceeding with tests"
65+ else
66+ echo "::warning::Running in ${GITHUB_EVENT_NAME} context from a fork, skipping tests"
67+ fi
68+ fi
69+ fi
70+
71+ {
72+ echo "test=${test}"
73+ echo "environment=${environment}"
74+ echo "fork=${fork}"
75+ } >> "${GITHUB_OUTPUT}"
76+
2677 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')
78+ name : Test ${{ matrix.mode || 'Skipped' }}
79+ needs :
80+ - setup
81+ if : needs.setup.outputs.test == 'true'
2982 runs-on : ubuntu-latest
3083 permissions :
3184 contents : read
3285 environment :
33- name : acctest-dotcom
86+ name : ${{ needs.setup.outputs.environment }}
3487 strategy :
3588 matrix :
36- mode : [anonymous, individual, organization] # team, enterprise
89+ mode : [anonymous, organization] # individual, team, enterprise
3790 fail-fast : true
3891 max-parallel : 1
3992 defaults :
@@ -44,33 +97,72 @@ jobs:
4497 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4598
4699 - name : Check secrets
47- if : github.event_name == 'pull_request_target'
100+ if : github.event_name == 'pull_request' || github.event_name == ' pull_request_target'
48101 env :
49- INPUT_ALLOWED_SECRETS : ${{ vars.DOTCOM_ACCEPTANCE_TESTS_ALLOWED_SECRETS || 'GH_TEST_TOKEN' }}
50102 INPUT_SECRETS : ${{ toJSON(secrets) }}
103+ INPUT_ALLOWED_SECRETS : ${{ vars.GH_TEST_ALLOWED_SECRETS }}
51104 run : |
52105 set -eou pipefail
53106
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}"
107+ allowed_secrets="$(jq --raw-input --raw-output --compact-output '[split(",")[] | trimstr(" ")]' <<<"${INPUT_ALLOWED_SECRETS}")"
108+
109+ secret_keys="$(jq --raw-output --compact-output --argjson allowed "${allowed_secrets}" '[[. | to_entries[] | select(.value != "" and .value != "-")] | from_entries | keys[] | ascii_upcase | select(test("^(?:(?:ACTIONS)|(?:GITHUB)|(?:TEST)|(?:GH_TEST))_") | not) | select((IN($allowed[]) | not))] | sort | join(",")' <<<"${INPUT_SECRETS}")"
110+ if [[ -n "${secret_keys}" ]]; then
111+ echo "::error::Unexpected secrets: ${secret_keys}"
57112 exit 1
58113 fi
59114
60115 - name : Check credentials
61116 id : credentials
62117 if : matrix.mode != 'anonymous'
63118 env :
119+ MATRIX_MODE : ${{ matrix.mode }}
120+ GH_TEST_APP_ID : ${{ vars.GH_TEST_APP_ID }}
121+ GH_TEST_APP_INSTALLATION_ID : ${{ vars.GH_TEST_APP_INSTALLATION_ID }}
122+ GH_TEST_APP_PEM : ${{ secrets.GH_TEST_APP_PEM }}
64123 GH_TEST_TOKEN : ${{ secrets.GH_TEST_TOKEN }}
65124 run : |
66125 set -eou pipefail
67126
68- if [[ -z "${GH_TEST_TOKEN}" ]]; then
69- echo "::error::Missing credentials"
70- exit 1
127+ app_id=""
128+ app_installation_id=""
129+ app_pem=""
130+ token=""
131+
132+ if [[ "${MATRIX_MODE}" == "individual" ]]; then
133+ if [[ -z "${GH_TEST_TOKEN}" ]]; then
134+ echo "::error::Missing token"
135+ exit 1
136+ fi
137+
138+ token="${GH_TEST_TOKEN}"
139+ else
140+ if [[ -z "${GH_TEST_APP_ID}" ]]; then
141+ echo "::error::Missing app id"
142+ exit 1
143+ fi
144+
145+ if [[ -z "${GH_TEST_APP_INSTALLATION_ID}" ]]; then
146+ echo "::error::Missing app installation id"
147+ exit 1
148+ fi
149+
150+ if [[ -z "${GH_TEST_APP_PEM}" ]]; then
151+ echo "::error::Missing app pem"
152+ exit 1
153+ fi
154+
155+ app_id="${GH_TEST_APP_ID}"
156+ app_installation_id="${GH_TEST_APP_INSTALLATION_ID}"
157+ app_pem="${GH_TEST_APP_PEM}"
71158 fi
72159
73- echo "token=${GH_TEST_TOKEN}" >> "${GITHUB_OUTPUT}"
160+ {
161+ echo "app_id=${app_id}"
162+ echo "app_installation_id=${app_installation_id}"
163+ echo "app_pem=${app_pem}"
164+ echo "token=${token}"
165+ } >> "${GITHUB_OUTPUT}"
74166
75167 - name : Set-up Go
76168 uses : actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
@@ -101,11 +193,14 @@ jobs:
101193 TF_ACC_TERRAFORM_PATH : ${{ steps.tf.outputs.path }}
102194 TF_ACC : " 1"
103195 TF_LOG : WARN
196+ GITHUB_APP_ID : ${{ steps.credentials.outputs.app_id }}
197+ GITHUB_APP_INSTALLATION_ID : ${{ steps.credentials.outputs.app_installation_id }}
198+ GITHUB_APP_PEM_FILE : ${{ steps.credentials.outputs.app_pem }}
104199 GITHUB_TOKEN : ${{ steps.credentials.outputs.token }}
105200 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 }}
201+ GITHUB_OWNER : ${{ case (matrix.mode == 'anonymous', '', matrix.mode == 'individual', vars.GH_TEST_LOGIN, vars.GH_TEST_ORG_NAME) }}
202+ GITHUB_USERNAME : ${{ case(matrix.mode == 'individual', vars.GH_TEST_LOGIN, '') }}
203+ GITHUB_ENTERPRISE_SLUG : ${{ case(matrix.mode == 'enterprise', vars.GH_TEST_ENTERPRISE_SLUG, '') }}
109204 GH_TEST_AUTH_MODE : ${{ matrix.mode }}
110205 GH_TEST_USER_REPOSITORY : ${{ vars.GH_TEST_USER_REPOSITORY }}
111206 GH_TEST_ORG_USER : ${{ vars.GH_TEST_ORG_USER }}
@@ -128,7 +223,7 @@ jobs:
128223
129224 check :
130225 name : Check DotCom Acceptance Tests
131- if : always() && github.event_name == 'pull_request'
226+ if : always() && ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target')
132227 needs :
133228 - test
134229 runs-on : ubuntu-latest
0 commit comments