From c702fdb4886516e02ec006d2937c8a1aab9b84db Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 23 Nov 2020 16:34:26 +0000 Subject: [PATCH] checkPlugins: Support adaptive npmpublish.yml (#4509) --- bin/plugins/checkPlugin.js | 21 ++++++++++++++++++++- bin/plugins/getCorePlugins.sh | 4 +++- bin/plugins/lib/README.md | 1 + bin/plugins/lib/npmpublish.yml | 21 +++++++++++++++++++-- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/bin/plugins/checkPlugin.js b/bin/plugins/checkPlugin.js index df8e4aef2..17a16675a 100755 --- a/bin/plugins/checkPlugin.js +++ b/bin/plugins/checkPlugin.js @@ -79,10 +79,29 @@ fs.readdir(pluginPath, function (err, rootFiles) { fs.readFileSync('bin/plugins/lib/npmpublish.yml', {encoding: 'utf8', flag: 'r'}); fs.mkdirSync(pluginPath + '/.github/workflows', {recursive: true}); fs.writeFileSync(path, npmpublish); + hasAutoFixed = true; console.log("If you haven't already, setup autopublish for this plugin https://github.com/ether/etherpad-lite/wiki/Plugins:-Automatically-publishing-to-npm-on-commit-to-Github-Repo"); } else { console.log('Setup autopublish for this plugin https://github.com/ether/etherpad-lite/wiki/Plugins:-Automatically-publishing-to-npm-on-commit-to-Github-Repo'); } + }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/npmpublish.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 npmpublish = + fs.readFileSync('bin/plugins/lib/npmpublish.yml', {encoding: 'utf8', flag: 'r'}); + fs.mkdirSync(pluginPath + '/.github/workflows', {recursive: true}); + fs.writeFileSync(path, npmpublish); + hasAutoFixed = true; + } } } catch (err) { console.error(err); @@ -126,7 +145,7 @@ fs.readdir(pluginPath, function (err, rootFiles) { if(autoFix){ let devDependencies = { "eslint": "^7.14.0", - "eslint-config-etherpad": "^1.0.8", + "eslint-config-etherpad": "^1.0.10", "eslint-plugin-mocha": "^8.0.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-prefer-arrow": "^1.2.2", diff --git a/bin/plugins/getCorePlugins.sh b/bin/plugins/getCorePlugins.sh index 60f6cdfce..e8ce68b21 100755 --- a/bin/plugins/getCorePlugins.sh +++ b/bin/plugins/getCorePlugins.sh @@ -1,2 +1,4 @@ cd node_modules/ -GHUSER=ether; curl "https://api.github.com/users/$GHUSER/repos?per_page=1000" | grep -o 'git@[^"]*' | grep /ep_ | xargs -L1 git clone +GHUSER=ether; curl "https://api.github.com/users/$GHUSER/repos?per_page=100" | grep -o 'git@[^"]*' | grep /ep_ | xargs -L1 git clone +GHUSER=ether; curl "https://api.github.com/users/$GHUSER/repos?per_page=100&page=2&" | grep -o 'git@[^"]*' | grep /ep_ | xargs -L1 git clone +GHUSER=ether; curl "https://api.github.com/users/$GHUSER/repos?per_page=100&page=3&" | grep -o 'git@[^"]*' | grep /ep_ | xargs -L1 git clone diff --git a/bin/plugins/lib/README.md b/bin/plugins/lib/README.md index 84ca700a8..3a1e26193 100755 --- a/bin/plugins/lib/README.md +++ b/bin/plugins/lib/README.md @@ -4,6 +4,7 @@ Explain what your plugin does and who it's useful for. ## Example animated gif of usage if appropriate +![screenshot](https://user-images.githubusercontent.com/220864/99979953-97841d80-2d9f-11eb-9782-5f65817c58f4.PNG) ## Installing npm install [plugin_name] diff --git a/bin/plugins/lib/npmpublish.yml b/bin/plugins/lib/npmpublish.yml index 227726279..75e0c62d1 100644 --- a/bin/plugins/lib/npmpublish.yml +++ b/bin/plugins/lib/npmpublish.yml @@ -4,24 +4,38 @@ name: Node.js Package on: + pull_request: push: branches: - main - master jobs: - build: + test: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 + with: + repository: ether/etherpad-lite + path: etherpad-lite + # Work around https://github.com/actions/checkout/issues/197: + - run: mv etherpad-lite .. - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: 12 + - run: cd ../etherpad-lite/src && npm ci - run: npm ci + - run: npm install ep_etherpad-lite@file:../etherpad-lite/src + - run: git diff + - run: ls -la node_modules + - run: ls -la node_modules/ep_etherpad-lite/node_modules - run: npm test + - run: npm run lint publish-npm: - needs: build + if: github.event_name == 'push' + needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -37,3 +51,6 @@ jobs: env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - run: git push --follow-tags + +##ETHERPAD_NPM_V=1 +## NPM configuration automatically created using bin/plugins/updateAllPluginsScript.sh