Skip to content
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

test: adding PR check scripts, github action and login code, updating… #88

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 21 additions & 0 deletions .github/workflows/base-test-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build and Push Base Test Image

# trigger manually
on: workflow_dispatch

jobs:
base-image:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Build and Push Base Image
env:
USERNAME=${{ secrets.QUAY_BOT_USERNAME }}
TOKEN=${{ secrets.QUAY_BOT_TOKEN }}
run: |
cd e2e-tests
podman login -u="$USERNAME" -p="$TOKEN" quay.io
podman build -t quay.io/konflux_ui_qe/konflux-ui-tests-base:latest -f BaseDockerfile
podman push quay.io/konflux_ui_qe/konflux-ui-tests-base:latest
2 changes: 2 additions & 0 deletions .github/workflows/post-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
fail_ci_if_error: true

# - name: Build E2E Test Image (if tests changed)
141 changes: 141 additions & 0 deletions .github/workflows/pr-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: PR Check Test

on:
pull_request_target:
types: [opened, synchronize, reopened, labeled]

jobs:
# check-org-membership:
# runs-on: ubuntu-latest
# outputs:
# org-member: ${{ steps.org-check.outputs.org-member }}
# steps:
# - name: Check if PR author is a member of the organization
# continue-on-error: true
# id: org-check
# run: |
# ORG="${{ github.repository_owner }}"
# AUTHOR="${{ github.event.pull_request.user.login }}"
# if ! gh api /orgs/$ORG/members/$AUTHOR; then
# echo '### ❌ PR author is not a member of GitHub organization' >> $GITHUB_STEP_SUMMARY
# exit 1
# fi
# echo "org-member=true" >> $GITHUB_OUTPUT
# env:
# GITHUB_TOKEN: ${{ secrets.HAC_TEST_GH_TOKEN }}

e2e-test:
# if: ${{ (needs.check-org-membership.outputs.org-member == 'true') || (github.event.pull_request.user.login == 'renovate[bot]') || contains(github.event.pull_request.labels.*.name, 'ok-to-test') }}
# needs: check-org-membership
runs-on: ubuntu-latest
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false
docker-images: false

# konflux-ci is cloned to /home/runner/work/konflux-ui/konflux-ui
# as it have to be at home folder to use helm/kind-action@v1 action
- name: Checkout Repository
uses: actions/checkout@v4
with:
repository: 'konflux-ci/konflux-ci'
ref: 'main'

- name: Disable AppArmor
# works around a change in ubuntu 24.04 that restricts Linux namespace access
# for unprivileged users
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
with:
config: kind-config.yaml

- name: Show version information
run: |
kubectl version
kind version

- name: List namespaces
run: |
kubectl get namespace

- name: Deploying Dependencies
run: |
./deploy-deps.sh

- name: List namespaces
run: |
kubectl get namespace

- name: Wait for the dependencies to be ready
run: |
./wait-for-all.sh

- name: WORKAROUND - Set up tkn cli for the following task
uses: tektoncd/actions/setup-tektoncd-cli@main
with:
version: latest

- name: WORKAROUND - Remove clair-scan task from docker-pipeline
run: |
./test/e2e/customize-docker-pipeline.sh

- name: Deploying Konflux
run: |
./deploy-konflux.sh

- name: List namespaces
run: |
kubectl get namespace

- name: Deploy test resources
run: |
./deploy-test-resources.sh

- name: Prepare resources for E2E tests
# Sets secrets, deploys image controller and setup smee.
env:
APP_ID: ${{ secrets.GH_APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
APP_WEBHOOK_SECRET: ${{ secrets.GH_APP_WEBHOOK_SECRET }}
QUAY_ORG: ${{ secrets.QUAY_TEST_ORG }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN_TEST }}
SMEE_CHANNEL: ${{ secrets.SMEE_URL }}
run: |
./test/e2e/prepare-e2e.sh

# konflux-ui repo is cloned to /home/runner/work/konflux-ui/konflux-ui/konflux-ui
- name: Checkout Konflux-UI Repository
uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.sha }}"
path: 'konflux-ui'

