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

Improve pipelines #2

Merged
merged 2 commits into from
Mar 28, 2024
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
71 changes: 58 additions & 13 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ env:
AUTH_SECRET: E2E

jobs:
e2e:
run-tests:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.repository == 'aulasoftwarelibre/codex' && (startsWith(github.ref, 'refs/heads/releases/') || startsWith(github.ref, 'refs/tags/v') )
if: always()
services:
smtp:
image: "corpusops/mailhog:v1.0.1"
image: "inbucket/inbucket"
ports:
- 1025:1025
- 8025:8025
- 1025:2500
- 8025:9000
db:
image: "postgres:12"
env:
Expand All @@ -30,27 +30,72 @@ jobs:
ports:
- 5432:5432
strategy:
fail-fast: false
matrix:
node-version: [ 20.x ]
name: Run e2e tests on Node ${{ matrix.node-version }}
shardIndex: [ 1, 2 ]
shardTotal: [ 2 ]
name: Run e2e shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
env:
DATABASE_URL: postgres://postgres@localhost/codex_test_${{ matrix.shardIndex}}
NODE_ENV: test
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache: 'pnpm'
- name: Install dependencies
run: yarn install --frozen-lockfile
run: pnpm install --frozen-lockfile --prefer-offline
- name: Run database migrations
run: yarn prisma:migrate
run: npx prisma migrate reset --force
- name: Store Playwright's Version
run: |
PLAYWRIGHT_VERSION=$(pnpm ls @playwright/test | grep @playwright | sed 's/.*@//')
echo "Playwright's Version: $PLAYWRIGHT_VERSION"
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: Cache Playwright Browsers for Playwright's Version
id: cache-playwright-browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }}
- name: Setup Playwright
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true'
run: npx playwright install chromium --with-deps
- name: Run e2e tests
run: yarn test:e2e
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
- name: Upload test report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
name: blob-report-${{ matrix.shardIndex }}
path: blob-report/
retention-days: 1

merge-reports:
if: failure()
needs: [run-tests]
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 20.x ]
steps:
- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v4
with:
path: all-blob-reports
pattern: blob-report-*
merge-multiple: true
- name: Merge into HTML Report
run: npx playwright merge-reports --reporter html ./all-blob-reports
- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-report--attempt-${{ github.run_attempt }}
path: playwright-report
retention-days: 7
2 changes: 1 addition & 1 deletion .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_call:

