diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 80b7482d9..f0d38b75b 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -30,10 +30,13 @@ admin: &admin - 'admin/**/*' +backend: &backend + - 'backend/**/*' + dht_node: &dht_node - 'dht-node/**/*' -docker: &docker +docker-compose: &docker-compose - 'docker-compose.*' federation: &federation @@ -42,5 +45,8 @@ federation: &federation frontend: &frontend - 'frontend/**/*' +mariadb: &mariadb + - 'mariadb/**/*' + nginx: &nginx - 'nginx/**/*' \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 0fcedb4ce..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,195 +0,0 @@ -name: gradido test CI - -on: push - -jobs: - ############################################################################## - # JOB: DOCKER BUILD TEST BACKEND ############################################# - ############################################################################## - build_test_backend: - name: Docker Build Test - Backend - runs-on: ubuntu-latest - #needs: [nothing] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # BACKEND ################################################################ - ########################################################################## - - name: Backend | Build `test` image - run: | - docker build -f ./backend/Dockerfile --target test -t "gradido/backend:test" . - docker save "gradido/backend:test" > /tmp/backend.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: docker-backend-test - path: /tmp/backend.tar - - ############################################################################## - # JOB: DOCKER BUILD TEST DATABASE UP ######################################### - ############################################################################## - build_test_database_up: - name: Docker Build Test - Database up - runs-on: ubuntu-latest - #needs: [nothing] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # DATABASE UP ############################################################ - ########################################################################## - - name: Database | Build `test_up` image - run: | - docker build --target test_up -t "gradido/database:test_up" database/ - docker save "gradido/database:test_up" > /tmp/database_up.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: docker-database-test_up - path: /tmp/database_up.tar - - ############################################################################## - # JOB: DOCKER BUILD TEST MARIADB ############################################# - ############################################################################## - build_test_mariadb: - name: Docker Build Test - MariaDB - runs-on: ubuntu-latest - #needs: [nothing] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # BUILD MARIADB DOCKER IMAGE ############################################# - ########################################################################## - - name: mariadb | Build `test` image - run: | - docker build --target mariadb_server -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./ - docker save "gradido/mariadb:test" > /tmp/mariadb.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: docker-mariadb-test - path: /tmp/mariadb.tar - - ############################################################################## - # JOB: LINT BACKEND ########################################################## - ############################################################################## - lint_backend: - name: Lint - Backend - runs-on: ubuntu-latest - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # LINT BACKEND ########################################################### - ########################################################################## - - name: backend | Lint - run: cd database && yarn && cd ../backend && yarn && yarn run lint - - ############################################################################## - # JOB: LOCALES BACKEND ####################################################### - ############################################################################## - locales_backend: - name: Locales - Backend - runs-on: ubuntu-latest - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # LOCALES BACKEND ##################################################### - ########################################################################## - - name: Backend | Locales - run: cd backend && yarn && yarn locales - - ############################################################################## - # JOB: LINT DATABASE UP ###################################################### - ############################################################################## - lint_database_up: - name: Lint - Database Up - runs-on: ubuntu-latest - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # LINT DATABASE ########################################################## - ########################################################################## - - name: Database | Lint - run: cd database && yarn && yarn run lint - - ############################################################################## - # JOB: UNIT TEST BACKEND #################################################### - ############################################################################## - unit_test_backend: - name: Unit tests - Backend - runs-on: ubuntu-latest - needs: [build_test_mariadb] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # DOWNLOAD DOCKER IMAGES ################################################# - ########################################################################## - - name: Download Docker Image (Mariadb) - uses: actions/download-artifact@v3 - with: - name: docker-mariadb-test - path: /tmp - - name: Load Docker Image - run: docker load < /tmp/mariadb.tar - ########################################################################## - # UNIT TESTS BACKEND ##################################################### - ########################################################################## - - name: backend | docker-compose mariadb - run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb - - name: Sleep for 30 seconds - run: sleep 30s - shell: bash - - name: backend | docker-compose database - run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps database - - name: backend Unit tests | test - run: cd database && yarn && yarn build && cd ../backend && yarn && yarn test - - ########################################################################## - # DATABASE MIGRATION TEST UP + RESET ##################################### - ########################################################################## - database_migration_test: - name: Database Migration Test - Up + Reset - runs-on: ubuntu-latest - #needs: [nothing] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # DOCKER COMPOSE DATABASE UP + RESET ##################################### - ########################################################################## - - name: database | docker-compose - run: docker-compose -f docker-compose.yml up --detach mariadb - - name: database | up - run: docker-compose -f docker-compose.yml run -T database yarn up - - name: database | reset - run: docker-compose -f docker-compose.yml run -T database yarn reset diff --git a/.github/workflows/test-admin-interface.yml b/.github/workflows/test_admin_interface.yml similarity index 100% rename from .github/workflows/test-admin-interface.yml rename to .github/workflows/test_admin_interface.yml diff --git a/.github/workflows/test_backend.yml b/.github/workflows/test_backend.yml new file mode 100644 index 000000000..b517c5186 --- /dev/null +++ b/.github/workflows/test_backend.yml @@ -0,0 +1,81 @@ +name: Gradido Backend Test CI + +on: push + +jobs: + files-changed: + name: Detect File Changes - Backend + runs-on: ubuntu-latest + outputs: + backend: ${{ steps.changes.outputs.backend }} + database: ${{ steps.changes.outputs.database }} + docker-compose: ${{ steps.changes.outputs.docker-compose }} + mariadb: ${{ steps.changes.outputs.mariadb }} + steps: + - uses: actions/checkout@v3.3.0 + + - name: Check for frontend file changes + uses: dorny/paths-filter@v2.11.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + + build_test: + if: needs.files-changed.outputs.backend == 'true' + name: Docker Build Test - Backend + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Backend | Build 'test' image + run: docker build -f ./backend/Dockerfile --target test -t "gradido/backend:test" . + + unit_test: + if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.database == 'true' || needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.mariadb == 'true' + name: Unit tests - Backend + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Backend | docker-compose mariadb + run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb + + - name: Sleep for 30 seconds + run: sleep 30s + shell: bash + + - name: Backend | docker-compose database + run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps database + + - name: Backend | Unit tests + run: cd database && yarn && yarn build && cd ../backend && yarn && yarn test + + lint: + if: needs.files-changed.outputs.backend == 'true' + name: Lint - Backend + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Backend | Lint + run: cd database && yarn && cd ../backend && yarn && yarn run lint + + locales: + if: needs.files-changed.outputs.backend == 'true' + name: Locales - Backend + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Backend | Locales + run: cd backend && yarn && yarn locales \ No newline at end of file diff --git a/.github/workflows/test_database.yml b/.github/workflows/test_database.yml new file mode 100644 index 000000000..0444a0538 --- /dev/null +++ b/.github/workflows/test_database.yml @@ -0,0 +1,64 @@ +name: Gradido Database Test CI + +on: push + +jobs: + files-changed: + name: Detect File Changes - Database + runs-on: ubuntu-latest + outputs: + database: ${{ steps.changes.outputs.database }} + docker-compose: ${{ steps.changes.outputs.docker-compose }} + mariadb: ${{ steps.changes.outputs.mariadb }} + steps: + - uses: actions/checkout@v3.3.0 + + - name: Check for frontend file changes + uses: dorny/paths-filter@v2.11.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + + build: + if: needs.files-changed.outputs.database == 'true' + name: Docker Build Test - Database up + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Database | Build 'test_up' image + run: docker build --target test_up -t "gradido/database:test_up" database/ + + database_migration_test: + if: needs.files-changed.outputs.database == 'true' || needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.mariadb == 'true' + name: Database Migration Test - Up + Reset + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Database | docker-compose + run: docker-compose -f docker-compose.yml up --detach mariadb + + - name: Database | up + run: docker-compose -f docker-compose.yml run -T database yarn up + + - name: Database | reset + run: docker-compose -f docker-compose.yml run -T database yarn reset + + lint: + if: needs.files-changed.outputs.database == 'true' + name: Lint - Database Up + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Database | Lint + run: cd database && yarn && yarn run lint \ No newline at end of file diff --git a/.github/workflows/test_dht-node.yml b/.github/workflows/test_dht_node.yml similarity index 68% rename from .github/workflows/test_dht-node.yml rename to .github/workflows/test_dht_node.yml index a57f09399..b63d1fc0d 100644 --- a/.github/workflows/test_dht-node.yml +++ b/.github/workflows/test_dht_node.yml @@ -3,14 +3,13 @@ name: Gradido DHT Node Test CI on: push jobs: - # only (but most important) job from this workflow required for pull requests - # check results serve as run conditions for all other jobs here files-changed: name: Detect File Changes - DHT Node runs-on: ubuntu-latest outputs: + database: ${{ steps.changes.outputs.database }} dht_node: ${{ steps.changes.outputs.dht_node }} - docker: ${{ steps.changes.outputs.docker }} + docker-compose: ${{ steps.changes.outputs.docker-compose }} steps: - uses: actions/checkout@v3.3.0 @@ -22,12 +21,9 @@ jobs: filters: .github/file-filters.yml list-files: shell - ############################################################################## - # JOB: DOCKER BUILD TEST ##################################################### - ############################################################################## build: name: Docker Build Test - DHT Node - if: needs.files-changed.outputs.dht_node == 'true' || needs.files-changed.outputs.docker == 'true' + if: needs.files-changed.outputs.dht_node == 'true' needs: files-changed runs-on: ubuntu-latest steps: @@ -45,9 +41,6 @@ jobs: name: docker-dht-node-test path: /tmp/dht-node.tar - ############################################################################## - # JOB: LINT ################################################################## - ############################################################################## lint: name: Lint - DHT Node if: needs.files-changed.outputs.dht_node == 'true' @@ -60,12 +53,9 @@ jobs: - name: Lint run: cd dht-node && yarn && yarn run lint - ############################################################################## - # JOB: UNIT TEST ############################################################# - ############################################################################## unit_test: name: Unit Tests - DHT Node - if: needs.files-changed.outputs.dht_node == 'true' || needs.files-changed.outputs.docker == 'true' + if: needs.files-changed.outputs.database == 'true' || needs.files-changed.outputs.dht_node == 'true' || needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.mariadb == 'true' needs: [files-changed, build] runs-on: ubuntu-latest steps: diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/test_e2e.yml similarity index 100% rename from .github/workflows/e2e-test.yml rename to .github/workflows/test_e2e.yml diff --git a/.github/workflows/test_federation.yml b/.github/workflows/test_federation.yml index fc29a1bf8..92ccd95d2 100644 --- a/.github/workflows/test_federation.yml +++ b/.github/workflows/test_federation.yml @@ -3,13 +3,11 @@ name: Gradido Federation Test CI on: push jobs: - # only (but most important) job from this workflow required for pull requests - # check results serve as run conditions for all other jobs here files-changed: name: Detect File Changes - Federation runs-on: ubuntu-latest outputs: - docker: ${{ steps.changes.outputs.docker }} + docker-compose: ${{ steps.changes.outputs.docker-compose }} federation: ${{ steps.changes.outputs.federation }} steps: - uses: actions/checkout@v3.3.0 @@ -22,12 +20,9 @@ jobs: filters: .github/file-filters.yml list-files: shell - ############################################################################## - # JOB: DOCKER BUILD TEST ##################################################### - ############################################################################## build: name: Docker Build Test - Federation - if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.federation == 'true' + if: needs.files-changed.outputs.federation == 'true' needs: files-changed runs-on: ubuntu-latest steps: @@ -45,9 +40,6 @@ jobs: name: docker-federation-test path: /tmp/federation.tar - ############################################################################## - # JOB: LINT ################################################################## - ############################################################################## lint: name: Lint - Federation if: needs.files-changed.outputs.federation == 'true' @@ -60,12 +52,9 @@ jobs: - name: Lint run: cd federation && yarn && yarn run lint - ############################################################################## - # JOB: UNIT TEST ############################################################# - ############################################################################## unit_test: name: Unit Tests - Federation - if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.federation == 'true' + if: needs.files-changed.outputs.database == 'true' || needs.files-changed.outputs.docker-compose == 'true' || needs.files-changed.outputs.federation == 'true' || needs.files-changed.outputs.mariadb == 'true' needs: [files-changed, build] runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test_mariadb.yml b/.github/workflows/test_mariadb.yml new file mode 100644 index 000000000..fe101bc48 --- /dev/null +++ b/.github/workflows/test_mariadb.yml @@ -0,0 +1,32 @@ +name: Gradido MariaDB Test CI + +on: push + +jobs: + files-changed: + name: Detect File Changes - MariaDB + runs-on: ubuntu-latest + outputs: + mariadb: ${{ steps.changes.outputs.mariadb }} + steps: + - uses: actions/checkout@v3.3.0 + + - name: Check for frontend file changes + uses: dorny/paths-filter@v2.11.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + + build_test: + if: needs.files-changed.outputs.mariadb == 'true' + name: Docker Build Test - MariaDB + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: MariaDB | Build 'test' image + run: docker build --target mariadb_server -t "gradido/mariadb:test" -f ./mariadb/Dockerfile ./ diff --git a/.github/workflows/test-nginx.yml b/.github/workflows/test_nginx.yml similarity index 100% rename from .github/workflows/test-nginx.yml rename to .github/workflows/test_nginx.yml diff --git a/backend/.eslintrc.js b/backend/.eslintrc.js index 4c53a638f..0e63a9bfe 100644 --- a/backend/.eslintrc.js +++ b/backend/.eslintrc.js @@ -5,7 +5,7 @@ module.exports = { node: true, }, parser: '@typescript-eslint/parser', - plugins: ['prettier', '@typescript-eslint', 'type-graphql', 'jest', 'import', 'n'], + plugins: ['prettier', '@typescript-eslint', 'type-graphql', 'jest', 'import', 'n', 'promise'], extends: [ 'standard', 'eslint:recommended', @@ -142,6 +142,21 @@ module.exports = { 'n/prefer-global/url-search-params': 'error', 'n/prefer-promises/dns': 'error', 'n/prefer-promises/fs': 'error', + // promise + 'promise/catch-or-return': 'error', + 'promise/no-return-wrap': 'error', + 'promise/param-names': 'error', + 'promise/always-return': 'error', + 'promise/no-native': 'off', + 'promise/no-nesting': 'warn', + 'promise/no-promise-in-callback': 'warn', + 'promise/no-callback-in-promise': 'warn', + 'promise/avoid-new': 'warn', + 'promise/no-new-statics': 'error', + 'promise/no-return-in-finally': 'warn', + 'promise/valid-params': 'warn', + 'promise/prefer-await-to-callbacks': 'error', + 'promise/no-multiple-resolved': 'error', }, overrides: [ // only for ts files diff --git a/backend/log4js-config.json b/backend/log4js-config.json index e595e7c52..160883eb3 100644 --- a/backend/log4js-config.json +++ b/backend/log4js-config.json @@ -8,7 +8,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -21,7 +21,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -34,7 +34,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -47,7 +47,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -60,7 +60,7 @@ "pattern": "yyyy-MM-dd", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m %s" }, "keepFileExt" : true, "fileNameSep" : "_", @@ -77,7 +77,7 @@ "type": "stdout", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" } }, "apolloOut": @@ -85,7 +85,7 @@ "type": "stdout", "layout": { - "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" + "type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{user}] [%f : %l] - %m" } } }, diff --git a/backend/src/apis/HttpRequest.ts b/backend/src/apis/HttpRequest.ts index 063dfa202..f40d577bd 100644 --- a/backend/src/apis/HttpRequest.ts +++ b/backend/src/apis/HttpRequest.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ @@ -9,39 +10,35 @@ import { backendLogger as logger } from '@/server/logger' // eslint-disable-next-line @typescript-eslint/no-explicit-any export const apiPost = async (url: string, payload: unknown): Promise => { logger.trace('POST', url, payload) - return axios - .post(url, payload) - .then((result) => { - logger.trace('POST-Response', result) - if (result.status !== 200) { - throw new LogError('HTTP Status Error', result.status) - } - if (result.data.state !== 'success') { - throw new Error(result.data.msg) - } - return { success: true, data: result.data } - }) - .catch((error) => { - return { success: false, data: error.message } - }) + try { + const result = await axios.post(url, payload) + logger.trace('POST-Response', result) + if (result.status !== 200) { + throw new LogError('HTTP Status Error', result.status) + } + if (result.data.state !== 'success') { + throw new LogError(result.data.msg) + } + return { success: true, data: result.data } + } catch (error: any) { + return { success: false, data: error.message } + } } // eslint-disable-next-line @typescript-eslint/no-explicit-any export const apiGet = async (url: string): Promise => { logger.trace('GET: url=' + url) - return axios - .get(url) - .then((result) => { - logger.trace('GET-Response', result) - if (result.status !== 200) { - throw new LogError('HTTP Status Error', result.status) - } - if (!['success', 'warning'].includes(result.data.state)) { - throw new Error(result.data.msg) - } - return { success: true, data: result.data } - }) - .catch((error) => { - return { success: false, data: error.message } - }) + try { + const result = await axios.get(url) + logger.trace('GET-Response', result) + if (result.status !== 200) { + throw new LogError('HTTP Status Error', result.status) + } + if (!['success', 'warning'].includes(result.data.state)) { + throw new LogError(result.data.msg) + } + return { success: true, data: result.data } + } catch (error: any) { + return { success: false, data: error.message } + } } diff --git a/mariadb/Dockerfile b/mariadb/Dockerfile index 07d2ba368..d3d5937d0 100644 --- a/mariadb/Dockerfile +++ b/mariadb/Dockerfile @@ -2,8 +2,3 @@ # mariadb server ######################################################################################################### FROM mariadb/server:10.5 as mariadb_server - -# ENV DOCKER_WORKDIR="/docker-entrypoint-initdb.d" - -# RUN mkdir -p ${DOCKER_WORKDIR} -# WORKDIR ${DOCKER_WORKDIR}