- name: Install Konflux-UI and run tests
env:
CYPRESS_GH_TOKEN: ${{ secrets.GH_TOKEN }}
TARGET_BRANCH: ${{ github.base_ref }}
PR_NUMBER: ${{ github.event.number }}
HEAD_SHA: "${{ github.event.pull_request.head.sha }}"
CYPRESS_USERNAME: "${{ secrets.CYPRESS_USERNAME }}"
CYPRESS_PASSWORD: "${{ secrets.CYPRESS_PASSWORD }}"
run: |
./konflux-ui/pr_check.sh

- name: Generate error logs
if: ${{ !cancelled() }}
run: |
.generate-err-logs.sh
cp -r konflux-ui/artifacts logs

- name: Archive logs
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: logs
path: logs
21 changes: 21 additions & 0 deletions connect_to_local_konflux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Change configs to connect the UI with locally running Konflux
# Mainly for the PR check but can be used locally too
echo "Patching .env and webpack.dev.config.js"
cat > .env << EOL
AUTH_URL=https://127.0.0.1:9443/
REGISTRATION_URL=https://127.0.0.1:9443/
PROXY_URL=https://127.0.0.1:9443/
PROXY_WEBSOCKET_URL=wss://127.0.0.1:9443
EOL

# regex cheatsheet
# [^ ].* - take everything before the text but leave spaces
# 0, - replace just the first occurence
#
sed -i "s%[^ ].*\/oauth2\/.*%context: (path) => path.includes('/oauth2/') || path.includes('/idp/'),%g" webpack.dev.config.js
sed -i '0,/autoRewrite: false,/s//autoRewrite: true,/' webpack.dev.config.js
sed -i "s/[^ ].*stone-stg-rh01.*/'localhost:9443',/" webpack.dev.config.js
sed -i "s/[^ ].*stone-stg-rh01.*/'localhost:9443',/" webpack.dev.config.js
sed -i "s/[^ ].*DEV_SERVER_PORT}\/oauth2\`,/\`localhost:\${DEV_SERVER_PORT}\`,/" webpack.dev.config.js

echo "Patching done, UI is connected to locally running Konflux."
8 changes: 8 additions & 0 deletions e2e-tests/BaseContainerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ARG DEFAULT_CHROME_VERSION='131.0.6778.139-1'

FROM cypress/factory:5.1.1

RUN apt update && \
apt install curl jq python3 python3-venv python3-pip xauth skopeo -y

RUN apt install python3-requests python3-click -y
6 changes: 3 additions & 3 deletions e2e-tests/Dockerfile → e2e-tests/Containerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM quay.io/hacdev/hac-tests:base
FROM quay.io/konflux_ui_qe/konflux-ui-tests-base:latest

RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

RUN wget "https://github.com/sigstore/cosign/releases/download/v2.0.0/cosign-linux-amd64" && \
RUN wget "https://github.com/sigstore/cosign/releases/download/v2.4.0/cosign-linux-amd64" && \
mv cosign-linux-amd64 /usr/local/bin/cosign && \
chmod +x /usr/local/bin/cosign

Expand All @@ -23,4 +23,4 @@ WORKDIR /tmp/
COPY --chown=node:root --chmod=775 entrypoint.sh /tmp/

