Skip to content

Commit

Permalink
ci: deploy e2e report to firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Nov 13, 2024
1 parent e042393 commit 8db3e42
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 43 deletions.
15 changes: 15 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"projects": {},
"targets": {
"taiga-editor": {
"hosting": {
"taiga-editor": [
"taiga-editor"
],
"taiga-editor-e2e-report": [
"taiga-editor-e2e-report"
]
}
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:

env:
JOBS_NAME: '[ "Build package", "Build demo", "Lint", "Tests", "E2E" ]'
JOBS_NAME: '[ "Build package", "Lint", "Tests", "E2E" ]'

jobs:
setup:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-demo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: ⚙️ Build demo
on:
pull_request:
push:
branches:
- main
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/cleanup-resources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 🤖 Cleanup resources after close PR
on:
pull_request:
types: [closed]

jobs:
purge-cache:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
BRANCH: refs/pull/${{ github.event.number }}/merge
steps:
- uses: actions/[email protected]
continue-on-error: true
- run: |
gh cache list --ref $BRANCH > cache.log && cat cache.log
for cacheId in $(gh cache list --ref $BRANCH --json id | jq -r .[].id); do
echo "> gh cache delete $cacheId"
gh cache delete $cacheId
done
delete-firebase-channel:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/[email protected]
- uses: w9jds/[email protected]
continue-on-error: true
with:
args: hosting:channel:delete pr${{ github.event.number }}-${{ github.head_ref }} --force
env:
GCP_SA_KEY: ${{ secrets.FIREBASE_TAIGA_PREVIEWS_SA }}
PROJECT_ID: taiga-editor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches: [main]

jobs:
deploy:
prod:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
name: 🚀 Deploy / preview
name: 🚀 Deploy
on: pull_request

jobs:
build_and_preview:
name: Firebase
staging:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: taiga-family/ci/actions/setup/[email protected]
- uses: taiga-family/ci/actions/setup/[email protected]
- run: npx nx build editor-demo
- name: Deploy preview
uses: FirebaseExtended/action-hosting-deploy@v0
- uses: FirebaseExtended/[email protected]
continue-on-error: true
if: ${{ env.IS_FORK == 'false' && env.IS_DEPENDABOT == 'false' }}
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_TUI_EDITOR }}
repoToken: ${{ secrets.GITHUB_TOKEN }}
projectId: taiga-editor
target: taiga-editor
expires: 1d

concurrency:
Expand Down
37 changes: 31 additions & 6 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ jobs:
e2e:
name: E2E
runs-on: ubuntu-latest
env:
PW_RESULT: ./projects/demo-playwright/tests-results
steps:
- uses: actions/[email protected]
- uses: taiga-family/ci/actions/setup/[email protected]
Expand All @@ -32,22 +34,45 @@ jobs:
- run: npx nx e2e editor-demo-playwright
continue-on-error: true

- uses: actions/[email protected]
- run: tree ${{ env.PW_RESULT }}
- name: Deploy e2e report
id: e2e-report
uses: FirebaseExtended/[email protected]
continue-on-error: true
with:
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_TUI_EDITOR }}
repoToken: ${{ secrets.GITHUB_TOKEN }}
target: taiga-editor-e2e-report
projectId: taiga-editor
disableComment: 'true'
expires: 1d

