Skip to content

Commit

Permalink
feat(ci): separate the swagger validation in own runner plus improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
p-fernandez committed Aug 16, 2023
1 parent 61299b2 commit 5a0018d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 26 deletions.
22 changes: 22 additions & 0 deletions .github/actions/run-api/action.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions .github/actions/validate-swagger/action.yml
Original file line number Diff line number Diff line change
@@ -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)
43 changes: 23 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

11 changes: 5 additions & 6 deletions scripts/print-affected-array.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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';
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';

Expand All @@ -22,7 +22,6 @@ class CliLogs {
}

log(log) {

const cleanLog = log.trim();
if (cleanLog.length) {
this._logs.push(cleanLog);
Expand Down Expand Up @@ -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)
Expand All @@ -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));
}
}
Expand Down
1 change: 1 addition & 0 deletions test-all-contain-task-cache.json
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 5a0018d

Please sign in to comment.