diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7603c6fb7c..ab22f255ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -260,9 +260,18 @@ jobs: name: OpenAPI Clients runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install server dependencies + run: npm --prefix=server ci + + - name: Build the app + run: npm --prefix=server run build + - name: Run API generation run: make open-api + - name: Find file changes uses: tj-actions/verify-changed-files@v20 id: verify-changed-files @@ -270,6 +279,8 @@ jobs: files: | mobile/openapi open-api/typescript-sdk + open-api/immich-openapi-specs.json + - name: Verify files have not changed if: steps.verify-changed-files.outputs.files_changed == 'true' run: | @@ -332,7 +343,7 @@ jobs: exit 1 - name: Run SQL generation - run: npm run sql:generate + run: npm run sync:sql env: DB_URL: postgres://postgres:postgres@localhost:5432/immich diff --git a/Makefile b/Makefile index ede70237fe..b7fe03591c 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ open-api-typescript: cd ./open-api && bash ./bin/generate-open-api.sh typescript sql: - npm --prefix server run sql:generate + npm --prefix server run sync:sql attach-server: docker exec -it docker_immich-server_1 sh diff --git a/misc/release/pump-version.sh b/misc/release/pump-version.sh index 14f0b3a817..0d0ae4b9e2 100755 --- a/misc/release/pump-version.sh +++ b/misc/release/pump-version.sh @@ -62,6 +62,8 @@ fi if [ "$CURRENT_SERVER" != "$NEXT_SERVER" ]; then echo "Pumping Server: $CURRENT_SERVER => $NEXT_SERVER" npm --prefix server version "$SERVER_PUMP" + npm --prefix server ci + npm --prefix server run build make open-api npm --prefix open-api/typescript-sdk version "$SERVER_PUMP" npm --prefix web version "$SERVER_PUMP" diff --git a/open-api/bin/generate-open-api.sh b/open-api/bin/generate-open-api.sh index 4eb121102d..a00d57d0ae 100755 --- a/open-api/bin/generate-open-api.sh +++ b/open-api/bin/generate-open-api.sh @@ -24,7 +24,8 @@ function typescript { npm --prefix typescript-sdk ci && npm --prefix typescript-sdk run build } -node ./bin/sync-spec-version.js +# requires server to be built +npm run sync:open-api --prefix=../server if [[ $1 == 'dart' ]]; then dart diff --git a/open-api/bin/sync-spec-version.js b/open-api/bin/sync-spec-version.js deleted file mode 100644 index 98c52413e6..0000000000 --- a/open-api/bin/sync-spec-version.js +++ /dev/null @@ -1,9 +0,0 @@ -const spec = require('../immich-openapi-specs.json'); -const pkg = require('../../server/package.json'); -const path = require('path'); -const fs = require('fs'); -spec.info.version = pkg.version; -fs.writeFileSync( - path.join(__dirname, '../immich-openapi-specs.json'), - JSON.stringify(spec, null, 2) -); diff --git a/server/package.json b/server/package.json index 6265c6d928..e657ca0757 100644 --- a/server/package.json +++ b/server/package.json @@ -30,7 +30,8 @@ "typeorm:migrations:revert": "typeorm migration:revert -d ./dist/database.config.js", "typeorm:schema:drop": "typeorm query -d ./dist/database.config.js 'DROP schema public cascade; CREATE schema public;'", "typeorm:schema:reset": "npm run typeorm:schema:drop && npm run typeorm:migrations:run", - "sql:generate": "node ./dist/utils/sql.js", + "sync:open-api": "node ./dist/bin/sync-open-api.js", + "sync:sql": "node ./dist/bin/sync-sql.js", "email:dev": "email dev -p 3050 --dir src/emails" }, "dependencies": { diff --git a/server/src/bin/sync-open-api.ts b/server/src/bin/sync-open-api.ts new file mode 100644 index 0000000000..70e2bb8c35 --- /dev/null +++ b/server/src/bin/sync-open-api.ts @@ -0,0 +1,23 @@ +#!/usr/bin/env node +process.env.DB_URL = 'postgres://postgres:postgres@localhost:5432/immich'; +import { NestFactory } from '@nestjs/core'; +import { NestExpressApplication } from '@nestjs/platform-express'; +import { ApiModule } from 'src/app.module'; +import { useSwagger } from 'src/utils/misc'; + +const sync = async () => { + const app = await NestFactory.create(ApiModule, { preview: true }); + useSwagger(app, true); + await app.close(); +}; + +sync() + .then(() => { + console.log('Done'); + process.exit(0); + }) + .catch((error) => { + console.error(error); + console.log('Something went wrong'); + process.exit(1); + }); diff --git a/server/src/utils/sql.ts b/server/src/bin/sync-sql.ts similarity index 100% rename from server/src/utils/sql.ts rename to server/src/bin/sync-sql.ts diff --git a/server/src/utils/misc.ts b/server/src/utils/misc.ts index 910bc0962a..f5c0105c03 100644 --- a/server/src/utils/misc.ts +++ b/server/src/utils/misc.ts @@ -174,7 +174,7 @@ const patchOpenAPI = (document: OpenAPIObject) => { return document; }; -export const useSwagger = (app: INestApplication) => { +export const useSwagger = (app: INestApplication, force = false) => { const config = new DocumentBuilder() .setTitle('Immich') .setDescription('Immich API') @@ -211,7 +211,7 @@ export const useSwagger = (app: INestApplication) => { SwaggerModule.setup('doc', app, specification, customOptions); - if (isDev()) { + if (isDev() || force) { // Generate API Documentation only in development mode const outputPath = path.resolve(process.cwd(), '../open-api/immich-openapi-specs.json'); writeFileSync(outputPath, JSON.stringify(patchOpenAPI(specification), null, 2), { encoding: 'utf8' });