Skip to content

fix tag used for hourly CI runs #954

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 4 commits into from
Oct 3, 2022
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ BASE_DIR=$(CURDIR)
TAG := # make sure tag is never injectable as an env var

ifdef CI
ifneq ($(CIRCLE_TAG),)
TAG := $(CIRCLE_TAG)
ifneq ($(NIGHTLY_TAG),)
TAG := $(NIGHTLY_TAG)
endif
endif

Expand Down
50 changes: 16 additions & 34 deletions scripts/ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ensure_CI() {
fi
}

# ci_export is a wrapper around export. This is here for legacy purposes.
ci_export() {
if [[ "$#" -ne 2 ]]; then
die "missing args. usage: ci_export <env-name> <env-value>"
Expand All @@ -22,11 +23,7 @@ ci_export() {
local env_name="$1"
local env_value="$2"

if command -v cci-export >/dev/null; then
cci-export "$env_name" "$env_value"
else
export "$env_name"="$env_value"
fi
export "$env_name"="$env_value"
}

ci_exit_trap() {
Expand Down Expand Up @@ -173,7 +170,7 @@ is_tagged() {
}

is_nightly_run() {
[[ "${CIRCLE_TAG:-}" =~ -nightly- ]]
[[ "${NIGHTLY_TAG:-}" =~ -nightly- ]]
}

is_in_PR_context() {
Expand All @@ -186,9 +183,9 @@ is_in_PR_context() {
local pull_request
pull_request=$(jq -r <<<"$CLONEREFS_OPTIONS" '.refs[0].pulls[0].number' 2>&1) || return 1
[[ "$pull_request" =~ ^[0-9]+$ ]] && return 0
else
return 1
fi

return 1
}

is_openshift_CI_rehearse_PR() {
Expand Down Expand Up @@ -506,21 +503,16 @@ openshift_ci_mods() {
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"
sha=$(jq -r <<<"$CLONEREFS_OPTIONS" '.refs[0].pulls[0].sha') || warn "Cannot find pull sha"
fi
if [[ -n "${sha:-}" ]] && [[ "$sha" != "null" ]]; then
info "Will checkout SHA to match PR: $sha"
git checkout "$sha"
else
echo "WARNING: Could not determine a SHA for this PR, ${sha:-}"
warn "Could not determine a SHA for this PR, ${sha:-}"
fi
fi

# Provide Circle CI vars that are commonly used
export CIRCLE_JOB="${JOB_NAME:-${OPENSHIFT_BUILD_NAME}}"
CIRCLE_TAG="$(git tag --sort=creatordate --contains | tail -1)" || echo "Warning: Cannot get tag"
export CIRCLE_TAG

handle_nightly_runs

info "Status after mods:"
Expand All @@ -539,16 +531,21 @@ openshift_ci_import_creds() {
done
}

openshift_ci_e2e_mods() {
unset_namespace_env_var() {
# NAMESPACE is injected by OpenShift CI for the cluster that is running the
# tests but this can have side effects for scanner tests due to its use as
# the default namespace e.g. with helm.
if [[ -n "${NAMESPACE:-}" ]]; then
export OPENSHIFT_CI_NAMESPACE="$NAMESPACE"
unset NAMESPACE
fi
}

# Similarly the incoming KUBECONFIG is best avoided.
openshift_ci_e2e_mods() {
unset_namespace_env_var

# The incoming KUBECONFIG is for the openshift/release cluster and not the
# e2e test cluster.
if [[ -n "${KUBECONFIG:-}" ]]; then
info "There is an incoming KUBECONFIG in ${KUBECONFIG}"
export OPENSHIFT_CI_KUBECONFIG="$KUBECONFIG"
Expand All @@ -557,7 +554,7 @@ openshift_ci_e2e_mods() {
info "KUBECONFIG set: ${KUBECONFIG}"
export KUBECONFIG

# KUBERNETES_{PORT,SERVICE} env values also interact with commandline kubectl tests
# KUBERNETES_{PORT,SERVICE} env values interact with commandline kubectl tests
if env | grep -e ^KUBERNETES_; then
local envfile
envfile="$(mktemp)"
Expand All @@ -573,25 +570,10 @@ handle_nightly_runs() {
die "Only for OpenShift CI"
fi

if ! is_in_PR_context; then
info "Debug:"
echo "JOB_NAME: ${JOB_NAME:-}"
echo "JOB_NAME_SAFE: ${JOB_NAME_SAFE:-}"
fi

local nightly_tag_prefix
nightly_tag_prefix="$(git describe --tags --abbrev=0 --exclude '*-nightly-*')-nightly-"
if ! is_in_PR_context && [[ "${JOB_NAME_SAFE:-}" =~ ^nightly- ]]; then
ci_export CIRCLE_TAG "${nightly_tag_prefix}$(date '+%Y%m%d')"
elif is_in_PR_context && pr_has_label "simulate-nightly-run"; then
local sha
if [[ -n "${PULL_PULL_SHA:-}" ]]; then
sha="${PULL_PULL_SHA}"
else
sha=$(jq -r <<<"$CLONEREFS_OPTIONS" '.refs[0].pulls[0].sha') || die "Cannot find pull sha"
[[ "$sha" != "null" ]] || die "Cannot find pull sha"
fi
ci_export CIRCLE_TAG "${nightly_tag_prefix}${sha:0:8}"
ci_export NIGHTLY_TAG "${nightly_tag_prefix}$(date '+%Y%m%d')"
fi
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/logcheck/check-logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ check_for_stackrox_restarts() {
if [[ -n "$previous_logs" ]]; then
echo >&2 "Previous logs found"
# shellcheck disable=SC2086
if ! "$SCRIPTS_ROOT/ci/logcheck/check-restart-logs.sh" "${CI_JOB_NAME:-${CIRCLE_JOB}}" $previous_logs; then
if ! "$SCRIPTS_ROOT/ci/logcheck/check-restart-logs.sh" "${CI_JOB_NAME}" $previous_logs; then
exit 1
fi
fi
Expand Down