Skip to content

Copy over https://github.com/stackrox/stackrox/pull/3032 #931

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 1 commit into from
Sep 14, 2022
Merged
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
36 changes: 30 additions & 6 deletions scripts/ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,13 @@ gate_pr_job() {
if [[ -n "${run_with_changed_path}" || -n "${changed_path_to_ignore}" ]]; then
local diff_base
if is_OPENSHIFT_CI; then
diff_base="$(jq -r '.refs[0].base_sha' <<<"$CLONEREFS_OPTIONS")"
if [[ -n "${PULL_BASE_SHA:-}" ]]; then
diff_base="${PULL_BASE_SHA:-}"
else
diff_base="$(jq -r '.refs[0].base_sha' <<<"$CLONEREFS_OPTIONS")"
fi
echo "Determined diff-base as ${diff_base}"
[[ "${diff_base}" != "null" ]] || die "Could not find base_sha in CLONEREFS_OPTIONS: $CLONEREFS_OPTIONS"
[[ "${diff_base}" != "null" ]] || die "Could not find base_sha in PULL_BASE_SHA nor CLONEREFS_OPTIONS"
else
die "unsupported"
fi
Expand Down Expand Up @@ -489,9 +493,21 @@ openshift_ci_mods() {
export CI=true
export OPENSHIFT_CI=true

# Single step test jobs do not have HOME
if [[ -z "${HOME:-}" ]] || ! touch "${HOME}/openshift-ci-write-test"; then
info "HOME (${HOME:-unset}) is not set or not writeable, using mktemp dir"
HOME=$( mktemp -d )
export HOME
info "HOME is now $HOME"
fi

if is_in_PR_context && ! is_openshift_CI_rehearse_PR; then
local sha
sha=$(jq -r <<<"$CLONEREFS_OPTIONS" '.refs[0].pulls[0].sha') || echo "WARNING: Cannot find pull sha"
if [[ -n "${PULL_PULL_SHA:-}" ]]; then
sha="${PULL_PULL_SHA}"
else
sha=$(jq -r <<<"$CLONEREFS_OPTIONS" '.refs[0].pulls[0].sha') || echo "WARNING: Cannot find pull sha"
fi
if [[ -n "${sha:-}" ]] && [[ "$sha" != "null" ]]; then
info "Will checkout SHA to match PR: $sha"
git checkout "$sha"
Expand Down Expand Up @@ -613,11 +629,19 @@ send_slack_notice_for_failures_on_merge() {

local webhook_url="${TEST_FAILURES_NOTIFY_WEBHOOK}"

local commit_details
org=$(jq -r <<<"$CLONEREFS_OPTIONS" '.refs[0].org') || return 1
repo=$(jq -r <<<"$CLONEREFS_OPTIONS" '.refs[0].repo') || return 1
if [[ -n "${JOB_SPEC:-}" ]]; then
org=$(jq -r <<<"$JOB_SPEC" '.refs.org')
repo=$(jq -r <<<"$JOB_SPEC" '.refs.repo')
elif [[ -n "${CLONEREFS_OPTIONS:-}" ]]; then
org=$(jq -r <<<"$CLONEREFS_OPTIONS" '.refs[0].org')
repo=$(jq -r <<<"$CLONEREFS_OPTIONS" '.refs[0].repo')
else
echo "Expect a JOB_SPEC or CLONEREFS_OPTIONS"
return 1
fi
[[ "$org" != "null" ]] && [[ "$repo" != "null" ]] || return 1
local commit_details_url="https://api.github.com/repos/${org}/${repo}/commits/${OPENSHIFT_BUILD_COMMIT}"
local commit_details
commit_details=$(curl --retry 5 -sS "${commit_details_url}") || return 1

local job_name="${JOB_NAME_SAFE#merge-}"
Expand Down