Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): separate the swagger validation in own runner plus improvement #3981

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
50 changes: 29 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ on:

jobs:
dependency-review:
name: Dependency review
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v3

spellcheck: # run the action
spellcheck:
name: Spell check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -203,6 +205,7 @@ jobs:
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
name: Lint and build
with:
targets: lint,build
projects: ${{matrix.projectName}}
Expand All @@ -215,37 +218,19 @@ jobs:
launch_darkly_sdk_key: ${{ secrets.LAUNCH_DARKLY_SDK_KEY }}

- uses: mansagroup/nrwl-nx-action@v3
name: Running the E2E tests
env:
IN_MEMORY_CLUSTER_MODE_ENABLED: true
LAUNCH_DARKLY_SDK_KEY: ${{ secrets.LAUNCH_DARKLY_SDK_KEY }}
with:
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 @@ -265,6 +250,29 @@ jobs:
slim: ${{ !contains(matrix.projectName, '@novu/api') && !contains(matrix.projectName, '@novu/worker') && !contains(matrix.projectName, '@novu/ws') }}
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
name: Lint and build and test
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] }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would expect to validate the Swagger when something affecting the unit tests for the API change.

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

10 changes: 4 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,7 +134,7 @@ 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']);

let projects =
BASE_BRANCH_NAME === ALL_FLAG
Expand All @@ -157,14 +156,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