Skip to content

Commit ad2452b

Browse files
committed
[TRUNK-14636] Use gh context with use_uncloned_repo
Adds a use_uncloned_repo flag that manually sets as much context as possible using gh context and the pull_request event.
1 parent 330ad5d commit ad2452b

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

action.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ inputs:
5050
variant:
5151
description: User specified variant of a set of tests being uploaded.
5252
required: false
53+
use-uncloned-repo:
54+
description: Set to 'true' if your tests do not require cloning the repository under test,
55+
required: false
56+
default: "false"
5357

5458
runs:
5559
using: composite
@@ -73,3 +77,10 @@ runs:
7377
PR_TITLE: ${{ github.event.pull_request.title }}
7478
HIDE_BANNER: ${{ inputs.hide-banner }}
7579
VARIANT: ${{ inputs.variant }}
80+
USE_UNCLONED_REPO: ${{ inputs.use-uncloned-repo }}
81+
GH_REPO_URL: ${{ github.pull_request.head.repo.html_url }}
82+
GH_REPO_HEAD_SHA: ${{ github.pull_request.head.sha }}
83+
GH_REPO_HEAD_BRANCH: ${{ github.pull_request.head.ref }}
84+
GH_REPO_HEAD_COMMIT_EPOCH: ${{ github.pull_request.updated_at }}
85+
GH_REPO_HEAD_AUTHOR_NAME: ${{ github.pull_request.head.user.name }}
86+
GH_REPO_HEAD_AUTHOR_EMAIL: ${{ github.pull_request.head.user.email }}

script.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ ALLOW_MISSING_JUNIT_FILES_ARG=$(parse_bool "${ALLOW_MISSING_JUNIT_FILES}" "--all
7575
HIDE_BANNER=$(parse_bool "${HIDE_BANNER}" "--hide-banner")
7676
QUARANTINE_ARG=$(parse_bool "${QUARANTINE}" "--use-quarantining")
7777
VARIANT="${VARIANT-}"
78+
USE_UNCLONED_REPO_FLAG=""
79+
REPO_URL=""
80+
REPO_HEAD_SHA=""
81+
REPO_HEAD_COMMIT_EPOCH=""
82+
REPO_HEAD_AUTHOR_NAME=""
83+
REPO_HEAD_AUTHOR_EMAIL=""
7884

7985
# CLI.
8086
set -x
@@ -88,6 +94,17 @@ fi
8894
chmod +x ./trunk-analytics-cli
8995
set +x
9096

97+
# Uncloned repo rules
98+
if [[ ${USE_UNCLONED_REPO} == "true" ]]; then
99+
USE_UNCLONED_REPO_FLAG="--use-uncloned-repo"
100+
REPO_URL="--repo-url ${GH_REPO_URL}"
101+
REPO_HEAD_SHA="--repo-head-sha ${GH_REPO_HEAD_BRANCH}"
102+
REPO_HEAD_BRANCH="${GH_REPO_HEAD_BRANCH}"
103+
REPO_HEAD_COMMIT_EPOCH="--repo-head-commit-epoch ${GH_REPO_HEAD_BRANCH}"
104+
REPO_HEAD_AUTHOR_NAME="--repo-head-author-name ${GH_REPO_HEAD_BRANCH}"
105+
REPO_HEAD_AUTHOR_EMAIL="--repo-head-author-email ${GH_REPO_HEAD_BRANCH}"
106+
fi
107+
91108
# trunk-ignore-begin(shellcheck/SC2086)
92109
if [[ $# -eq 0 ]]; then
93110
./trunk-analytics-cli upload \
@@ -102,7 +119,14 @@ if [[ $# -eq 0 ]]; then
102119
${ALLOW_MISSING_JUNIT_FILES_ARG} \
103120
${HIDE_BANNER} \
104121
${VARIANT:+--variant "${VARIANT}"} \
105-
${QUARANTINE_ARG}
122+
${QUARANTINE_ARG} \
123+
"${USE_UNCLONED_REPO_FLAG}" \
124+
${REPO_URL} \
125+
${REPO_HEAD_SHA} \
126+
${REPO_HEAD_COMMIT_EPOCH} \
127+
${REPO_HEAD_AUTHOR_NAME} \
128+
${REPO_HEAD_AUTHOR_EMAIL}
129+
106130
else
107131
./trunk-analytics-cli test \
108132
${JUNIT_PATHS:+--junit-paths "${JUNIT_PATHS}"} \
@@ -116,6 +140,12 @@ else
116140
${ALLOW_MISSING_JUNIT_FILES_ARG} \
117141
${HIDE_BANNER} \
118142
${VARIANT:+--variant "${VARIANT}"} \
119-
${QUARANTINE_ARG} "$@"
143+
${QUARANTINE_ARG} \
144+
"${USE_UNCLONED_REPO_FLAG}" \
145+
${REPO_URL} \
146+
${REPO_HEAD_SHA} \
147+
${REPO_HEAD_COMMIT_EPOCH} \
148+
${REPO_HEAD_AUTHOR_NAME} \
149+
${REPO_HEAD_AUTHOR_EMAIL} "$@"
120150
fi
121151
# trunk-ignore-end(shellcheck/SC2086)

tests/arguments.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test("Forwards inputs", async () => {
3838
ALLOW_MISSING_JUNIT_FILES: "",
3939
BAZEL_BEP_PATH: "",
4040
HIDE_BANNER: "",
41+
USE_UNCLONED_REPO: "false",
4142
};
4243

4344
const scriptPath = path.resolve(repoRoot, "script.sh");

0 commit comments

Comments
 (0)