From d1e9ea6e27f2ce05dbbf978b0deb5b737b051648 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 30 Nov 2020 17:22:52 +0000 Subject: [PATCH] tests/plugins: checkPlugins backend tests config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tnx to @webzwo0i 👍 --- bin/plugins/checkPlugin.js | 35 +++++++++++++++++++++ bin/plugins/lib/backend-tests.yml | 51 +++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 bin/plugins/lib/backend-tests.yml diff --git a/bin/plugins/checkPlugin.js b/bin/plugins/checkPlugin.js index 523fe11c5..286c762c9 100755 --- a/bin/plugins/checkPlugin.js +++ b/bin/plugins/checkPlugin.js @@ -107,6 +107,41 @@ fs.readdir(pluginPath, (err, rootFiles) => { console.error(err); } + + try { + const path = `${pluginPath}/.github/workflows/backend-tests.yml`; + if (!fs.existsSync(path)) { + console.log('no .github/workflows/backend-tests.yml, create one and set npm secret to auto publish to npm on commit'); + if (autoFix) { + const backendTests = + fs.readFileSync('bin/plugins/lib/backend-tests.yml', {encoding: 'utf8', flag: 'r'}); + fs.mkdirSync(`${pluginPath}/.github/workflows`, {recursive: true}); + fs.writeFileSync(path, backendTests); + hasAutoFixed = true; + } + } else { + // autopublish exists, we should check the version.. + // checkVersion takes two file paths and checks for a version string in them. + const currVersionFile = fs.readFileSync(path, {encoding: 'utf8', flag: 'r'}); + const existingConfigLocation = currVersionFile.indexOf('##ETHERPAD_NPM_V='); + const existingValue = parseInt(currVersionFile.substr(existingConfigLocation + 17, existingConfigLocation.length)); + + const reqVersionFile = fs.readFileSync('bin/plugins/lib/backend-tests.yml', {encoding: 'utf8', flag: 'r'}); + const reqConfigLocation = reqVersionFile.indexOf('##ETHERPAD_NPM_V='); + const reqValue = parseInt(reqVersionFile.substr(reqConfigLocation + 17, reqConfigLocation.length)); + + if (!existingValue || (reqValue > existingValue)) { + const backendTests = + fs.readFileSync('bin/plugins/lib/backend-tests.yml', {encoding: 'utf8', flag: 'r'}); + fs.mkdirSync(`${pluginPath}/.github/workflows`, {recursive: true}); + fs.writeFileSync(path, backendTests); + hasAutoFixed = true; + } + } + } catch (err) { + console.error(err); + } + if (files.indexOf('package.json') === -1) { console.warn('no package.json, please create'); } diff --git a/bin/plugins/lib/backend-tests.yml b/bin/plugins/lib/backend-tests.yml new file mode 100644 index 000000000..324cc4baf --- /dev/null +++ b/bin/plugins/lib/backend-tests.yml @@ -0,0 +1,51 @@ +# You need to change lines 38 and 46 in case the plugin's name on npmjs.com is different +# from the repository name + +name: "Backend tests" + +# any branch is useful for testing before a PR is submitted +on: [push, pull_request] + +jobs: + withplugins: + # run on pushes to any branch + # run on PRs from external forks + if: | + (github.event_name != 'pull_request') + || (github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id) + name: with Plugins + runs-on: ubuntu-latest + + steps: + - name: Install libreoffice + run: | + sudo add-apt-repository -y ppa:libreoffice/ppa + sudo apt update + sudo apt install -y --no-install-recommends libreoffice libreoffice-pdfimport + + # clone etherpad-lite + - name: Install etherpad core + uses: actions/checkout@v2 + with: + repository: ether/etherpad-lite + + - name: Install all dependencies and symlink for ep_etherpad-lite + run: bin/installDeps.sh + + # clone this repository into node_modules/ep_plugin-name + - name: Checkout plugin repository + uses: actions/checkout@v2 + with: + path: ./node_modules/${{github.event.repository.name}} + + - name: Install plugin dependencies + run: | + cd node_modules/${{github.event.repository.name}} + npm ci + + # configures some settings and runs npm run test + - name: Run the backend tests + run: tests/frontend/travis/runnerBackend.sh + +##ETHERPAD_NPM_V=1 +## NPM configuration automatically created using bin/plugins/updateAllPluginsScript.sh