jobs:
tests:
run-tests:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -13,12 +13,14 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache: 'pnpm'
- name: Install dependencies
run: yarn install --frozen-lockfile
run: pnpm install --frozen-lockfile --prefer-offline
- name: Run tests
run: yarn test:ci
run: pnpm run test:ci
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public-hoist-pattern[]=*@nextui-org/*
13 changes: 13 additions & 0 deletions e2e/tests/helpers/gravatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createHash } from 'crypto'

export function gravatar(email: string | null) {
if (!email) {
return `http://www.gravatar.com/avatar`
}

const hash = createHash('sha256')
.update(email.trim().toLowerCase())
.digest('hex')

return `https://gravatar.com/avatar/${hash}.jpg`
}
3 changes: 3 additions & 0 deletions e2e/tests/helpers/prisma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { PrismaClient } from '@prisma/client'

export const prisma = new PrismaClient()
2 changes: 1 addition & 1 deletion e2e/tests/pages/book.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Page } from '@playwright/test'
import { ulid } from 'ulid'

import { prisma } from '@/lib/prisma/prisma'
import { prisma } from '../helpers/prisma'

export class BookPage {
constructor(private readonly page: Page) {}
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/pages/settings.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Page } from '@playwright/test'

import { prisma } from '@/lib/prisma/prisma'
import { gravatar } from '@/lib/utils/gravatar'
import { gravatar } from '../helpers/gravatar'
import { prisma } from '../helpers/prisma'

export class SettingsPage {
constructor(private readonly page: Page) {}
Expand Down
39 changes: 21 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
"start": "next start",
"lint": "next lint",
"prepare": "husky",
"postinstall": "npx prisma generate",
"test": "vitest",
"coverage": "vitest run --coverage",
"test:ci": "NODE_ENV=test vitest --watch=false",
"test:ui": "NODE_ENV=test vitest --ui --coverage.enabled=true",
"pretest:e2e": "playwright install",
"pretest:e2e": "playwright install chromium --with-deps",
"test:e2e": "rimraf playwright && NODE_ENV=test playwright test",
"pretest:e2e:ui": "playwright install",
"pretest:e2e:ui": "playwright install chromium --with-deps",
"test:e2e:ui": "rimraf playwright && NODE_ENV=test playwright test --ui",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
Expand All @@ -28,13 +29,13 @@
},
"dependencies": {
"@aulasoftwarelibre/next-auth-firewall": "1.2.0",
"@auth/prisma-adapter": "^1.5.0",
"@auth/prisma-adapter": "^1.5.1",
"@heroicons/react": "^2.1.3",
"@nextui-org/react": "2.2.9",
"@opentelemetry/api": "^1.8.0",
"@prisma/client": "^5.11.0",
"date-fns": "^3.6.0",
"framer-motion": "^11.0.20",
"framer-motion": "^11.0.22",
"neverthrow": "^6.1.0",
"next": "14.1.4",
"next-auth": "5.0.0-beta.9",
Expand All @@ -55,37 +56,38 @@
"@commitlint/cli": "^19.2.1",
"@commitlint/config-conventional": "19.1.0",
"@playwright/test": "^1.42.1",
"@storybook/addon-essentials": "^8.0.4",
"@storybook/addon-interactions": "^8.0.4",
"@storybook/addon-links": "^8.0.4",
"@storybook/addon-onboarding": "^8.0.4",
"@storybook/addon-themes": "^8.0.4",
"@storybook/blocks": "^8.0.4",
"@storybook/nextjs": "^8.0.4",
"@storybook/react": "^8.0.4",
"@storybook/addon-essentials": "^8.0.5",
"@storybook/addon-interactions": "^8.0.5",
"@storybook/addon-links": "^8.0.5",
"@storybook/addon-onboarding": "^8.0.5",
"@storybook/addon-themes": "^8.0.5",
"@storybook/blocks": "^8.0.5",
"@storybook/nextjs": "^8.0.5",
"@storybook/react": "^8.0.5",
"@storybook/testing-library": "^0.2.2",
"@testcontainers/postgresql": "^10.7.2",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.2",
"@types/lodash.clonedeep": "^4.5.9",
"@types/node": "^20.11.30",
"@types/nodemailer": "^6.4.14",
"@types/react": "^18.2.69",
"@types/react": "^18.2.73",
"@types/react-dom": "^18.2.22",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-v8": "1.4.0",
"@vitest/ui": "1.4.0",
"autoprefixer": "^10.4.19",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-next": "14.1.4",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-simple-import-sort": "^12.0.0",
"eslint-plugin-sort": "^3.0.1",
"eslint-plugin-sort": "^3.0.2",
"eslint-plugin-storybook": "^0.8.0",
"eslint-plugin-unicorn": "^51.0.1",
"eslint-plugin-unused-imports": "^3.1.0",
Expand All @@ -96,8 +98,9 @@
"postcss": "^8.4.38",
"prettier": "^3.2.5",
"prisma": "^5.11.0",
"storybook": "^8.0.4",
"tailwindcss": "^3.4.1",
"rimraf": "^5.0.5",
"storybook": "^8.0.5",
"tailwindcss": "^3.4.3",
"testcontainers": "^10.7.2",
"tsx": "^4.7.1",
"typescript": "^5.4.3",
Expand Down
3 changes: 2 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dotenv.config({
path: '.env.test',
})

// eslint-disable-next-line import/no-default-export
export default defineConfig({
fullyParallel: false,
projects: [
Expand All @@ -22,7 +23,7 @@ export default defineConfig({
},
},
],
reporter: 'html',
reporter: process.env.CI ? 'blob' : 'html',
retries: 3,
testDir: './e2e',
use: {
Expand Down
Loading