From 5a0018daf983b64fbb020cc2d27257f8d5b0473a Mon Sep 17 00:00:00 2001 From: p-fernandez Date: Wed, 16 Aug 2023 10:55:51 +0100 Subject: [PATCH] feat(ci): separate the swagger validation in own runner plus improvement --- .github/actions/run-api/action.yml | 22 +++++++++++ .github/actions/validate-swagger/action.yml | 17 ++++++++ .github/workflows/test.yml | 43 +++++++++++---------- scripts/print-affected-array.mjs | 11 +++--- test-all-contain-task-cache.json | 1 + 5 files changed, 68 insertions(+), 26 deletions(-) create mode 100644 .github/actions/run-api/action.yml create mode 100644 .github/actions/validate-swagger/action.yml create mode 100644 test-all-contain-task-cache.json diff --git a/.github/actions/run-api/action.yml b/.github/actions/run-api/action.yml new file mode 100644 index 000000000000..1b69da6fa8a8 --- /dev/null +++ b/.github/actions/run-api/action.yml @@ -0,0 +1,22 @@ +name: Run API + +description: Starts and waits for an API running instance + +inputs: + launch_darkly_sdk_key: + description: 'The Launch Darkly SDK key to use' + required: false + default: '' + +runs: + using: composite + + steps: + - name: Start API + env: + IS_IN_MEMORY_CLUSTER_MODE_ENABLED: true + LAUNCH_DARKLY_SDK_KEY: ${{ inputs.launch_darkly_sdk_key }} + run: cd apps/api && pnpm start:test & + + - name: Wait on API + run: wait-on --timeout=180000 http://localhost:1336/v1/health-check diff --git a/.github/actions/validate-swagger/action.yml b/.github/actions/validate-swagger/action.yml new file mode 100644 index 000000000000..f5f3671a1a67 --- /dev/null +++ b/.github/actions/validate-swagger/action.yml @@ -0,0 +1,17 @@ +name: Validate Swagger + +description: Validates the swagger from the API + +runs: + using: composite + + steps: + - name: Get swagger json as file + run: | + curl -o swagger.json http://localhost:1336/api-json + - uses: char0n/swagger-editor-validate@v1 + with: + definition-file: swagger.json + + - name: Kill port for api 1336 for unit tests + run: sudo kill -9 $(sudo lsof -t -i:1336) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fb34d39f75af..b9dd4145f783 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -222,30 +222,11 @@ jobs: targets: test:e2e projects: ${{matrix.projectName}} - - name: Start Api - env: - IN_MEMORY_CLUSTER_MODE_ENABLED: true - run: cd apps/api && pnpm start:test & - - - name: Wait on Api - run: wait-on --timeout=180000 http://localhost:1336/v1/health-check - - - name: Get swagger json as file - run: | - curl -o swagger.json http://localhost:1336/api-json - - - uses: char0n/swagger-editor-validate@v1 - with: - definition-file: swagger.json - - - name: Kill port for api 1336 for unit tests - run: sudo kill -9 $(sudo lsof -t -i:1336) - test_unit: name: Unit Test runs-on: ubuntu-latest needs: [get-affected] - if: ${{ fromJson(needs.get-affected.outputs.test-unit)[0] }} + if: ${{ fromJson(needs.get-affected.outputs.test-unit)[0] }} timeout-minutes: 80 strategy: # One job for each different project and node version @@ -268,3 +249,25 @@ jobs: with: targets: lint,build,test projects: ${{matrix.projectName}} + + validate_swagger: + name: Validate Swagger + runs-on: ubuntu-latest + needs: [get-affected] + if: ${{ fromJson(needs.get-affected.outputs.test-unit)[0] }} + timeout-minutes: 10 + permissions: + contents: read + packages: write + deployments: write + id-token: write + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/setup-project + - uses: ./.github/actions/setup-redis-cluster + - uses: ./.github/actions/run-api + with: + launch_darkly_sdk_key: ${{ secrets.LAUNCH_DARKLY_SDK_KEY }} + + - uses: ./.github/actions/validate-swagger + diff --git a/scripts/print-affected-array.mjs b/scripts/print-affected-array.mjs index ba296176067c..be33fc95b89b 100644 --- a/scripts/print-affected-array.mjs +++ b/scripts/print-affected-array.mjs @@ -3,7 +3,7 @@ import spawn from 'cross-spawn'; import { fileURLToPath } from 'url'; import path from 'path'; import * as fs from 'fs'; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const dirname = path.dirname(fileURLToPath(import.meta.url)); const processArguments = process.argv.slice(2); const ALL_FLAG = '--all'; @@ -11,7 +11,7 @@ const TASK_NAME = processArguments[0]; const BASE_BRANCH_NAME = processArguments[1]; const GROUP = processArguments[2]; -const ROOT_PATH = path.resolve(__dirname, '..'); +const ROOT_PATH = path.resolve(dirname, '..'); const ENCODING_TYPE = 'utf8'; const NEW_LINE_CHAR = '\n'; @@ -22,7 +22,6 @@ class CliLogs { } log(log) { - const cleanLog = log.trim(); if (cleanLog.length) { this._logs.push(cleanLog); @@ -135,8 +134,9 @@ async function allProjectsContainingTask(taskName) { } async function printAffectedProjectsContainingTask() { - const { providers, packages , libs } = await getPackageFolders(['providers', 'packages', 'libs']); + const { providers, packages, libs } = await getPackageFolders(['providers', 'packages', 'libs']); + console.log(BASE_BRANCH_NAME, ALL_FLAG); let projects = BASE_BRANCH_NAME === ALL_FLAG ? await allProjectsContainingTask(TASK_NAME) @@ -157,14 +157,13 @@ async function printAffectedProjectsContainingTask() { projects = projects.filter((project) => !libs.includes(project)); } - if (GROUP === 'providers') { console.log(JSON.stringify(foundProviders)); } else if (GROUP === 'packages') { console.log(JSON.stringify(foundPackages)); } else if (GROUP === 'libs') { console.log(JSON.stringify(foundLibs)); - } else { + } else { console.log(JSON.stringify(projects)); } } diff --git a/test-all-contain-task-cache.json b/test-all-contain-task-cache.json new file mode 100644 index 000000000000..117bc3bcaf21 --- /dev/null +++ b/test-all-contain-task-cache.json @@ -0,0 +1 @@ +["@novu/docs","@novu/notification-center-angular","@novu/firetext","@novu/inbound-mail","@novu/webhook","@novu/worker","@novu/api","@novu/ws","@novu/headless","@novu/gupshup","@novu/termii","@novu/sms77","@novu/notification-center","@novu/notification-center-vue","@novu/embed","@novu/africas-talking","@novu/forty-six-elks","@novu/push-webhook","@novu/sms-central","@novu/clickatell","@novu/mailersend","@novu/mattermost","@novu/nodemailer","@novu/one-signal","@novu/outlook365","@novu/sendinblue","@novu/burst-sms","@novu/sparkpost","@novu/mandrill","@novu/ms-teams","@novu/postmark","@novu/sendgrid","@novu/discord","@novu/emailjs","@novu/infobip","@novu/mailgun","@novu/mailjet","@novu/netcore","@novu/kannel","@novu/maqsam","@novu/resend","@novu/telnyx","@novu/twilio","@novu/client","@novu/nexmo","@novu/plivo","@novu/slack","@novu/apns","@novu/expo","@novu/nest","@novu/node","@novu/testing","@novu/fcm","@novu/ses","@novu/sns","@novu/email-webhook","@novu/sendchamp","@novu/plunk","@novu/stateless","@novu/dal","@novu/shared"] \ No newline at end of file