The minimalistic document archiving platform.
chore(ci): mutualized CI workflows (#463)
Corentin Thomassete48745331fff
diff --git a/.github/workflows/ci-apps-docs.yaml b/.github/workflows/ci-apps-docs.yamldeleted file mode 100644index e6177de1..00000000--- a/.github/workflows/ci-apps-docs.yaml+++ /dev/null@@ -1,42 +0,0 @@-name: CI - Docs--on:- pull_request:- push:- branches:- - main--jobs:- ci-apps-docs:- name: CI - Docs- runs-on: ubuntu-latest- defaults:- run:- working-directory: apps/docs-- steps:- - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4-- - name: Install pnpm- uses: pnpm/action-setup@v4-- - uses: actions/setup-node@v4- with:- node-version: 22- cache: 'pnpm'-- - name: Install dependencies- run: pnpm i- working-directory: ./-- - name: Run linters- run: pnpm lint-- # - name: Type check- # run: pnpm typecheck-- # - name: Run unit test- # run: pnpm test-- - name: Build the app- run: pnpm build\ No newline at end of filediff --git a/.github/workflows/ci-apps-papra-client.yaml b/.github/workflows/ci-apps-papra-client.yamldeleted file mode 100644index 36f7ae75..00000000--- a/.github/workflows/ci-apps-papra-client.yaml+++ /dev/null@@ -1,49 +0,0 @@-name: CI - App Client--on:- pull_request:- push:- branches:- - main--jobs:- ci-apps-papra-client:- name: CI - Papra Client- runs-on: ubuntu-latest- defaults:- run:- working-directory: apps/papra-client-- steps:- - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4-- - name: Install pnpm- uses: pnpm/action-setup@v4-- - uses: actions/setup-node@v4- with:- node-version: 22- cache: 'pnpm'-- - name: Install dependencies- run: pnpm i- working-directory: ./-- - name: Run linters- run: pnpm lint-- - name: Type check- run: pnpm typecheck-- - name: Run unit test- run: pnpm test-- # Ensure locales types are up to date, must be run before building the app- - name: Check locales types- run: |- pnpm script:generate-i18n-types- git diff --exit-code -- src/modules/i18n/locales.types.ts > /dev/null || (echo "Locales types are outdated, please run 'pnpm script:generate-i18n-types' and commit the changes." && exit 1)-- - name: Build the app- run: pnpm build-diff --git a/.github/workflows/ci-apps-papra-server.yaml b/.github/workflows/ci-apps-papra-server.yamldeleted file mode 100644index 6abe9cca..00000000--- a/.github/workflows/ci-apps-papra-server.yaml+++ /dev/null@@ -1,43 +0,0 @@-name: CI - App Server--on:- pull_request:- push:- branches:- - main--jobs:- ci-apps-papra-server:- name: CI - Papra Server- runs-on: ubuntu-latest- defaults:- run:- working-directory: apps/papra-server-- steps:- - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4-- - name: Install pnpm- uses: pnpm/action-setup@v4-- - uses: actions/setup-node@v4- with:- node-version: 22- cache: 'pnpm'-- - name: Install dependencies- run: |- pnpm i --frozen-lockfile- pnpm --filter "@papra/app-server^..." build-- - name: Run linters- run: pnpm lint-- - name: Type check- run: pnpm typecheck-- - name: Run unit test- run: pnpm test-- - name: Build the app- run: pnpm build\ No newline at end of filediff --git a/.github/workflows/ci-packages-api-sdk.yaml b/.github/workflows/ci-packages-api-sdk.yamldeleted file mode 100644index 8b1caf80..00000000--- a/.github/workflows/ci-packages-api-sdk.yaml+++ /dev/null@@ -1,41 +0,0 @@-name: CI - Api SDK--on:- pull_request:- push:- branches:- - main--jobs:- ci-packages-api-sdk:- name: CI - Api SDK- runs-on: ubuntu-latest- defaults:- run:- working-directory: packages/api-sdk-- steps:- - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4-- - name: Install pnpm- uses: pnpm/action-setup@v4-- - uses: actions/setup-node@v4- with:- node-version: 22- cache: 'pnpm'-- - name: Install dependencies- run: pnpm i-- - name: Run linters- run: pnpm lint-- - name: Type check- run: pnpm typecheck-- # - name: Run unit test- # run: pnpm test-- - name: Build the app- run: pnpm build\ No newline at end of filediff --git a/.github/workflows/ci-packages-cli.yaml b/.github/workflows/ci-packages-cli.yamldeleted file mode 100644index 0217b1d8..00000000--- a/.github/workflows/ci-packages-cli.yaml+++ /dev/null@@ -1,44 +0,0 @@-name: CI - CLI--on:- pull_request:- push:- branches:- - main--jobs:- ci-packages-cli:- name: CI - CLI- runs-on: ubuntu-latest- defaults:- run:- working-directory: packages/cli-- steps:- - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4-- - name: Install pnpm- uses: pnpm/action-setup@v4-- - uses: actions/setup-node@v4- with:- node-version: 22- cache: 'pnpm'-- - name: Install dependencies- run: pnpm i-- - name: Build related packages- run: cd ../api-sdk && pnpm build-- - name: Run linters- run: pnpm lint-- - name: Type check- run: pnpm typecheck-- # - name: Run unit test- # run: pnpm test-- - name: Build the app- run: pnpm build\ No newline at end of filediff --git a/.github/workflows/ci-packages-lecture.yaml b/.github/workflows/ci-packages-lecture.yamldeleted file mode 100644index b64bc192..00000000--- a/.github/workflows/ci-packages-lecture.yaml+++ /dev/null@@ -1,41 +0,0 @@-name: CI - Lecture--on:- pull_request:- push:- branches:- - main--jobs:- ci-packages-lecture:- name: CI - Lecture- runs-on: ubuntu-latest- defaults:- run:- working-directory: packages/lecture-- steps:- - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4-- - name: Install pnpm- uses: pnpm/action-setup@v4-- - uses: actions/setup-node@v4- with:- node-version: 22- cache: 'pnpm'-- - name: Install dependencies- run: pnpm i-- - name: Run linters- run: pnpm lint-- - name: Type check- run: pnpm typecheck-- - name: Run unit test- run: pnpm test-- - name: Build the app- run: pnpm build\ No newline at end of filediff --git a/.github/workflows/ci-packages-webhook.yaml b/.github/workflows/ci-packages-webhook.yamldeleted file mode 100644index 591a56a5..00000000--- a/.github/workflows/ci-packages-webhook.yaml+++ /dev/null@@ -1,41 +0,0 @@-name: CI - Webhooks--on:- pull_request:- push:- branches:- - main--jobs:- ci-packages-webhooks:- name: CI - Webhooks- runs-on: ubuntu-latest- defaults:- run:- working-directory: packages/webhooks-- steps:- - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4-- - name: Install pnpm- uses: pnpm/action-setup@v4-- - uses: actions/setup-node@v4- with:- node-version: 22- cache: 'pnpm'-- - name: Install dependencies- run: pnpm i-- - name: Run linters- run: pnpm lint-- - name: Type check- run: pnpm typecheck-- - name: Run unit test- run: pnpm test-- - name: Build the app- run: pnpm build\ No newline at end of filediff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yamlnew file mode 100644index 00000000..cd5c2881--- /dev/null+++ b/.github/workflows/ci.yaml@@ -0,0 +1,47 @@+name: CI++on:+ pull_request:+ push:+ branches:+ - main++jobs:+ ci:+ name: CI+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4++ - name: Install pnpm+ uses: pnpm/action-setup@v4++ - uses: actions/setup-node@v4+ with:+ node-version: 22+ cache: 'pnpm'++ - name: Install dependencies+ run: pnpm i++ # Build only the packages first to properly run the lint and test first to get faster feedback+ - name: Build packages+ run: pnpm -r --parallel -F "./packages/*" build++ - name: Run linters+ run: pnpm -r --parallel lint++ - name: Type check+ # Exclude docs as their are some typing issues we are ok with for now+ run: pnpm -r --parallel -F "!@papra/docs" typecheck++ # Tests are run using vitest projects+ - name: Run tests+ run: pnpm test++ # Now build the apps, the longer step, so we do it last as they are more unlikely to fail if the previous steps works+ - name: Build the apps+ run: pnpm -r --parallel -F "./apps/*" build++ - name: Ensure no non-excluded files are changed for the whole repo+ run: git diff --exit-code > /dev/null || (echo "After running the CI, some un-committed changes were detected. Please ensure cleanness before merging." && exit 1)\ No newline at end of filediff --git a/.github/workflows/release-docker.yaml b/.github/workflows/release-docker.yamlindex c6ca4d9a..71e7d939 100644--- a/.github/workflows/release-docker.yaml+++ b/.github/workflows/release-docker.yaml@@ -1,10 +1,10 @@-name: Release new versions+name: Build and publish Docker imageson:workflow_dispatch:inputs:version:- description: 'Version to release'+ description: 'Version to release (e.g. 0.8.2)'required: truetype: string@@ -14,7 +14,7 @@ permissions:jobs:docker-release:- name: Release Docker images+ name: Build and publish Docker imagesruns-on: ubuntu-lateststeps:- name: Checkoutdiff --git a/apps/papra-client/package.json b/apps/papra-client/package.jsonindex 48e5a944..3507eb2b 100644--- a/apps/papra-client/package.json+++ b/apps/papra-client/package.json@@ -21,10 +21,11 @@"serve": "vite preview","lint": "eslint .","lint:fix": "eslint --fix .",- "test": "vitest run",+ "test": "pnpm check-i18n-types-outdated && vitest run","test:watch": "vitest watch","test:e2e": "playwright test","typecheck": "tsc --noEmit",+ "check-i18n-types-outdated": "pnpm script:generate-i18n-types && git diff --exit-code -- src/modules/i18n/locales.types.ts > /dev/null || (echo \"Locales types are outdated, please run 'pnpm script:generate-i18n-types' and commit the changes.\" && exit 1)","script:get-missing-i18n-keys": "tsx src/scripts/get-missing-i18n-keys.script.ts","script:generate-i18n-types": "tsx src/scripts/generate-i18n-types.script.ts","script:sync-i18n-key-order": "tsx src/scripts/sync-i18n-key-order.script.ts"diff --git a/apps/papra-client/src/modules/i18n/locales.test.ts b/apps/papra-client/src/modules/i18n/locales.test.tsindex 4c48a65c..4d7a13b4 100644--- a/apps/papra-client/src/modules/i18n/locales.test.ts+++ b/apps/papra-client/src/modules/i18n/locales.test.ts@@ -1,4 +1,6 @@import { readFile } from 'node:fs/promises';+import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';import { glob } from 'tinyglobby';import { describe, expect, test } from 'vitest';@@ -9,6 +11,8 @@ const locales = Object.fromEntries(const { en: defaultLocal } = locales;+const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..');+describe('locales', () => {for (const [locale, translations] of Object.entries(locales)) {describe(locale, () => {@@ -32,7 +36,7 @@ describe('locales', () => {}test('all keys in en.yml must be used in the app (dynamic keys are manually excluded)', async () => {- const srcFileNames = await glob(['src/**/*.{ts,tsx}', '!src/**/*.test.*', '!src/modules/i18n/locales.types.ts'], { cwd: process.cwd() });+ const srcFileNames = await glob(['src/**/*.{ts,tsx}', '!src/**/*.test.*', '!src/modules/i18n/locales.types.ts'], { cwd: packageRoot });// Exclude keys that are used in dynamic contextsconst dynamicKeysMatchers = [@@ -53,7 +57,7 @@ describe('locales', () => {);for (const srcFileName of srcFileNames) {- const fileContent = await readFile(srcFileName, 'utf-8');+ const fileContent = await readFile(join(packageRoot, srcFileName), 'utf-8');for (const key of keys) {if (fileContent.includes(key)) {diff --git a/apps/papra-client/src/plugins/i18n-types/i18n-types.services.ts b/apps/papra-client/src/plugins/i18n-types/i18n-types.services.tsindex 637f4cc9..77fc6722 100644--- a/apps/papra-client/src/plugins/i18n-types/i18n-types.services.ts+++ b/apps/papra-client/src/plugins/i18n-types/i18n-types.services.ts@@ -1,16 +1,16 @@/* eslint-disable no-console */import { readFile, writeFile } from 'node:fs/promises';-import path from 'node:path';-import { cwd as getCwd } from 'node:process';+import { dirname, join, relative } from 'node:path';import { fileURLToPath } from 'node:url';import { parse } from 'yaml';-const filename = fileURLToPath(import.meta.url);+const currentFile = fileURLToPath(import.meta.url);+const packageRoot = join(dirname(currentFile), '..', '..', '..');-export async function generateI18nTypes({ cwd = getCwd() }: { cwd?: string } = {}) {+export async function generateI18nTypes() {try {- const yamlPath = path.join(cwd, 'src/locales/en.yml');- const outputPath = path.join(cwd, 'src/modules/i18n/locales.types.ts');+ const yamlPath = join(packageRoot, 'src/locales/en.yml');+ const outputPath = join(packageRoot, 'src/modules/i18n/locales.types.ts');const enLocales = await readFile(yamlPath, 'utf-8');const parsedLocales = parse(enLocales);@@ -20,7 +20,7 @@ export async function generateI18nTypes({ cwd = getCwd() }: { cwd?: string } = {// Do not manually edit this file.// This file is dynamically generated when the dev server runs (or using the \`pnpm script:generate-i18n-types\` command).// Keys are extracted from the en.yml file.-// Source code : ${path.relative(cwd, filename)}+// Source code : ${relative(packageRoot, currentFile)}export type LocaleKeys =\n${localKeys.map(key => ` | '${key}'`).join('\n')};`.trimStart();diff --git a/apps/papra-client/src/scripts/sync-i18n-key-order.script.ts b/apps/papra-client/src/scripts/sync-i18n-key-order.script.tsindex 58d16f86..cdb5354a 100644--- a/apps/papra-client/src/scripts/sync-i18n-key-order.script.ts+++ b/apps/papra-client/src/scripts/sync-i18n-key-order.script.ts@@ -26,7 +26,7 @@ function indexLinesByKeys(yaml: string) {}function syncLocaleFiles() {- const localesDir = path.join(dirname, '../locales');+ const localesDir = path.join(dirname, '..', 'locales');const enFile = path.join(localesDir, 'en.yml');const enContent = fs.readFileSync(enFile, 'utf8');const enLines = enContent.split('\n');diff --git a/package.json b/package.jsonindex 26d2db2d..b094672a 100644--- a/package.json+++ b/package.json@@ -14,10 +14,13 @@"docker:build:rootless": "docker build -t papra-rootless -f docker/Dockerfile.rootless .","version": "changeset version && pnpm install --no-frozen-lockfile","changeset": "changeset",- "build:packages": "pnpm --filter './packages/*' --stream build"+ "build:packages": "pnpm --filter './packages/*' --stream build",+ "test": "TZ=UTC vitest run",+ "test:watch": "TZ=UTC vitest watch"},"devDependencies": {"@changesets/changelog-github": "^0.5.1",- "@changesets/cli": "^2.29.3"+ "@changesets/cli": "^2.29.3",+ "vitest": "catalog:"}}diff --git a/packages/api-sdk/package.json b/packages/api-sdk/package.jsonindex 4e42a46f..a486f576 100644--- a/packages/api-sdk/package.json+++ b/packages/api-sdk/package.json@@ -36,7 +36,7 @@"scripts": {"lint": "eslint .","lint:fix": "eslint --fix .",- "test": "vitest run",+ "test": "vitest run --passWithNoTests","test:watch": "vitest watch","typecheck": "tsc --noEmit","build": "unbuild"diff --git a/packages/api-sdk/vitest.config.ts b/packages/api-sdk/vitest.config.tsnew file mode 100644index 00000000..94ede10e--- /dev/null+++ b/packages/api-sdk/vitest.config.ts@@ -0,0 +1,3 @@+import { defineConfig } from 'vitest/config';++export default defineConfig({});diff --git a/packages/cli/package.json b/packages/cli/package.jsonindex 29747637..d27888b3 100644--- a/packages/cli/package.json+++ b/packages/cli/package.json@@ -34,7 +34,7 @@"dev": "tsx ./src/cli.ts","lint": "eslint .","lint:fix": "eslint --fix .",- "test": "vitest run",+ "test": "vitest run --passWithNoTests","test:watch": "vitest watch","typecheck": "tsc --noEmit","build": "unbuild"diff --git a/packages/cli/vitest.config.ts b/packages/cli/vitest.config.tsnew file mode 100644index 00000000..94ede10e--- /dev/null+++ b/packages/cli/vitest.config.ts@@ -0,0 +1,3 @@+import { defineConfig } from 'vitest/config';++export default defineConfig({});diff --git a/packages/lecture/src/extractors.usecases.test.ts b/packages/lecture/src/extractors.usecases.test.tsindex 4378dc3d..6c85bbea 100644--- a/packages/lecture/src/extractors.usecases.test.ts+++ b/packages/lecture/src/extractors.usecases.test.ts@@ -1,10 +1,15 @@import fs from 'node:fs/promises';+import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';import mime from 'mime';import { glob } from 'tinyglobby';import { describe, expect, test } from 'vitest';import { extractText, extractTextFromBlob, extractTextFromFile } from './extractors.usecases';-const fixturesDir = await glob(['fixtures/*'], { onlyDirectories: true });+const currentFile = fileURLToPath(import.meta.url);+const packageRoot = join(dirname(currentFile), '..');++const fixturesDir = await glob(['fixtures/*'], { onlyDirectories: true, cwd: packageRoot, absolute: true });describe('extractors usecases', () => {describe('extractText', () => {@@ -36,10 +41,13 @@ describe('extractors usecases', () => {expect(fixturesDir.length).to.be.greaterThan(0);});- for (const fixture of fixturesDir) {+ for (const fixtureDir of fixturesDir) {+ const fixtureName = fixtureDir.split('/').filter(Boolean).pop();+// use test.concurrent to run the tests in parallel -> need to use the provided expect- test(`fixture ${fixture}`, { timeout: 10_000, concurrent: true }, async ({ expect }) => {- const fixtureFilesPaths = await glob([`${fixture}/*`]);+ test(`fixture ${fixtureName}`, { timeout: 10_000, concurrent: true }, async ({ expect }) => {+ const fixtureFilesPaths = await glob(['*'], { cwd: fixtureDir, absolute: true });+const inputFilePath = fixtureFilesPaths.find(name => name.match(/\/\d{3}\.input\.\w+$/));const configFilePath = fixtureFilesPaths.find(name => name.match(/\/\d{3}\.config\.ts$/));@@ -53,8 +61,8 @@ describe('extractors usecases', () => {expect(error).to.eql(undefined);expect(extractorName).to.not.eql(undefined);- const fixtureNumber = fixture.split('/').filter(Boolean).pop().slice(0, 3);- const expectedFilePath = `../${fixture}/${fixtureNumber}.expected.txt`;+ const fixtureNumber = fixtureDir.split('/').filter(Boolean).pop().slice(0, 3);+ const expectedFilePath = join(fixtureDir, `${fixtureNumber}.expected.txt`);await expect(textContent).toMatchFileSnapshot(expectedFilePath, 'Fixture does not match snapshot');});diff --git a/packages/lecture/vitest.config.ts b/packages/lecture/vitest.config.tsnew file mode 100644index 00000000..94ede10e--- /dev/null+++ b/packages/lecture/vitest.config.ts@@ -0,0 +1,3 @@+import { defineConfig } from 'vitest/config';++export default defineConfig({});diff --git a/packages/webhooks/vitest.config.ts b/packages/webhooks/vitest.config.tsnew file mode 100644index 00000000..94ede10e--- /dev/null+++ b/packages/webhooks/vitest.config.ts@@ -0,0 +1,3 @@+import { defineConfig } from 'vitest/config';++export default defineConfig({});diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 96dc0a43..50283999 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -41,6 +41,9 @@ importers:'@changesets/cli':specifier: ^2.29.3version: 2.29.4+ vitest:+ specifier: 'catalog:'apps/docs:dependencies:@@ -17555,7 +17558,7 @@ snapshots:dependencies:'@types/chai': 5.2.2'@vitest/expect': 3.2.4- '@vitest/mocker': 3.2.4([email protected](@types/[email protected]))+ '@vitest/mocker': 3.2.4([email protected](@types/[email protected]))'@vitest/pretty-format': 3.2.4'@vitest/runner': 3.2.4'@vitest/snapshot': 3.2.4diff --git a/vitest.config.ts b/vitest.config.tsnew file mode 100644index 00000000..68d852b6--- /dev/null+++ b/vitest.config.ts@@ -0,0 +1,12 @@+import { defineConfig } from 'vitest/config'++export default defineConfig({++ test: {+ reporters: ['verbose'],+ projects: ['apps/*', 'packages/*'],+ coverage: {+ include: ['packages/*/src'],+ }+ },+})\ No newline at end of file