Skip to content

[TRUNK-14636] Use gh context with use_uncloned_repo #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ inputs:
variant:
description: User specified variant of a set of tests being uploaded.
required: false
use-uncloned-repo:
description: Set to 'true' if your tests do not require cloning the repository under test,
required: false
default: false
previous-step-outcome:
description: The outcome of the previous step in the workflow. Set this equal to steps.[id].outcome where `[id]` is the id of the corresponding test run.
required: false
Expand All @@ -76,4 +80,10 @@ runs:
PR_TITLE: ${{ github.event.pull_request.title }}
HIDE_BANNER: ${{ inputs.hide-banner }}
VARIANT: ${{ inputs.variant }}
USE_UNCLONED_REPO: ${{ inputs.use-uncloned-repo }}
GH_REPO_URL: ${{ github.event.pull_request.head.repo.html_url }}
GH_REPO_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
GH_REPO_HEAD_BRANCH: ${{ github.event.pull_request.head.ref }}
GH_REPO_HEAD_COMMIT_EPOCH: ${{ github.event.pull_request.updated_at }}
GH_REPO_HEAD_AUTHOR_NAME: ${{ github.actor }}
PREVIOUS_STEP_OUTCOME: ${{ inputs.previous-step-outcome }}
43 changes: 38 additions & 5 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ if [[ (-z ${INPUT_TOKEN}) && (-z ${TRUNK_API_TOKEN-}) ]]; then
fi

REPO_HEAD_BRANCH="${REPO_HEAD_BRANCH-}"
REPO_ROOT="${REPO_ROOT-}"
REPO_ROOT_ARG="--repo-root ${REPO_ROOT-}"

if [[ -z ${REPO_ROOT-} ]]; then
REPO_ROOT_ARG=""
fi

TOKEN=${INPUT_TOKEN:-${TRUNK_API_TOKEN}} # Defaults to TRUNK_API_TOKEN env var.
TEAM="${TEAM-}"
JUNIT_PATHS="${JUNIT_PATHS-}"
Expand All @@ -82,6 +87,10 @@ if [[ -n ${PREVIOUS_STEP_OUTCOME} ]]; then
fi
fi
VARIANT="${VARIANT-}"
USE_UNCLONED_REPO="${USE_UNCLONED_REPO-}"
REPO_URL=""
REPO_HEAD_SHA=""
REPO_HEAD_AUTHOR_NAME=""

# CLI.
set -x
Expand All @@ -95,7 +104,21 @@ fi
chmod +x ./trunk-analytics-cli
set +x

# Uncloned repo rules
lower_use_uncloned_repo=$(echo "${USE_UNCLONED_REPO}" | tr '[:upper:]' '[:lower:]')
if [[ ${lower_use_uncloned_repo} == "true" ]]; then
USE_UNCLONED_REPO="--use-uncloned-repo"
REPO_URL="--repo-url ${GH_REPO_URL}"
REPO_HEAD_SHA="--repo-head-sha ${GH_REPO_HEAD_SHA}"
REPO_HEAD_BRANCH="${GH_REPO_HEAD_BRANCH}"
REPO_HEAD_AUTHOR_NAME="--repo-head-author-name ${GH_REPO_HEAD_AUTHOR_NAME}"
REPO_ROOT_ARG=""
else
USE_UNCLONED_REPO=""
fi

# trunk-ignore-begin(shellcheck/SC2086)
# trunk-ignore-begin(shellcheck/SC2248)
if [[ $# -eq 0 ]]; then
./trunk-analytics-cli upload \
${JUNIT_PATHS:+--junit-paths "${JUNIT_PATHS}"} \
Expand All @@ -104,13 +127,18 @@ if [[ $# -eq 0 ]]; then
--org-url-slug "${ORG_URL_SLUG}" \
--token "${TOKEN}" \
${REPO_HEAD_BRANCH:+--repo-head-branch "${REPO_HEAD_BRANCH}"} \
--repo-root "${REPO_ROOT}" \
${REPO_ROOT_ARG} \
--team "${TEAM}" \
${PREVIOUS_STEP_OUTCOME:+--test-process-exit-code="${PREVIOUS_STEP_OUTCOME}"} \
${ALLOW_MISSING_JUNIT_FILES_ARG} \
${HIDE_BANNER} \
${VARIANT:+--variant "${VARIANT}"} \
${QUARANTINE_ARG}
${QUARANTINE_ARG} \
${USE_UNCLONED_REPO} \
${REPO_URL} \
${REPO_HEAD_SHA} \
${REPO_HEAD_AUTHOR_NAME}

else
./trunk-analytics-cli test \
${JUNIT_PATHS:+--junit-paths "${JUNIT_PATHS}"} \
Expand All @@ -119,12 +147,17 @@ else
--org-url-slug "${ORG_URL_SLUG}" \
--token "${TOKEN}" \
${REPO_HEAD_BRANCH:+--repo-head-branch "${REPO_HEAD_BRANCH}"} \
--repo-root "${REPO_ROOT}" \
${REPO_ROOT_ARG} \
--team "${TEAM}" \
${PREVIOUS_STEP_OUTCOME:+--test-process-exit-code="${PREVIOUS_STEP_OUTCOME}"} \
${ALLOW_MISSING_JUNIT_FILES_ARG} \
${HIDE_BANNER} \
${VARIANT:+--variant "${VARIANT}"} \
${QUARANTINE_ARG} "$@"
${QUARANTINE_ARG} \
${USE_UNCLONED_REPO} \
${REPO_URL} \
${REPO_HEAD_SHA} \
${REPO_HEAD_AUTHOR_NAME} "$@"
fi
# trunk-ignore-end(shellcheck/SC2086)
# trunk-ignore-end(shellcheck/SC2248)
3 changes: 2 additions & 1 deletion tests/arguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ test("Forwards inputs", async () => {
ALLOW_MISSING_JUNIT_FILES: "",
BAZEL_BEP_PATH: "",
HIDE_BANNER: "",
USE_UNCLONED_REPO: "false",
PREVIOUS_STEP_OUTCOME: "success",
};

Expand All @@ -58,7 +59,7 @@ test("Forwards inputs", async () => {
}
expect({ stdout, stderr, exit_code }).toMatchObject({
stdout:
"upload --junit-paths junit.xml --org-url-slug org --token token --repo-root --team --test-process-exit-code=0",
"upload --junit-paths junit.xml --org-url-slug org --token token --team --test-process-exit-code=0",
stderr: `+ [[ 0.0.0 == \\l\\a\\t\\e\\s\\t ]]
+ [[ -f ./trunk-analytics-cli ]]
+ chmod +x ./trunk-analytics-cli
Expand Down