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

Add workflow #1

Draft
wants to merge 13 commits into
base: devel
Choose a base branch
from
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cypress.config.ts
playwright.config.ts
40 changes: 40 additions & 0 deletions .github/workflows/ui-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'Run Playwright UI tests'

on:
pull_request:

env:
USER_EMAIL: "uitest-${{ github.run_id }}@lumeer.io"
USER_PASSWORD: ${{ secrets.USER_PASSWORD }}

jobs:
run-tests:
timeout-minutes: 60
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11.0.12'
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Build (mvn clean install)
run: |
chmod +x ./playwright-scripts/build.sh
./playwright-scripts/build.sh
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run tests
run: |
chmod +x ./playwright-scripts/playwright-tests.sh
./playwright-scripts/playwright-tests.sh
shell: bash
- name: "Upload artifact"
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ src/assets/config/config.json
.settings/

**/.DS_Store
/test-results/
/playwright-report/
/playwright/.cache/
/playwright/.auth/
66 changes: 66 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"test:watch": "ng test --watch",
"cypress:open": "npx cypress open",
"cypress:run": "npx cypress run",
"prepare": "husky install"
"prepare": "husky install",
"playwright:run": "playwright test"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -79,6 +80,7 @@
"d3-time-format": "^4.1.0",
"d3-zoom": "^3.0.0",
"dompurify": "^2.4.4",
"dotenv": "^16.3.1",
"driver.js": "^0.9.8",
"file-saver": "^2.0.5",
"flag-icons": "^6.6.6",
Expand Down Expand Up @@ -121,6 +123,7 @@
"@angular/language-service": "^14.2.12",
"@compodoc/compodoc": "^1.1.19",
"@ngrx/schematics": "^14.3.3",
"@playwright/test": "^1.35.1",
"@sentry/cli": "^2.7.0",
"@types/auth0-js": "^9.14.7",
"@types/big.js": "^6.1.6",
Expand Down
12 changes: 12 additions & 0 deletions playwright-scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Abort on Error
set -e

# Set up a repeating loop to send some output to Travis.
export PING_SLEEP=300s
bash -c "while true; do echo \$(date) - building ...; sleep $PING_SLEEP; done" &
export BUILD_PING_LOOP_PID=$!

LUMEER_ENV=testing COMPILER_NODE_OPTIONS=--max_old_space_size=4000 mvn clean install war:war -Dcontext.root=/

kill $BUILD_PING_LOOP_PID 2> /dev/null || :
47 changes: 47 additions & 0 deletions playwright-scripts/playwright-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
# Abort on Error
set -e

# Set up a repeating loop to send some output to Github Actions environment.
export PING_SLEEP=300s
bash -c "while true; do echo \$(date) - building ...; sleep $PING_SLEEP; done" &
export PING_LOOP_PID=$!

echo "Starting frontend..."
npm run http-server &
while ! curl --output /dev/null --silent -r 0-0 --fail "http://127.0.0.1:7000"; do
sleep 3
done
cd playwright-scripts
echo "Starting backend..."
./start-engine.sh
RESPONSE=$(curl http://localhost:8080/lumeer-engine/)

PASSED=false
cd ../
echo "Running E2E tests..."
set +e
npm run playwright:run
if [[ $? -ne 0 ]]; then
set -e
npm run playwright:run

if [[ $? -eq 0 ]]; then
PASSED=true
fi
else
set -e
PASSED=true
fi

echo "Stopping frontend..."
pkill npm

cd playwright-scripts
echo "Stopping backend..."
./stop-engine.sh

echo "Printing bundle sizes..."
npm run bundlesize

kill $PING_LOOP_PID
38 changes: 38 additions & 0 deletions playwright-scripts/start-engine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
ORIG=$(pwd)

if [ -d ~/.engine -a -d ~/.engine/.git ]; then
echo "Pulling latest engine updates..."
cd ~/.engine
git checkout devel
git pull origin devel
else
echo "Downloading engine..."
git clone https://github.com/Lumeer/engine.git ~/.engine
cd ~/.engine
git checkout devel
fi

echo ls
chmod +w ./lumeer-core/src/main/resources/defaults-dev.properties
echo $'\n' >> ./lumeer-core/src/main/resources/defaults-dev.properties
echo $"admin_user_emails=$USER_EMAIL" >> ./lumeer-core/src/main/resources/defaults-dev.properties
cat ./lumeer-core/src/main/resources/defaults-dev.properties
echo "Building engine..."
mvn install -DskipTests -DskipITs -B --quiet
cd war

echo "Starting engine..."
export SKIP_LIMITS=true
mvn -s settings.xml wildfly:run -PstartEngine -B --quiet &
echo $! > $ORIG/engine.pid

echo "Waiting for engine to start..."
while test $(curl -s -o /dev/null -I -w "%{http_code}" http://localhost:8080/lumeer-engine/rest/users) != 401; do
sleep 10
done
sleep 5

echo "Engine started!"

cd $ORIG
16 changes: 16 additions & 0 deletions playwright-scripts/stop-engine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
PID=$(cat engine.pid)
if [ ! -z $PID ]; then
echo "Stopping engine..."
if ps -p $PID >/dev/null; then
kill $PID
sleep 5
if ps -p $PID >/dev/null; then
kill -9 $PID
fi
fi

rm engine.pid

echo "Engine stopped!"
fi
55 changes: 55 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {defineConfig, devices} from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './playwright',
timeout: 60000,
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
baseURL: 'http://localhost:7000/ui',
},
expect: {
timeout: 10000,
},

/* Configure projects for major browsers */
projects: [
{
name: 'onboarding',
use: {...devices['Desktop Chrome']},
testMatch: /onboarding.spec\.ts/,
teardown: 'teardown',
},
{
name: 'tests',
use: {
...devices['Desktop Chrome'],
storageState: 'playwright/.auth/user.json',
},
testMatch: '*playwright/*.spec.ts',
testIgnore: /onboarding.spec\.ts/,
dependencies: ['onboarding'],
},
{
name: 'teardown',
testMatch: /global.teardown\.ts/,
},
],
});
Loading