From 53e07fd6ff701c95dfeecc6a5003337bb07c5a2a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Wed, 21 Nov 2018 05:55:15 +0000 Subject: [PATCH 1/3] Bump @types/cookie from 0.3.1 to 0.3.2 in /api Bumps [@types/cookie](https://github.com/DefinitelyTyped/DefinitelyTyped) from 0.3.1 to 0.3.2. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits) Signed-off-by: dependabot[bot] --- api/package-lock.json | 6 +++--- api/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/package-lock.json b/api/package-lock.json index 1d78f49e9..ebfa7ad42 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -79,9 +79,9 @@ } }, "@types/cookie": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.1.tgz", - "integrity": "sha512-64Uv+8bTRVZHlbB8eXQgMP9HguxPgnOOIYrQpwHWrtLDrtcG/lILKhUl7bV65NSOIJ9dXGYD7skQFXzhL8tk1A==", + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.2.tgz", + "integrity": "sha512-aHQA072E10/8iUQsPH7mQU/KUyQBZAGzTVRCUvnSz8mSvbrYsP4xEO2RSA0Pjltolzi0j8+8ixrm//Hr4umPzw==", "dev": true }, "@types/cookiejar": { diff --git a/api/package.json b/api/package.json index fb5ba9c71..8ca7e5c55 100644 --- a/api/package.json +++ b/api/package.json @@ -69,7 +69,7 @@ "@types/body-parser": "^1.17.0", "@types/chai": "4.1.7", "@types/chai-http": "3.0.5", - "@types/cookie": "^0.3.1", + "@types/cookie": "^0.3.2", "@types/express": "^4.16.0", "@types/jsonwebtoken": "^8.3.0", "@types/markdown-it": "0.0.7", From 2d17118bff2d31c7c44a4eed2e3689546418caff Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 1 Nov 2018 17:39:03 +0100 Subject: [PATCH 2/3] :construction_worker: Use travis build stages --- .travis.yml | 131 ++++++++++++++++++++----------------- .travis/apidoc-check.sh | 21 ------ .travis/apidoc.sh | 2 +- .travis/build-fe.sh | 28 -------- .travis/license-crawler.js | 49 +++++++------- .travis/license-crawler.sh | 67 +++++-------------- CHANGELOG.md | 1 + api/package-lock.json | 15 +++-- api/package.json | 4 +- 9 files changed, 122 insertions(+), 196 deletions(-) delete mode 100755 .travis/apidoc-check.sh delete mode 100755 .travis/build-fe.sh diff --git a/.travis.yml b/.travis.yml index 1dd36b929..54a9b53db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,67 +34,80 @@ branches: cache: directories: - - "$HOME/.npm" + - "$HOME/.npm" -before_install: - # check for change in changelog - - .travis/changelog.sh +stages: + - test + - name: deploy + if: type = push AND (branch IN (develop, master) OR tag IS present) -before_script: - # required for chrome to start properly - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start - # required for MongoDB to have time to start up - - sleep 15 - -install: - # install api and return back to root for following steps - - cd api - - npm ci - - cd .. - # install frontend and return back to root for following steps - - cd app/webFrontend - - npm ci - - cd ../.. - # install travis dependencies - - cd .travis - - npm ci - - cd .. - -script: - # check for versions - - .travis/check-version.sh - # run license checker and write license.json / dependencies.ts - - .travis/license-crawler.sh - # run backend-tests and return back to root for following steps - - cd api - - sed -i 's/$TRAVIS_COMMIT/'$TRAVIS_COMMIT'/' src/server.ts - - npm run test # run backend test - - cd .. - - .travis/apidoc-check.sh - # run frontend-tests and return back to root for following steps - - cd api - - npm run load:fixtures - - npm start & - - cd ../app/webFrontend - - npm run lint # run linter - # - npm run test-ci || true # run test - many tests are broken - - npm run e2e # run end-to-end-tests - - sed -i 's/$TRAVIS_COMMIT/'$TRAVIS_COMMIT'/' src/app/shared/services/raven-error-handler.service.ts - - cd ../.. -# - travis_wait 30 .travis/build-fe.sh # build in prod mode - - .travis/build-fe.sh # build in prod mode - -after_script: - # send required files to coveralls.io - - .travis/coveralls.sh - -after_success: - - .travis/package-checker.sh - - .travis/apidoc.sh - - .travis/docker.sh - - .travis/deploy.sh - - .travis/sentry.sh +jobs: + include: + - stage: test + name: "Tests Api" + install: + - ${TRAVIS_BUILD_DIR}/.travis/changelog.sh + - cd ${TRAVIS_BUILD_DIR}/.travis + - npm ci + - cd ${TRAVIS_BUILD_DIR}/api + - npm ci + - ${TRAVIS_BUILD_DIR}/.travis/license-crawler.sh + script: + - npm run lint + - npm run test + - npm run apidoc + after_script: + - cd ${TRAVIS_BUILD_DIR} + - .travis/coveralls.sh + - stage: test + name: "Tests Frontend" + before_install: + - export NODE_OPTIONS=--max_old_space_size=4096 + install: + - ${TRAVIS_BUILD_DIR}/.travis/changelog.sh + - cd ${TRAVIS_BUILD_DIR}/.travis + - npm ci + - cd ${TRAVIS_BUILD_DIR}/api + - npm ci + - cd ${TRAVIS_BUILD_DIR}/app/webFrontend + - npm ci + - ${TRAVIS_BUILD_DIR}/.travis/license-crawler.sh + before_script: + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start + script: + - cd ${TRAVIS_BUILD_DIR}/api + - npm run load:fixtures + - npm start & + - cd ${TRAVIS_BUILD_DIR}/app/webFrontend + - npm run lint + - npm run e2e + - npm run build + - stage: deploy + before_install: + - export NODE_OPTIONS=--max_old_space_size=4096 + install: + - cd ${TRAVIS_BUILD_DIR}/.travis + - npm ci + - cd ${TRAVIS_BUILD_DIR}/api + - npm ci + - sed -i 's/$TRAVIS_COMMIT/'$TRAVIS_COMMIT'/' src/server.ts + - cd ${TRAVIS_BUILD_DIR}/app/webFrontend + - npm ci + - sed -i 's/$TRAVIS_COMMIT/'$TRAVIS_COMMIT'/' src/app/shared/services/raven-error-handler.service.ts + - ${TRAVIS_BUILD_DIR}/.travis/license-crawler.sh + script: + - cd ${TRAVIS_BUILD_DIR}/api + - npm run build + - cd ${TRAVIS_BUILD_DIR}/app/webFrontend + - npm run build + after_success: + - cd ${TRAVIS_BUILD_DIR} + - .travis/package-checker.sh + - .travis/docker.sh + - .travis/apidoc.sh + - .travis/deploy.sh + - .travis/sentry.sh # Configure notification notifications: diff --git a/.travis/apidoc-check.sh b/.travis/apidoc-check.sh deleted file mode 100755 index e4b7b551c..000000000 --- a/.travis/apidoc-check.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# Path to this file -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Path the script was called from -IPWD="$(pwd)" -# Import shared vars -. ${DIR}/_shared-vars.sh - - -echo -echo "+++ Check API-Doc +++" -echo - -if ([ "$TRAVIS_PULL_REQUEST" != "false" ] && [ "$TRAVIS_BRANCH" == "develop" ]) || ([ "$TRAVIS_PULL_REQUEST" != "false" ] && [ "$TRAVIS_BRANCH" == "master" ]); then - echo "+ detected pull request from ($TRAVIS_PULL_REQUEST_BRANCH) to $TRAVIS_BRANCH" - cd api - npm run apidoc -else - echo -e "${YELLOW}+ WARNING: No Pull Request agiainst Develop or Master -> skipping automate api doc check${NC}"; -fi diff --git a/.travis/apidoc.sh b/.travis/apidoc.sh index 447586031..5be8f0486 100755 --- a/.travis/apidoc.sh +++ b/.travis/apidoc.sh @@ -7,7 +7,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" . "${DIR}/_shared-vars.sh" echo -echo "+++ Create and publish API-Doc +++" +echo "+++ Create and publish Api-Doc +++" echo if [[ ${TRAVIS_PULL_REQUEST} != false ]]; then diff --git a/.travis/build-fe.sh b/.travis/build-fe.sh deleted file mode 100755 index f29af9824..000000000 --- a/.travis/build-fe.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -# Path to this file -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Path the script was called from -IPWD="$(pwd)" -# Import shared vars -. ${DIR}/_shared-vars.sh -SECONDS=0 - -echo -echo "+++ Check if this is prod-build" -echo - -cd app/webFrontend - -export NODE_OPTIONS=--max_old_space_size=4096 # allow up to 4gb for ng build - -if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then - echo "+++ in PR; do not build sourcemaps" - npm run build-pr -else - echo "+++ is no PR; build with sourcemaps" - npm run build -fi - -echo -echo "+ Needed $SECONDS Seconds" diff --git a/.travis/license-crawler.js b/.travis/license-crawler.js index 16c1e79eb..62de068a1 100644 --- a/.travis/license-crawler.js +++ b/.travis/license-crawler.js @@ -2,15 +2,12 @@ const fs = require('fs'); const nlf = require('nlf'); -const LICENSE_FILE_NAME = 'nlf-licenses'; -const PATH_API = '../api/'; -const PATH_APP_WEB = '../app/webFrontend/'; -const PATH_APP_WEB_FILE_NAME = 'src/app/about/licenses/dependencies.ts'; -const PACKAGE_BLACKLIST = [ - 'geli-api', - 'geli-web-frontend', - 'rxjs-compat' -]; +const API_PATH = '../api/'; +const API_FILE_NAME = 'nlf-licenses'; +const WEB_PATH = '../app/webFrontend/'; +const WEB_FILE_NAME = 'src/app/about/licenses/dependencies.ts'; + +const PACKAGE_BLACKLIST = ['geli-api', 'geli-web-frontend', 'rxjs-compat']; const SEARCH_FOR = '// DEPENDENCY_REPLACE'; console.log('\n+++ Starting license js +++\n'); @@ -18,18 +15,20 @@ console.log('\n+++ Starting license js +++\n'); // API console.log('+ starting api crawl'); nlf.find({ - directory: PATH_API, + directory: API_PATH, production: true, depth: 1 }, (err, data) => { - if (err) throw err; + if (err) { + throw err; + } console.log('+ api: polish json'); let json = JSON.stringify( {data: polishJson(data)} ); fs.writeFile( - PATH_API + LICENSE_FILE_NAME + '.json', + API_PATH + API_FILE_NAME + '.json', json, 'utf8', () => console.log('+ api: wrote json') @@ -39,7 +38,7 @@ nlf.find({ // WEB_APP console.log('+ starting appWeb crawl'); nlf.find({ - directory: PATH_APP_WEB, + directory: WEB_PATH, production: true, depth: 1 }, (err, data) => { @@ -49,7 +48,7 @@ nlf.find({ let out = ''; json.forEach((value, i) => { if (i > 0) { - out += '\n , '; + out += ',\n '; } let sep = '\', \''; @@ -62,19 +61,17 @@ nlf.find({ + ')'; }); - fs.readFile(PATH_APP_WEB + PATH_APP_WEB_FILE_NAME, (err, data) => { - if (err) throw err; - data = data.toString(); - data = data.replace(SEARCH_FOR, out); - - if (process.env.TRAVIS) { - fs.writeFile(PATH_APP_WEB + PATH_APP_WEB_FILE_NAME, data, 'utf8', - () => console.log(('+ appWeb: wrote file')) - ); - } else { - console.warn('+ appWeb: We are not on travis, will only print content:'); - console.log(data); + fs.readFile(WEB_PATH + WEB_FILE_NAME, 'utf8', (err, data) => { + if (err) { + throw err; } + + fs.writeFile( + WEB_PATH + WEB_FILE_NAME, + data.replace(SEARCH_FOR, out), + 'utf8', + () => console.log(('+ appWeb: wrote file')) + ); }) }); diff --git a/.travis/license-crawler.sh b/.travis/license-crawler.sh index 0e67f947f..78fca7a76 100755 --- a/.travis/license-crawler.sh +++ b/.travis/license-crawler.sh @@ -2,67 +2,30 @@ # Path to this file DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Path the script was called from -IPWD="$(pwd)" -# Import shared vars -. ${DIR}/_shared-vars.sh -# Functions -function npm_package_is_installed { - local return_=1 - ls node_modules | grep $1 > /dev/null 2>&1 || { local return_=0; } - echo "$return_" -} +# shellcheck source=_shared-vars.sh +. "${DIR}/_shared-vars.sh" -# Begin of code echo -echo "+++ Run NLF +++" +echo "+++ Run node license finder +++" echo -[ ! "$TRAVIS_PULL_REQUEST" == "false" ] ; IS_PR=$? -( [ "$TRAVIS_BRANCH" == "master" ] || [ "$TRAVIS_BRANCH" == "develop" ] ) ; IS_BRANCH=$? -[ -n "$TRAVIS_TAG" ] ; IS_TAG=$? +if [[ ${TRAVIS_PULL_REQUEST} != false ]]; then + echo -e "${YELLOW}+ Pull Request. Write dummy data.${NC}" -IS_PR=$(if [ "$IS_PR" == "0" ]; then echo -n true; else echo -n false; fi) -IS_BRANCH=$(if [ "$IS_BRANCH" == "0" ]; then echo -n true; else echo -n false; fi) -IS_TAG=$(if [ "$IS_TAG" == "0" ]; then echo -n true; else echo -n false; fi) + echo '{"data":[{"name":"NO-DEP","version":"0.0.1","repository":"https://exmaple.com","license":"MIT","devDependency":false},{"name":"NO-DEP","version":"0.0.1","repository":"https://exmaple.com","license":"MIT","devDependency":true}]}' > "${DIR}/../api/nlf-licenses.json" + sed -i "s#// DEPENDENCY_REPLACE#new Dependency('NO-DEP', '0.0.1', 'https://example.com', 'MIT', false), new Dependency('NO-DEP', '0.0.1', 'https://example.com', 'MIT', true)#" "${DIR}/../app/webFrontend/src/app/about/licenses/dependencies.ts" -echo -e "+ IS_PR => $IS_PR\t($TRAVIS_PULL_REQUEST)" -echo -e "+ IS_BRANCH => $IS_BRANCH\t($TRAVIS_BRANCH)" -echo -e "+ IS_TAG => $IS_TAG\t($TRAVIS_TAG)" -echo - -if ( [ "$IS_BRANCH" == "true" ] && [ "$IS_PR" == "false" ] ) || [ "$IS_TAG" == "true" ]; then - echo "+ checking if nlf is installed" - cd ${DIR} - if [ $(npm_package_is_installed nlf) == 0 ]; then - echo -e "${RED}+ ERROR: nlf is not installed, please add nlf to the .travis/package.json${NC}" - exit 1 - fi - cd ${IPWD} + exit 0; +fi - echo "+ run node" - echo +if [[ ${TRAVIS_BRANCH} == "master" ]] || [[ ${TRAVIS_BRANCH} == "develop" ]] || [[ -n ${TRAVIS_TAG} ]]; then + cd "${DIR}" || exit 0 - cd ${DIR} node license-crawler.js - cd ${IPWD} -else - echo -e "${YELLOW}+ WARNING: Branch not whitelisted OR PullRequest${NC}"; - echo "+ will write dummy data" - echo "{ - \"data\": [ - {\"name\":\"NO-DEP\",\"version\":\"0.0.1\",\"repository\":\"https://exmaple.com\",\"license\":\"MIT\",\"devDependency\":false}, - {\"name\":\"NO-DEP\",\"version\":\"0.0.1\",\"repository\":\"https://exmaple.com\",\"license\":\"MIT\",\"devDependency\":true} - ] -}" > api/nlf-licenses.json - FE_DATA=" -new Dependency('NO-DEP', '0.0.1', 'https://example.com', 'MIT', false), -new Dependency('NO-DEP', '0.0.1', 'https://example.com', 'MIT', true) - " - FE_DATA=`echo $FE_DATA | tr '\n' "\\n"` - sed -i "s!// DEPENDENCY_REPLACE!$FE_DATA!" app/webFrontend/src/app/about/licenses/dependencies.ts + + exit 0 fi -echo -echo "+ finished" +echo -e "${YELLOW}+ Branch not master or develop and no tag. Nothing todo.${NC}" +exit 0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 666132abd..fd00110b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Switched to cookie-based JWT authentication. [#840](https://github.com/geli-lms/geli/issues/840) [#968](https://github.com/geli-lms/geli/issues/968) - Prepare `typescript` 3.1 upgrade. [#967](https://github.com/geli-lms/geli/pull/967) - Use `npm ci` instead `npm install` and cache `$HOME/.npm` instead of `node_modules`. [#972](https://github.com/geli-lms/geli/pull/972) +- Use travis build stages. [#962](https://github.com/geli-lms/geli/issues/962) ### Removed - `@types/winston`. [#945](https://github.com/geli-lms/geli/pull/945) diff --git a/api/package-lock.json b/api/package-lock.json index 28cdb18ee..ebfa7ad42 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -79,9 +79,9 @@ } }, "@types/cookie": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.1.tgz", - "integrity": "sha512-64Uv+8bTRVZHlbB8eXQgMP9HguxPgnOOIYrQpwHWrtLDrtcG/lILKhUl7bV65NSOIJ9dXGYD7skQFXzhL8tk1A==", + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.2.tgz", + "integrity": "sha512-aHQA072E10/8iUQsPH7mQU/KUyQBZAGzTVRCUvnSz8mSvbrYsP4xEO2RSA0Pjltolzi0j8+8ixrm//Hr4umPzw==", "dev": true }, "@types/cookiejar": { @@ -6461,7 +6461,8 @@ "is-extglob": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz", - "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=" + "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=", + "optional": true }, "is-finite": { "version": "1.0.2", @@ -8100,9 +8101,9 @@ } }, "nodemailer": { - "version": "4.6.8", - "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-4.6.8.tgz", - "integrity": "sha512-A3s7EM/426OBIZbLHXq2KkgvmKbn2Xga4m4G+ZUA4IaZvG8PcZXrFh+2E4VaS2o+emhuUVRnzKN2YmpkXQ9qwA==" + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-4.7.0.tgz", + "integrity": "sha512-IludxDypFpYw4xpzKdMAozBSkzKHmNBvGanUREjJItgJ2NYcK/s8+PggVhj7c2yGFQykKsnnmv1+Aqo0ZfjHmw==" }, "nodemailer-markdown": { "version": "1.0.2", diff --git a/api/package.json b/api/package.json index 598fbd497..8ca7e5c55 100644 --- a/api/package.json +++ b/api/package.json @@ -50,7 +50,7 @@ "morgan": "^1.9.1", "multer": "^1.4.1", "node-file-cache": "^1.0.2", - "nodemailer": "^4.6.8", + "nodemailer": "^4.7.0", "nodemailer-markdown": "^1.0.2", "passport": "^0.4.0", "passport-jwt": "^4.0.0", @@ -69,7 +69,7 @@ "@types/body-parser": "^1.17.0", "@types/chai": "4.1.7", "@types/chai-http": "3.0.5", - "@types/cookie": "^0.3.1", + "@types/cookie": "^0.3.2", "@types/express": "^4.16.0", "@types/jsonwebtoken": "^8.3.0", "@types/markdown-it": "0.0.7", From 140bd7c0a587c1088395210c6c28db36489ff300 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Wed, 21 Nov 2018 19:14:11 +0100 Subject: [PATCH 3/3] Add `await` to `localUnit.toHtmlForIndividualPDF()` --- api/src/controllers/DownloadController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/controllers/DownloadController.ts b/api/src/controllers/DownloadController.ts index d162482ea..0e1870659 100644 --- a/api/src/controllers/DownloadController.ts +++ b/api/src/controllers/DownloadController.ts @@ -252,7 +252,7 @@ export class DownloadController { ' .bottomBox {position: absolute; bottom: 0;}' + md_css + ' ' + ' '; - html += localUnit.toHtmlForIndividualPDF(); + html += await localUnit.toHtmlForIndividualPDF(); html += ''; const name = lecCounter + '_' + lcName + '/' + unitCounter + '_' + this.replaceCharInFilename(localUnit.name) + '.pdf'; await this.savePdfToFile(html, options, tempPdfFileName);