@@ -2,14 +2,36 @@ SANDBOX_UI_NS := sandbox-ui
22SANDBOX_PLUGIN_IMAGE_NAME := sandbox-rhdh-plugin
33TAG := latest
44PLATFORM ?= linux/amd64
5- RHDH_PLUGINS_DIR ?= $(TMPDIR ) rhdh-plugins
5+ RHDH_PLUGINS_TMP ?= $(TMPDIR ) rhdh-plugins
66AUTH_FILE := /tmp/auth.json
7- IMAGE_TO_PUSH_IN_QUAY ?= quay.io/$(QUAY_NAMESPACE ) /sandbox-rhdh-plugin:$(TAG )
87OPENID_SECRET_NAME =openid-sandbox-public-client-secret
9- PUSH_SANDBOX_IMAGE ?= true
8+ PUSH_SANDBOX_IMAGE ?= false
109UI_ENVIRONMENT := ui-e2e-tests
10+ SSO_USERNAME_READ := $(shell if [ -n "$(CI ) " ]; then cat /usr/local/sandbox-secrets/SSO_USERNAME 2>/dev/null || echo ""; else echo "${SSO_USERNAME}"; fi)
11+ SSO_PASSWORD_READ := $(shell if [ -n "$(CI ) " ]; then cat /usr/local/sandbox-secrets/SSO_PASSWORD 2>/dev/null || echo ""; else echo "${SSO_PASSWORD}"; fi)
12+
13+ TAG := $(shell \
14+ if [ -n "$(CI )$(CLONEREFS_OPTIONS ) " ]; then \
15+ if [ -n "$(GITHUB_ACTIONS ) " ]; then \
16+ REPOSITORY_NAME=$$(basename "$(GITHUB_REPOSITORY ) ") ; \
17+ COMMIT_ID_SUFFIX=$$(echo "$(PULL_PULL_SHA ) " | cut -c1-7 ) ; \
18+ echo "from.$${REPOSITORY_NAME}.PR$(PULL_NUMBER ) .$${COMMIT_ID_SUFFIX}"; \
19+ else \
20+ AUTHOR=$$(jq -r '.refs[0].pulls[0].author' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]' ) ; \
21+ PULL_PULL_SHA=$${PULL_PULL_SHA:-$$(jq -r '.refs[0].pulls[0].sha' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]' ) }; \
22+ COMMIT_ID_SUFFIX=$$(echo "$${PULL_PULL_SHA}" | cut -c1-7 ) ; \
23+ echo "from.$(REPO_NAME ) .PR$(PULL_NUMBER ) .$${COMMIT_ID_SUFFIX}"; \
24+ fi; \
25+ else \
26+ echo "latest"; \
27+ fi)
28+
29+
30+ IMAGE_TO_PUSH_IN_QUAY ?= quay.io/$(QUAY_NAMESPACE ) /sandbox-rhdh-plugin:$(TAG )
31+
1132
1233.PHONY : deploy-sandbox-ui
34+ deploy-sandbox-ui : HOST_NS=$(shell oc get projects -l app=host-operator --output=name -o jsonpath='{range .items[* ]}{.metadata.name}{"\n"}{end}' | sort | tail -n 1)
1335deploy-sandbox-ui : REGISTRATION_SERVICE_API=https://$(shell oc get route registration-service -n ${HOST_NS} -o custom-columns=":spec.host" | tr -d '\n') /api/v1
1436deploy-sandbox-ui : HOST_OPERATOR_API=https://$(shell oc get route api -n ${HOST_NS} -o custom-columns=":spec.host" | tr -d '\n')
1537deploy-sandbox-ui : RHDH=https://rhdh-${SANDBOX_UI_NS}.$(shell oc get ingress.config.openshift.io/cluster -o jsonpath='{.spec.domain}')
@@ -21,34 +43,46 @@ ifeq ($(PUSH_SANDBOX_IMAGE),true)
2143 $(MAKE) push-sandbox-plugin
2244endif
2345 kustomize build deploy/sandbox-ui/ui-e2e-tests | REGISTRATION_SERVICE_API=${REGISTRATION_SERVICE_API} \
24- HOST_NS=${HOST_NS} \
25- HOST_OPERATOR_API=${HOST_OPERATOR_API} \
26- SANDBOX_UI_NS=${SANDBOX_UI_NS} \
27- SANDBOX_PLUGIN_IMAGE=${IMAGE_TO_PUSH_IN_QUAY} \
28- RHDH=${RHDH} envsubst | oc apply -f -
46+ HOST_OPERATOR_API=${HOST_OPERATOR_API} \
47+ SANDBOX_UI_NS=${SANDBOX_UI_NS} \
48+ SANDBOX_PLUGIN_IMAGE=${IMAGE_TO_PUSH_IN_QUAY} \
49+ RHDH=${RHDH} envsubst | oc apply -f -
2950 $(MAKE) configure-oauth-idp
51+ ifeq ($(ENVIRONMENT ) ,ui-e2e-tests)
52+ @echo "applying toolchainconfig changes"
53+ @echo "HOST_NS: ${HOST_NS}"
54+ @oc apply -f deploy/host-operator/ui-e2e-tests/toolchainconfig.yaml -n ${HOST_NS}
3055 @echo "restarting registration-service to apply toolchainconfig changes"
3156 @oc -n ${HOST_NS} rollout restart deploy/registration-service
57+ else
58+ @echo "skipping toolchainconfig changes - environment is not ui-e2e-tests"
59+ endif
3260 @oc -n ${SANDBOX_UI_NS} rollout status deploy/rhdh
3361 @echo "Developer Sandbox UI running at ${RHDH}"
3462
3563
3664check-sso-credentials :
3765 @echo " checking SSO credentials..."
38- @if [ -z " $$ SSO_USERNAME" ] || [ -z " $$ SSO_PASSWORD" ]; then \
39- echo " SSO_USERNAME or SSO_PASSWORD not set" ; \
66+ @if [ -z " $( SSO_USERNAME_READ) " ] || [ -z " $( SSO_PASSWORD_READ) " ]; then \
67+ if [ -n " $( CI) " ]; then \
68+ echo " SSO credential files not found or empty in CI environment" ; \
69+ else \
70+ echo " SSO_USERNAME or SSO_PASSWORD environment variables not set" ; \
71+ fi ; \
4072 exit 1; \
4173 fi
74+ @echo " Validating SSO credentials..."
4275 @status=$$(curl -s -o /dev/null -w "%{http_code}" \
4376 -X POST " https://sso.devsandbox.dev/auth/realms/sandbox-dev/protocol/openid-connect/token" \
4477 -d " grant_type=password" \
4578 -d " client_id=sandbox-public" \
46- -d " username=$$ SSO_USERNAME " \
47- -d " password=$$ SSO_PASSWORD " ); \
79+ -d " username=$( SSO_USERNAME_READ ) " \
80+ -d " password=$( SSO_PASSWORD_READ ) " ); \
4881 if [ " $$ status" != " 200" ]; then \
4982 echo " failed trying to login to 'https://sso.devsandbox.dev/auth/realms/sandbox-dev' ($$ status) — check your SSO credentials." ; \
5083 exit 1; \
5184 fi
85+ @echo " SSO credentials validated successfully"
5286
5387configure-oauth-idp :
5488 @echo " configuring DevSandbox identity provider"
@@ -70,38 +104,73 @@ create-namespace:
70104
71105.PHONY : get-rhdh-plugins
72106get-rhdh-plugins :
73- ifeq ($(strip $(RHDH_PLUGINS_DIR ) ) , $(TMPDIR ) rhdh-plugins)
74- echo "using rhdh-plugins repo from master"
107+ ifeq ($(strip $(RHDH_PLUGINS_TMP ) ) , $(TMPDIR ) rhdh-plugins)
108+ ifeq ($(GITHUB_ACTIONS ) ,true)
109+ @echo "using author ${AUTHOR}"
110+ $(eval AUTHOR_LINK = https://github.com/${AUTHOR})
111+ @echo "detected branch ${BRANCH_NAME}"
112+ # check if a branch with the same ref exists in the user's fork of rhdh-plugins repo
113+ @echo "branches of ${AUTHOR_LINK}/rhdh-plugins - checking if there is a branch ${BRANCH_NAME} we could pair with."
114+ curl ${AUTHOR_LINK}/rhdh-plugins.git/info/refs?service=git-upload-pack --output -
115+ $(eval REMOTE_RHDH_PLUGINS_BRANCH := $(shell curl ${AUTHOR_LINK}/rhdh-plugins.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a "refs/heads/${BRANCH_NAME}$$" | awk '{print $$2}'))
116+
117+ # check if the branch with the same name exists, if so then merge it with master and use the merge branch, if not then use master
118+ @echo "REMOTE_RHDH_PLUGINS_BRANCH: ${REMOTE_RHDH_PLUGINS_BRANCH}"
119+ @$(MAKE) pair-if-needed REMOTE_RHDH_PLUGINS_BRANCH=${REMOTE_RHDH_PLUGINS_BRANCH} AUTHOR_LINK=${AUTHOR_LINK}
120+ else
121+ @echo "using rhdh-plugins repo from master"
75122 @$(MAKE) clone-rhdh-plugins
123+ endif
76124else
77- echo "using local rhdh-plugins repo: ${RHDH_PLUGINS_DIR}"
125+ @echo "using local rhdh-plugins repo, no pairing needed: ${RHDH_PLUGINS_TMP}"
126+ endif
127+
128+ pair-if-needed :
129+ ifneq ($(strip $(REMOTE_RHDH_PLUGINS_BRANCH ) ) ,)
130+ @echo "Branch ref of the user's fork to be used for pairing: \"${REMOTE_RHDH_PLUGINS_BRANCH}\""
131+ git config --global user.email "devsandbox@redhat.com"
132+ git config --global user.name "KubeSaw"
133+ # clone
134+ rm -rf ${RHDH_PLUGINS_TMP}
135+ git clone --depth=1 https://github.com/redhat-developer/rhdh-plugins.git ${RHDH_PLUGINS_TMP}
136+ # add the user's fork as remote repo
137+ git --git-dir=${RHDH_PLUGINS_TMP}/.git --work-tree=${RHDH_PLUGINS_TMP} remote add external ${AUTHOR_LINK}/rhdh-plugins.git
138+ # fetch the branch
139+ git --git-dir=${RHDH_PLUGINS_TMP}/.git --work-tree=${RHDH_PLUGINS_TMP} fetch external ${REMOTE_RHDH_PLUGINS_BRANCH}
140+ # merge the branch with master
141+ git --git-dir=${RHDH_PLUGINS_TMP}/.git --work-tree=${RHDH_PLUGINS_TMP} merge --ff-only FETCH_HEAD
142+ else
143+ @echo "no pairing needed, using rhdh-plugins repo from master"
144+ @$(MAKE) clone-rhdh-plugins
78145endif
79146
80147.PHONY : clone-rhdh-plugins
81148clone-rhdh-plugins :
82- rm -rf ${RHDH_PLUGINS_DIR } ; \
83- git clone https://github.com/redhat-developer/rhdh-plugins $(RHDH_PLUGINS_DIR ) && \
84- echo " cloned to $( RHDH_PLUGINS_DIR ) "
149+ rm -rf ${RHDH_PLUGINS_TMP } ; \
150+ git clone --depth=1 https://github.com/redhat-developer/rhdh-plugins $(RHDH_PLUGINS_TMP ) && \
151+ echo " cloned to $( RHDH_PLUGINS_TMP ) "
85152
86153.PHONY : push-sandbox-plugin
87154push-sandbox-plugin :
88155 $(MAKE ) get-rhdh-plugins
89- cd $(RHDH_PLUGINS_DIR ) /workspaces/sandbox && \
156+ cd $(RHDH_PLUGINS_TMP ) /workspaces/sandbox && \
90157 rm -rf plugins/sandbox/dist-dynamic && \
91158 rm -rf red-hat-developer-hub-backstage-plugin-sandbox && \
92159 yarn install && \
93160 npx @janus-idp/cli@3.3.1 package package-dynamic-plugins \
94- --tag $(IMAGE_TO_PUSH_IN_QUAY) \
95- --platform $(PLATFORM) && \
96- podman push $(IMAGE_TO_PUSH_IN_QUAY)
161+ --tag $(IMAGE_TO_PUSH_IN_QUAY ) \
162+ --platform $(PLATFORM ) && \
163+ podman push $(IMAGE_TO_PUSH_IN_QUAY )
97164
98165.PHONY : clean-sandbox-ui
166+ clean-sandbox-ui : HOST_NS=$(shell oc get projects -l app=host-operator --output=name -o jsonpath='{range .items[* ]}{.metadata.name}{"\n"}{end}' | sort | tail -n 1)
99167clean-sandbox-ui :
100168 @oc delete ns ${SANDBOX_UI_NS}
101169 @oc delete secret ${OPENID_SECRET_NAME} -n openshift-config
102170 @oc delete usersignup ${SSO_USERNAME} -n ${HOST_NS}
103171
104172.PHONY : e2e-run-sandbox-ui
173+ e2e-run-sandbox-ui : HOST_NS=$(shell oc get projects -l app=host-operator --output=name -o jsonpath='{range .items[* ]}{.metadata.name}{"\n"}{end}' | sort | tail -n 1)
105174e2e-run-sandbox-ui : RHDH=https://rhdh-${SANDBOX_UI_NS}.$(shell oc get ingress.config.openshift.io/cluster -o jsonpath='{.spec.domain}')
106175e2e-run-sandbox-ui :
107176 @echo " Installing Playwright..."
@@ -112,24 +181,23 @@ e2e-run-sandbox-ui:
112181 $(GOPATH ) /bin/playwright install firefox
113182
114183 @echo "Running Developer Sandbox UI setup e2e tests..."
115- SANDBOX_UI_NS=${SANDBOX_UI_NS} go test "./test/e2e/sandbox-ui/setup" -v -timeout=10m -failfast -count=1
184+ SANDBOX_UI_NS=${SANDBOX_UI_NS} go test "./test/e2e/sandbox-ui/setup" -v -timeout=10m -failfast
116185
117186 @echo "Running Developer Sandbox UI e2e tests in firefox..."
118- SSO_USERNAME=${SSO_USERNAME} SSO_PASSWORD=${SSO_PASSWORD} BASE_URL=${RHDH} BROWSER=firefox envsubst < deploy/sandbox-ui/ui-e2e-tests/.env > testsupport/sandbox-ui/.env
119- # NOTE: The "-count=1" is the idiomatic way of turning off the test result cache according to https://pkg.go.dev/cmd/go#hdr-Testing_flags.
120- go test "./test/e2e/sandbox-ui" -v -timeout=10m -failfast -count=1
121- @oc delete usersignup ${SSO_USERNAME} -n ${HOST_NS}
187+ @SSO_USERNAME=$(SSO_USERNAME_READ) SSO_PASSWORD=$(SSO_PASSWORD_READ) BASE_URL=${RHDH} BROWSER=firefox envsubst < deploy/sandbox-ui/ui-e2e-tests/.env > testsupport/sandbox-ui/.env
188+ go test "./test/e2e/sandbox-ui" -v -timeout=10m -failfast
189+ @oc delete usersignup $(SSO_USERNAME_READ) -n $(HOST_NS)
122190
123191 @echo "The Developer Sandbox UI e2e tests successfully finished"
124192
125193
126194.PHONY : test-ui-e2e
127195test-ui-e2e :
128- $(MAKE ) prepare-and-deploy-e2e deploy-sandbox-ui e2e-run-sandbox-ui ENVIRONMENT=${UI_ENVIRONMENT}
196+ $(MAKE ) deploy-sandbox-ui e2e-run-sandbox-ui ENVIRONMENT=${UI_ENVIRONMENT}
129197
130198.PHONY : test-ui-e2e-local
131199test-ui-e2e-local :
132- $(MAKE ) prepare-and- deploy-e2e deploy- sandbox-ui e2e-run-sandbox-ui RHDH_PLUGINS_DIR =${PWD} /../rhdh-plugins ENVIRONMENT=${UI_ENVIRONMENT}
200+ $(MAKE ) deploy-sandbox-ui e2e-run-sandbox-ui RHDH_PLUGINS_TMP =${PWD} /../rhdh-plugins ENVIRONMENT=${UI_ENVIRONMENT}
133201
134202
135203UNIT_TEST_IMAGE_NAME =sandbox-ui-e2e-tests
@@ -142,7 +210,7 @@ build-sandbox-ui-e2e-tests:
142210 podman build --platform $(PLATFORM ) -t $(UNIT_TEST_IMAGE_NAME ) -f $(UNIT_TEST_DOCKERFILE ) .
143211
144212# Run Developer Sandbox UI e2e tests image using podman
145- PHONY : test-sandbox-ui-in-container
213+ . PHONY : test-sandbox-ui-in-container
146214test-sandbox-ui-in-container : build-sandbox-ui-e2e-tests
147215 @echo " pushing Developer Sandbox UI image..."
148216 $(MAKE ) push-sandbox-plugin
@@ -152,12 +220,11 @@ test-sandbox-ui-in-container: build-sandbox-ui-e2e-tests
152220 -e KUBECONFIG=/root/.kube/config \
153221 -v ${PWD} :/root/toolchain-e2e \
154222 -e E2E_REPO_PATH=/root/toolchain-e2e \
155- -v $(RHDH_PLUGINS_DIR ) :/root/rhdh-plugins \
156- -e RHDH_PLUGINS_DIR =/root/rhdh-plugins \
223+ -v $(RHDH_PLUGINS_TMP ) :/root/rhdh-plugins \
224+ -e RHDH_PLUGINS_TMP =/root/rhdh-plugins \
157225 -e SSO_USERNAME=$(SSO_USERNAME ) \
158226 -e SSO_PASSWORD=$(SSO_PASSWORD ) \
159227 -e QUAY_NAMESPACE=$(QUAY_NAMESPACE ) \
160228 -e TMP=/tmp/ \
161- -e PUSH_SANDBOX_IMAGE=false \
162229 -e RUNNING_IN_CONTAINER=true \
163230 $(UNIT_TEST_IMAGE_NAME )
0 commit comments