diff --git a/.github/workflows/job-build.yml b/.github/workflows/job-build.yml new file mode 100644 index 0000000..860c2c0 --- /dev/null +++ b/.github/workflows/job-build.yml @@ -0,0 +1,38 @@ +name: Build + +on: + workflow_call: + +env: + BASE_URL: ${{ vars.BASE_URL }} + +jobs: + build: + timeout-minutes: 10 + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + - name: Install dependencies + run: npm ci + - name: Build + run: npm run build + - uses: actions/upload-artifact@v3 + with: + name: dist + path: dist/ + retention-days: 1 + - name: Fix permissions + run: | + chmod -c -R +rX "dist/" | while read line; do + echo "::warning title=Invalid file permissions automatically fixed::$line" + done + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@v2 + with: + path: dist/ diff --git a/.github/workflows/test-workflow.yml b/.github/workflows/job-e2e-test.yml similarity index 75% rename from .github/workflows/test-workflow.yml rename to .github/workflows/job-e2e-test.yml index f0b35ff..ba124f9 100644 --- a/.github/workflows/test-workflow.yml +++ b/.github/workflows/job-e2e-test.yml @@ -1,10 +1,14 @@ -name: Test +name: E2e Test on: workflow_call: jobs: - test: + build: + uses: ./.github/workflows/job-build.yml + + e2e-test: + needs: build timeout-minutes: 10 runs-on: ubuntu-latest steps: @@ -16,15 +20,11 @@ jobs: run: npm ci - name: Install Playwright browsers run: npx playwright install --with-deps chromium - - name: Build - run: npm run build - - uses: actions/upload-artifact@v3 + - name: Download the build artifacts + uses: actions/download-artifact@v3 with: name: dist path: dist/ - retention-days: 1 - - name: Run Unit Tests - run: npm run test:unit:coverage - name: Run E2e Tests run: npm run test:e2e - uses: actions/upload-artifact@v3 diff --git a/.github/workflows/job-unit-test.yml b/.github/workflows/job-unit-test.yml new file mode 100644 index 0000000..2872d08 --- /dev/null +++ b/.github/workflows/job-unit-test.yml @@ -0,0 +1,18 @@ +name: Unit Test + +on: + workflow_call: + +jobs: + unit-test: + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + - name: Install dependencies + run: npm ci + - name: Run Unit Tests + run: npm run test:unit:coverage diff --git a/.github/workflows/main-branch.yml b/.github/workflows/main-branch.yml new file mode 100644 index 0000000..1fa2f24 --- /dev/null +++ b/.github/workflows/main-branch.yml @@ -0,0 +1,38 @@ +name: Main Branch +run-name: ${{ github.actor }} is running main branch checks and deploy 🚀 + +on: + push: + branches: [main, EO-28/deploy-to-github-pages] + +env: + CI: true + BASE_URL: ${{ vars.BASE_URL }} + +concurrency: + group: 'pages' + cancel-in-progress: true + +jobs: + unit-test: + uses: ./.github/workflows/job-unit-test.yml + + e2e-test: + uses: ./.github/workflows/job-e2e-test.yml + + deploy: + needs: [unit-test, e2e-test] + runs-on: ubuntu-latest + permissions: + contents: read + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v3 + with: + timeout: 300000 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 68ddc1b..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Main Branch -run-name: ${{ github.actor }} is running main branch tests 🚀 - -on: - push: - branches: [main] - -env: - CI: true - -jobs: - test: - uses: ./.github/workflows/test-workflow.yml diff --git a/.github/workflows/pr-rename.yml b/.github/workflows/pull-request-title.yml similarity index 79% rename from .github/workflows/pr-rename.yml rename to .github/workflows/pull-request-title.yml index 96567a2..1dcfab2 100644 --- a/.github/workflows/pr-rename.yml +++ b/.github/workflows/pull-request-title.yml @@ -1,5 +1,5 @@ -name: Pull Request -run-name: ${{ github.actor }} is running pull request checks 🚀 +name: Pull Request Title +run-name: ${{ github.actor }} is checking the pull request title 🚀 on: pull_request: @@ -14,7 +14,7 @@ jobs: steps: - name: Check PR title run: | - if [[ "${{ github.event.pull_request.title }}" =~ ^\[EO+-[0-9]+\] ]]; then + if [[ "${{ github.event.pull_request.title }}" =~ ^\[EO-[0-9]+\] ]]; then echo "Pr title is correct" else echo "Incorrect PR title: should starts with [EO-XXXX] where XXXX is a task number" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 6f36267..da88df1 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -8,9 +8,6 @@ env: CI: true jobs: - test: - uses: ./.github/workflows/test-workflow.yml - lint: timeout-minutes: 10 runs-on: ubuntu-latest @@ -23,3 +20,9 @@ jobs: run: npm ci - name: Run Lint run: npm run lint + + unit-test: + uses: ./.github/workflows/job-unit-test.yml + + e2e-test: + uses: ./.github/workflows/job-e2e-test.yml diff --git a/index.html b/index.html index eff9577..209a689 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,6 @@ - OpenAPI editor diff --git a/src/main.tsx b/src/main.tsx index 3f2a483..ab4c044 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -4,7 +4,10 @@ import './index.css'; import { createBrowserRouter, RouterProvider } from 'react-router-dom'; import routes from './routes'; -const router = createBrowserRouter(routes); +const router = createBrowserRouter(routes, { + basename: import.meta.env.BASE_URL, +}); +console.log(router); ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( diff --git a/tests/e2e/example.test.ts b/tests/e2e/example.test.ts index 480d0e2..64d83ee 100644 --- a/tests/e2e/example.test.ts +++ b/tests/e2e/example.test.ts @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test'; test.describe('Main page', () => { test('should import schema', async ({ page }) => { - await page.goto('/'); + await page.goto(process.env.BASE_URL || '/'); await expect(page.getByTestId('import-schema-drawer')).not.toBeVisible(); diff --git a/vite.config.ts b/vite.config.ts index 452e5df..a28b554 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,8 +2,12 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react-swc'; +import 'dotenv/config'; + +console.log('ENV!!!', process.env.CI, process.env.BASE_URL); export default defineConfig({ + base: process.env.BASE_URL || '/', plugins: [react()], server: { port: 3000,