- name: Upload artifacts / ${{ env.PLAYWRIGHT_SNAPSHOTS_ARTIFACTS_KEY }}
uses: actions/[email protected]
id: artifact
with:
path: ./projects/demo-playwright/tests-results/**/*-diff.png
path: ${{ env.PW_RESULT }}/**/*-retry2/*-diff.png
name: ${{ env.PLAYWRIGHT_SNAPSHOTS_ARTIFACTS_KEY }}
if-no-files-found: ignore
compression-level: 0
retention-days: 1

- id: diff-checker
- name: Check if diff-output exists
id: diff_checker
run: |
echo "diff_exist=$(find ./projects/demo-playwright/tests-results -regex '.*diff\.png$' | wc -l | sed -e 's/^[[:space:]]*//')" >> $GITHUB_OUTPUT
- if: ${{ steps.diff-checker.outputs.diff_exist != '0' }}
echo "diff_exist=$(find ${{ env.PW_RESULT }} -path '*retry2/*' -iname '*-diff.png' | wc -l | sed -e 's/^[[:space:]]*//')" >> $GITHUB_OUTPUT
- name: Fall with an error if diff-output exists
if: ${{ steps.diff_checker.outputs.diff_exist != '0' }}
run: |
find ./projects/demo-playwright/tests-results -regex '.*diff\.png$' -exec echo "{}" \;
find ${{ env.PW_RESULT }} -path '*retry2/*' -iname '*-diff.png' -exec echo "{}" \;
exit 1
- uses: daun/[email protected]
if: always()
with:
custom-info: 'For more information, [see our report](${{ steps.e2e-report.outputs.details_url }})'
report-file: ${{ env.PW_RESULT }}/test-results.json

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# misc
/coverage
test-results.json
*.log