ENTRYPOINT ["/tmp/entrypoint.sh"]
CMD [""]
CMD [""]
2 changes: 1 addition & 1 deletion e2e-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ Job history is available [here](https://prow.ci.openshift.org/job-history/gs/ori
## Reporting issues
If you find a problem with the tests, feel free to open an issue at the [Konflux-UI Jira project](https://issues.redhat.com/projects/KFLUXUI). You can set the label as `qe` to indicate it is a quality problem.

<!-- If you discover a production bug thanks to a test failure, please label any issue created for that bug as `ci-fail`. That way we can see all this automation has actually generated some value. -->
<!-- If you discover a production bug thanks to a test failure, please label any issue created for that bug as `ci-fail`. That way we can see all this automation has actually generated some value. -->
15 changes: 9 additions & 6 deletions e2e-tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ export default defineConfig({
});

const defaultValues: { [key: string]: string | boolean } = {
KONFLUX_BASE_URL: 'https://prod.foo.redhat.com:1337/preview/application-pipeline',
USERNAME: '',
PASSWORD: '',
KONFLUX_BASE_URL: 'https://localhost:9443',
USERNAME: '[email protected]',
PASSWORD: 'password',
GH_USERNAME: 'hac-test',
GH_PASSWORD: '',
GH_TOKEN: '',
GH_SETUP_KEY: '',
KUBECONFIG: '~/.kube/appstudio-config',
CLEAN_NAMESPACE: 'false',
PR_CHECK: false,
PR_CHECK: '',
PERIODIC_RUN: false,
resolution: 'high',
REMOVE_APP_ON_FAIL: false,
Expand All @@ -161,8 +161,11 @@ export default defineConfig({
}

config.env.HAC_WORKSPACE = config.env.USERNAME.toLowerCase();
config.env.HAC_NAMESPACE = `${config.env.HAC_WORKSPACE}-tenant`;

if (config.env.PR_CHECK === true) {
config.env.HAC_NAMESPACE = `user-ns1`;
} else {
config.env.HAC_NAMESPACE = `${config.env.HAC_WORKSPACE}-tenant`;
}
if (
config.env.PR_CHECK === true &&
config.reporterOptions.reportportalAgentJsCypressReporterOptions
Expand Down
5 changes: 4 additions & 1 deletion e2e-tests/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ else
fi

npx cypress run $args
echo "Test run finished, dealing with artifacts..."

if [ -d "/e2e/cypress" ]; then
echo "Cypress folder found, copying artifacts"
cp -a /e2e/cypress/* /tmp/artifacts
chmod -R a+rwx /tmp/artifacts
chmod -R a+rwx /e2e/cypress
else
echo "Copying artifacts"
cp -a /tmp/e2e/cypress/* /tmp/artifacts
fi
fi
44 changes: 22 additions & 22 deletions e2e-tests/support/commands/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { Common } from '../../utils/Common';
import { Login } from '../../utils/Login';

before(() => {
//Clear namespace before running the tests
Common.cleanNamespace();
// before(() => {
// //Clear namespace before running the tests
// Common.cleanNamespace();

const url = new URL(Cypress.env('KONFLUX_BASE_URL'));
cy.setCookie('notice_gdpr_prefs', '0,1,2:', { domain: url.hostname });
cy.setCookie('cmapi_cookie_privacy', 'permit 1,2,3', { domain: url.hostname });
cy.setCookie('notice_preferences', '2:', { domain: url.hostname });
// const url = new URL(Cypress.env('KONFLUX_BASE_URL'));
// cy.setCookie('notice_gdpr_prefs', '0,1,2:', { domain: url.hostname });
// cy.setCookie('cmapi_cookie_privacy', 'permit 1,2,3', { domain: url.hostname });
// cy.setCookie('notice_preferences', '2:', { domain: url.hostname });

// set local storage to avoid getting started modal
localStorage.setItem(
'getting-started-modal',
JSON.stringify({ 'application-list-getting-started-modal': true }),
);
// // set local storage to avoid getting started modal
// localStorage.setItem(
// 'getting-started-modal',
// JSON.stringify({ 'application-list-getting-started-modal': true }),
// );

if (Cypress.env('PR_CHECK') || Cypress.env('PERIODIC_RUN')) {
Login.prCheckLogin();
} else {
Login.login();
}
});
// if (Cypress.env('PR_CHECK') || Cypress.env('PERIODIC_RUN')) {
// Login.localKonfluxLogin();
// } else {
// Login.login();
// }
// });

after(() => {
//Clear namespace after running the tests
Common.cleanNamespace();
});
// after(() => {
// //Clear namespace after running the tests
// Common.cleanNamespace();
// });
20 changes: 10 additions & 10 deletions e2e-tests/support/pageObjects/global-po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ export const alertTitle = '.pf-v5-c-alert__title';

export const consentButton = '[id="truste-consent-button"]';

export const loginPO = {
usernameForm: '.pf-c-login__main',
username: '#rh-username-verification-form',
nextButton: '#login-show-step2',
passwordForm: '#login-show-step2',
password: '#rh-password-verification-form',
loginButton: '#rh-password-verification-submit-button',
export const stageLoginPO = {
username: '#username',
password: '#password',
loginButton: '#submit',
dex: `button[type="submit"]`,
loginWithSso: `a[title="Log in with redhat-sso"]`,
};

export const kcLoginPO = {
username: '#username',
export const localKonfluxLoginPO = {
username: '#login',
password: '#password',
loginButton: '#kc-login',
loginButton: '#submit-login',
dex: `button[type="submit"]`,
};

export const waits = {
Expand Down
Loading
Loading