From 7f44dbd145b148a6ce075efcd9ccd32af2f93b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A5=98=EC=84=A0=EC=9E=84?= Date: Thu, 21 May 2020 20:03:06 +0900 Subject: [PATCH] feat: add config files to log error of example pages (#963) --- .github/workflows/examplePageTest.yml | 31 ++++++++++++++++++ apps/editor/scripts/createConfigVariable.js | 36 +++++++++++++++++++++ apps/editor/tuidoc.config.json | 3 +- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/examplePageTest.yml create mode 100644 apps/editor/scripts/createConfigVariable.js diff --git a/.github/workflows/examplePageTest.yml b/.github/workflows/examplePageTest.yml new file mode 100644 index 0000000000..1675843018 --- /dev/null +++ b/.github/workflows/examplePageTest.yml @@ -0,0 +1,31 @@ +name: detect runtime error + +on: + schedule: + - cron: '0 22 * * *' +jobs: + makeUrl: + runs-on: ubuntu-latest + steps: + - name: checkout repository + uses: actions/checkout@v2 + - name: create config variable + run: | + node apps/editor/scripts/createConfigVariable.js + - name: set global error variable + run: | + errorVariable=`cat ./errorVariable.txt` + echo ::set-env name=ERROR_VARIABLE::$errorVariable + - name: set url + shell: bash + run: | + url=`cat ./url.txt` + echo ::set-env name=URLS::$url + - name: detect runtime error + uses: nhn/toast-ui.detect-runtime-error-actions@master + with: + global-error-log-variable: ${{ env.ERROR_VARIABLE }} + urls: ${{ env.URLS }} + env: + BROWSERSTACK_USERNAME: ${{secrets.BROWSERSTACK_USERNAME}} + BROWSERSTACK_ACCESS_KEY: ${{secrets.BROWSERSTACK_ACCESS_KEY}} diff --git a/apps/editor/scripts/createConfigVariable.js b/apps/editor/scripts/createConfigVariable.js new file mode 100644 index 0000000000..e0e9e5b6ce --- /dev/null +++ b/apps/editor/scripts/createConfigVariable.js @@ -0,0 +1,36 @@ +const fs = require('fs'); +const path = require('path'); +const config = require(path.resolve(process.cwd(), 'tuidoc.config.json')); +const examples = config.examples || {}; +const { filePath, globalErrorLogVariable } = examples; + +/** + * Get Examples Url + */ +function getTestUrls() { + if (!filePath) { + throw Error('not exist examples path at tuidoc.config.json'); + } + + const urlPrefix = 'http://nhn.github.io/tui.editor/latest'; + + const testUrls = fs.readdirSync(filePath).reduce((urls, fileName) => { + if (/html$/.test(fileName)) { + urls.push(`${urlPrefix}/${filePath}/${fileName}`); + } + return urls; + }, []); + + fs.writeFileSync('url.txt', testUrls.join(', ')); +} + +function getGlobalVariable() { + if (!globalErrorLogVariable) { + throw Error('not exist examples path at tuidoc.config.json'); + } + + fs.writeFileSync('errorVariable.txt', globalErrorLogVariable); +} + +getTestUrls(); +getGlobalVariable(); diff --git a/apps/editor/tuidoc.config.json b/apps/editor/tuidoc.config.json index 762823132e..6de89e3751 100644 --- a/apps/editor/tuidoc.config.json +++ b/apps/editor/tuidoc.config.json @@ -55,7 +55,8 @@ "example20-i18n": "20. Internationalization (i18n)", "example21-placeholder": "21. Placeholder", "example22-using-custom-sanitizer": "22. Using Custom HTML Sanitizer" - } + }, + "globalErrorLogVariable": true }, "pathPrefix": "tui.editor" }