# System Files
Expand Down
35 changes: 25 additions & 10 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
{
"hosting": {
"public": "dist/demo/browser",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
"$schema": "https://raw.githubusercontent.com/firebase/firebase-tools/master/schema/firebase-config.json",
"hosting": [
{
"target": "taiga-editor",
"public": "dist/demo/browser",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
{
"target": "taiga-editor-e2e-report",
"public": "projects/demo-playwright/tests-report",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
]
}
26 changes: 16 additions & 10 deletions projects/demo-playwright/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
import type {ViewportSize} from '@playwright/test';
import {defineConfig, devices} from '@playwright/test';

/**
* See https://playwright.dev/docs/test-configuration.
*/
const DEFAULT_VIEWPORT: ViewportSize = {width: 750, height: 700};

export default defineConfig({
testDir: __dirname,
testMatch: '**/*.spec.ts',
outputDir: 'tests-results',
snapshotDir: 'snapshots',
reporter: process.env.CI ? 'github' : [['html', {outputFolder: 'tests-report'}]],
reporter: [
['html', {outputFolder: 'tests-report'}],
['json', {outputFile: 'tests-results/test-results.json'}],
],
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? '100%' : '50%',
timeout: 5 * 60 * 1000,
use: {
baseURL: `http://localhost:${process.env.NG_SERVER_PORT ?? 3333}`,
trace: 'on-first-retry',
testIdAttribute: 'automation-id',
actionTimeout: 10_000,
contextOptions: {
deviceScaleFactor: 2,
reducedMotion: 'reduce',
viewport: DEFAULT_VIEWPORT,
screen: DEFAULT_VIEWPORT,
hasTouch: true,
},
},
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome HiDPI'],
viewport: {
width: 720,
height: 1024,
},
viewport: DEFAULT_VIEWPORT,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion projects/demo-playwright/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"e2e-ui": {
"executor": "nx:run-commands",
"options": {
"command": "nx e2e editor-demo-playwright -- --ui --debug --update-snapshots"
"command": "nx e2e editor-demo-playwright --ui --debug --update-snapshots"
}
}
}
Expand Down
33 changes: 26 additions & 7 deletions projects/demo-playwright/tests/toolbar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ test.describe('Toolbar', () => {
await page.locator('[contenteditable]').nth(0).focus();
await page.locator('[automation-id="toolbar__color-button"]').focus();
await page.keyboard.press('Enter');
await page.waitForTimeout(300);

await page.locator('[automation-id="toolbar__hilite-button"]').focus();
await page.keyboard.press('Enter');
await page.waitForTimeout(300);

await expect(page.locator('#demo-content tui-editor')).toHaveScreenshot(
'Toolbar-02.png',
Expand All @@ -30,6 +32,7 @@ test.describe('Toolbar', () => {
await page.locator('[contenteditable]').nth(0).focus();
await page.locator('[automation-id="toolbar__color-button"]').focus();
await page.keyboard.press('Enter');
await page.waitForTimeout(300);

await expect(page.locator('#demo-content tui-editor')).toHaveScreenshot(
'Toolbar-03.png',
Expand Down Expand Up @@ -58,6 +61,7 @@ test.describe('Toolbar', () => {
await expect(page.locator('tui-editor')).toHaveScreenshot('Toolbar-07.png');

await page.keyboard.type('awesome library for awesome people');
await page.waitForTimeout(300);

await expect(page.locator('tui-editor')).toHaveScreenshot('Toolbar-08.png');

Expand All @@ -75,11 +79,16 @@ test.describe('Toolbar', () => {

await page.locator('[contenteditable]').nth(0).focus();
await page.keyboard.type('\n\n\n\n');
await page.waitForTimeout(300);

await page.keyboard.press('ArrowUp');
await page.keyboard.press('ArrowUp');
await page.keyboard.press('ArrowUp');
await page.locator('[contenteditable]').scrollIntoViewIfNeeded();
await page.waitForTimeout(100);

await page.locator('[automation-id="toolbar__insert-table-button"]').click();
await page.waitForTimeout(100);

await expect(page.locator('tui-editor')).toHaveScreenshot('Toolbar-11.png');

Expand All @@ -105,36 +114,40 @@ test.describe('Toolbar', () => {
await expect(page.locator('tui-editor')).toHaveScreenshot('Toolbar-13.png');

await page.locator('[automation-id="toolbar__ordering-list-button"]').focus();
await page.waitForTimeout(100);

await page.keyboard.press('Enter');
await page.waitForTimeout(300);

await page
.locator('[automation-id="toolbar__un-ordered-list-button"].t-option')
.focus();
await page.waitForTimeout(100);

await page.keyboard.press('Enter');
await page.waitForTimeout(300);

await page.locator('[automation-id="toolbar__font-style-button"]').focus();
await page.waitForTimeout(100);

await page.keyboard.press('Enter');
await page.waitForTimeout(300);

await page.locator('[contenteditable]').nth(0).focus();
await page.waitForTimeout(100);

await page.keyboard.type('12345');
await page.waitForTimeout(300);

await expect(page.locator('tui-editor')).toHaveScreenshot('Toolbar-14.png');

await page.locator('[automation-id="toolbar__insert-table-button"]').focus();
await page.waitForTimeout(100);

await page.keyboard.press('Enter');
await page.waitForTimeout(300);

const cell = page
.locator('tui-table-size-selector .t-column')
.nth(1)
.locator('.t-cell')
.nth(1);

await page.waitForTimeout(100);
await cell.hover();
await cell.click();

Expand All @@ -149,17 +162,24 @@ test.describe('Toolbar', () => {
await page.locator('[contenteditable]').nth(0).focus();
await page.locator('[automation-id="toolbar__align-button"]').focus();
await page.keyboard.press('Enter');
await page.waitForTimeout(300);

await expect(page.locator('tui-editor')).toHaveScreenshot('Toolbar-16.png');

await page.locator('[contenteditable]').nth(0).focus();
await page.locator('[automation-id="toolbar__align-button"]').focus();
await page.keyboard.press('Enter');
await page.waitForTimeout(300);
await page.keyboard.press('ArrowRight');
await page.keyboard.press('Enter');
await page.waitForTimeout(300);

await expect(page.locator('tui-editor')).toHaveScreenshot('Toolbar-17.png');

await page.keyboard.press('ArrowLeft');
await page.keyboard.press('ArrowLeft');
await page.keyboard.press('Enter');
await page.waitForTimeout(300);

await expect(page.locator('tui-editor')).toHaveScreenshot('Toolbar-18.png');
});
Expand All @@ -170,7 +190,6 @@ test.describe('Toolbar', () => {
await page.locator('[contenteditable]').nth(0).focus();
await page.keyboard.press('Meta+A');
await page.keyboard.press('Backspace');
await page.waitForTimeout(300);

await expect(page.locator('tui-editor')).toHaveScreenshot('Toolbar-19.png');

Expand Down
Loading

0 comments on commit 8db3e42

Please sign in to comment.