From 9631a43b8c68992b3360470606fb1d0c55eb330e Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Sun, 5 Jun 2022 23:54:14 -0700 Subject: [PATCH] Release v1.0.5 (#25) - ci: replace appveyor & travis with GitHub actions - ci: add GHA shared workflows - lint: prefer-template - test: replace nodeunit with mocha --- .codeclimate.yml | 5 +- .github/dependabot.yml | 10 ++ .github/workflows/ci.yml | 41 +++++++ .github/workflows/codeql.yml | 13 +++ .github/workflows/publish.yml | 14 +++ .gitignore | 3 + .gitmodules | 3 + .release | 1 + .travis.yml | 29 ----- Changes.md | 28 ++++- README.md | 8 +- appveyor.yml | 20 ---- index.js | 6 +- package.json | 17 ++- run_tests | 33 ------ test/syslog.js | 206 ++++++++++++++++------------------ 16 files changed, 223 insertions(+), 214 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .gitmodules create mode 160000 .release delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100755 run_tests diff --git a/.codeclimate.yml b/.codeclimate.yml index 6830f73..a27da1d 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -7,9 +7,9 @@ engines: - javascript eslint: enabled: true - channel: "eslint-3" + channel: "eslint-8" config: - config: ".eslintrc.json" + config: ".eslintrc.yaml" fixme: enabled: true checks: @@ -17,6 +17,7 @@ engines: enabled: false TODO: enabled: false + ratings: paths: - "**.js" diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0449e4a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "weekly" + allow: + - dependency-type: production diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3eae1ac --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: [ push ] + +env: + CI: true + +jobs: + + lint: + uses: haraka/.github/.github/workflows/lint.yml@master + + # coverage: + # uses: haraka/.github/.github/workflows/coverage.yml@master + # secrets: inherit + + test: + needs: [ lint, get-lts ] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest ] + node-version: ${{ fromJson(needs.get-lts.outputs.active) }} + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + name: Node ${{ matrix.node-version }} on ${{ matrix.os }} + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test + + get-lts: + runs-on: ubuntu-latest + steps: + - id: get + uses: msimerson/node-lts-versions@v1 + outputs: + active: ${{ steps.get.outputs.active }} + lts: ${{ steps.get.outputs.lts }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..383aca2 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,13 @@ +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + schedule: + - cron: '18 7 * * 4' + +jobs: + codeql: + uses: haraka/.github/.github/workflows/codeql.yml@master diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..42a9bb9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,14 @@ +name: publish + +on: + push: + branches: + - master + +env: + CI: true + +jobs: + publish: + uses: haraka/.github/.github/workflows/publish.yml@master + secrets: inherit \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5148e52..ed4df71 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ jspm_packages # Optional REPL history .node_repl_history + +haraka-update.sh +package-lock.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a8e94cb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule ".release"] + path = .release + url = git@github.com:msimerson/.release.git diff --git a/.release b/.release new file mode 160000 index 0000000..9be2b27 --- /dev/null +++ b/.release @@ -0,0 +1 @@ +Subproject commit 9be2b270ef836bcfefda085674bf62e2a91defe8 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e93650c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: node_js -node_js: - - "8" - - "10" - - "12" - -# these are required for building on node.js v4 -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.8 -env: - - "CXX=g++-4.8" -# end: these are required for building on node.js v4 - -before_script: - -script: - - npm run lint - - npm test - -after_success: -# - npm install istanbul codecov -# - npm run cover -# - ./node_modules/.bin/codecov - -sudo: false diff --git a/Changes.md b/Changes.md index c4178d7..68718c5 100644 --- a/Changes.md +++ b/Changes.md @@ -1,23 +1,41 @@ +### Unreleased -## 1.0.4 - 2017-__-__ + +### [1.0.5] - 2022-06-05 + +- ci: replace appveyor & travis with GitHub actions +- ci: add GHA shared workflows +- lint: prefer-template +- test: replace nodeunit with mocha + + +### [1.0.4] - 2017-09-05 - drop node 4.x testing. -## 1.0.3 - 2017-08-06 + +### 1.0.3 - 2017-08-06 - corrected config path to always_ok setting -## 1.0.2 - 2017-07-30 + +### 1.0.2 - 2017-07-30 - declare booleans in config.get - simplify a bunch of the follow-on code - refactor away 5x redundancy - remove Mooney-isms from nodeunit and use npm version -## 1.0.1 - 2017-06-13 + +### 1.0.1 - 2017-06-13 - Require higher haraka-constants so constants.OK is set properly -## 1.0.0 - 2016-11-09 + +### 1.0.0 - 2016-11-09 - import from haraka/Haraka + + +[1.0.4]: https://github.com/haraka/haraka-plugin-syslog/releases/tag/1.0.4 +[1.0.5]: https://github.com/haraka/haraka-plugin-syslog/releases/tag/1.0.5 diff --git a/README.md b/README.md index 47dbcd4..de7b46a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![Code Climate][clim-img]][clim-url] [![NPM][npm-img]][npm-url] - # haraka-plugin-syslog @@ -85,12 +84,9 @@ Sane defaults are chosen for you. This will case the plugin to always call next(OK). -[ci-img]: https://travis-ci.org/haraka/haraka-plugin-syslog.svg -[ci-url]: https://travis-ci.org/haraka/haraka-plugin-syslog -[cov-img]: https://codecov.io/github/haraka/haraka-plugin-syslog/coverage.svg -[cov-url]: https://codecov.io/github/haraka/haraka-plugin-syslog +[ci-img]: https://github.com/haraka/haraka-plugin-syslog/actions/workflows/ci.yml/badge.svg +[ci-url]: https://github.com/haraka/haraka-plugin-syslog/actions/workflows/ci.yml [clim-img]: https://codeclimate.com/github/haraka/haraka-plugin-syslog/badges/gpa.svg [clim-url]: https://codeclimate.com/github/haraka/haraka-plugin-syslog [npm-img]: https://nodei.co/npm/haraka-plugin-syslog.png [npm-url]: https://www.npmjs.com/package/haraka-plugin-syslog -[gk-img]: https://badges.greenkeeper.io/haraka/haraka-plugin-syslog.svg diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 8858bc2..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,20 +0,0 @@ -environment: - nodejs_version: "6" - -install: - - ps: Install-Product node $env:nodejs_version - - npm install - -before_build: -build: off -after_build: - -before_test: - - node --version - - npm --version - -test_script: - - npm test - -after_test: - diff --git a/index.js b/index.js index 7f5013b..7aede27 100644 --- a/index.js +++ b/index.js @@ -10,12 +10,12 @@ exports.register = function () { plugin.load_syslog_ini(); - const name = plugin.cfg.general.name || 'haraka'; + const name = plugin.cfg.general.name || 'haraka'; let facility = plugin.cfg.general.facility || 'MAIL'; ['pid','odelay','cons','ndelay','nowait'].forEach(opt => { if (!plugin.cfg.general[opt]) return; - options |= syslog['LOG_' + opt.toUpperCase() ]; + options |= syslog[`LOG_${ opt.toUpperCase()}` ]; }) if (facility !== facility.toUpperCase()) facility = facility.toUpperCase(); @@ -38,7 +38,7 @@ exports.register = function () { case 'LOCAL5': case 'LOCAL6': case 'LOCAL7': - syslog.init(name, options, syslog[ 'LOG_' + facility ]); + syslog.init(name, options, syslog[ `LOG_${ facility}` ]); break; default: syslog.init(name, options, syslog.LOG_MAIL); diff --git a/package.json b/package.json index 654939d..a828960 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,12 @@ { "name": "haraka-plugin-syslog", - "version": "1.0.4", + "version": "1.0.5", "description": "Haraka plugin that logs to syslog", "main": "index.js", "scripts": { - "test": "node run_tests", - "lint": "node node_modules/.bin/eslint *.js test/*.js", - "lintfix": "node node_modules/.bin/eslint --fix *.js test/*.js", - "cover": "node node_modules/.bin/istanbul cover ./run_tests" + "test": "npx mocha", + "lint": "npx eslint *.js test", + "lintfix": "npx eslint --fix *.js test" }, "repository": { "type": "git", @@ -19,7 +18,7 @@ "syslog", "log" ], - "author": "Haraka Team ", + "author": "Haraka Team ", "license": "MIT", "bugs": { "url": "https://github.com/haraka/haraka-plugin-syslog/issues" @@ -30,9 +29,9 @@ "modern-syslog": "^1.1.4" }, "devDependencies": { - "eslint": "*", + "eslint": ">=8", "eslint-plugin-haraka": "*", "haraka-test-fixtures": "*", - "nodeunit": "*" + "mocha": ">=9" } -} +} \ No newline at end of file diff --git a/run_tests b/run_tests deleted file mode 100755 index 22222c3..0000000 --- a/run_tests +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env node - -"use strict"; - -try { - var reporter = require('nodeunit').reporters.default; -} -catch(e) { - console.log("Error: " + e.message); - console.log(""); - console.log("Cannot find nodeunit module."); - console.log("Please run the following:"); - console.log(""); - console.log(" npm install"); - console.log(""); - process.exit(); -} - -process.chdir(__dirname); - -if (process.argv[2]) { - console.log("Running tests: ", process.argv.slice(2)); - reporter.run(process.argv.slice(2), undefined, function (err) { - process.exit(((err) ? 1 : 0)); - }); -} -else { - reporter.run([ - 'test', - ], undefined, function (err) { - process.exit(((err) ? 1 : 0)); - }); -} diff --git a/test/syslog.js b/test/syslog.js index be03c61..4dd713b 100644 --- a/test/syslog.js +++ b/test/syslog.js @@ -1,12 +1,14 @@ 'use strict'; +const assert = require('assert') + const fixtures = require('haraka-test-fixtures'); const constants = require('haraka-constants'); const stub = fixtures.stub.stub; const _set_up = function (done) { - this.backup = { plugin: { Syslog: {} } }; + this.backup = { plugin: { Syslog: {} } } this.plugin = new fixtures.plugin('syslog'); @@ -27,7 +29,7 @@ const _set_up = function (done) { log_nowait : 'random', always_ok : false } - }; + } if (this.plugin) { this.plugin.config.get = function () { @@ -36,195 +38,186 @@ const _set_up = function (done) { } done(); -}; +} -exports.register = { - setUp : _set_up, - 'should have register function' : function (test) { +describe('register', function () { + beforeEach(_set_up) + + it('should have register function', function (done) { if (this.plugin) { - test.expect(2); - test.ok(this.plugin); - test.equals(typeof this.plugin.register, 'function'); + assert.ok(this.plugin); + assert.equal(typeof this.plugin.register, 'function'); } - test.done(); - }, - 'register function should call register_hook()' : function (test) { + done() + }) + + it('register function should call register_hook()', function (done) { if (this.plugin && this.plugin.Syslog) { this.plugin.register(); - test.expect(1); - test.ok(this.plugin.register_hook.called); + assert.ok(this.plugin.register_hook.called); } - test.done(); - }, - 'register_hook() should register for proper hook' : function (test) { + done() + }) + + it('register_hook() should register for proper hook', function (done) { if (this.plugin && this.plugin.Syslog) { this.plugin.register(); - test.expect(1); - test.equals(this.plugin.register_hook.args[0], 'log'); + assert.equal(this.plugin.register_hook.args[0], 'log'); } - test.done(); - }, - 'register_hook() should register available function' : function (test) { + done() + }) + + it('register_hook() should register available function', function (done) { if (this.plugin && this.plugin.Syslog) { this.plugin.register(); - test.expect(3); - test.equals(this.plugin.register_hook.args[1], 'syslog'); - test.ok(this.plugin.syslog); - test.equals(typeof this.plugin.syslog, 'function'); + assert.equal(this.plugin.register_hook.args[1], 'syslog'); + assert.ok(this.plugin.syslog); + assert.equal(typeof this.plugin.syslog, 'function'); } - test.done(); - }, - 'register calls Syslog.init()' : function (test) { + done() + }) + + it('register calls Syslog.init()', function (done) { // local setup if (this.plugin && this.plugin.Syslog) { this.backup.plugin.Syslog.init = this.plugin.Syslog.init; this.plugin.Syslog.init = stub(); this.plugin.register(); - test.expect(1); - test.ok(this.plugin.Syslog.init.called); + assert.ok(this.plugin.Syslog.init.called); } - test.done(); + done() // local teardown if (this.plugin && this.plugin.Syslog) { this.plugin.Syslog.init = this.backup.plugin.Syslog.init; } - }, - 'register calls Syslog.init() with correct args' : function (test) { + }) + + it('register calls Syslog.init() with correct args', function (done) { // local setup if (this.plugin && this.plugin.Syslog) { this.backup.plugin.Syslog.init = this.plugin.Syslog.init; this.plugin.Syslog.init = stub(); this.plugin.register(); - test.expect(4); - test.ok(this.plugin.Syslog.init.called); - test.equals(this.plugin.Syslog.init.args[0], + assert.ok(this.plugin.Syslog.init.called); + assert.equal(this.plugin.Syslog.init.args[0], this.plugin.config.get("test").general.name); - test.equals(this.plugin.Syslog.init.args[1], + assert.equal(this.plugin.Syslog.init.args[1], this.plugin.Syslog.LOG_PID | this.plugin.Syslog.LOG_ODELAY); - test.equals(this.plugin.Syslog.init.args[2], + assert.equal(this.plugin.Syslog.init.args[2], this.plugin.Syslog.LOG_MAIL); } - test.done(); + done() // local teardown if (this.plugin && this.plugin.Syslog) { this.plugin.Syslog.init = this.backup.plugin.Syslog.init; } - }, -}; + }) +}) + +describe('hook', function () { + beforeEach(_set_up) -exports.hook = { - setUp : _set_up, - 'returns just next() by default (missing always_ok)' : function (test) { - if (!this.plugin || !this.plugin.Syslog) { return test.done(); } + it('returns just next() by default (missing always_ok)', function (done) { + if (!this.plugin || !this.plugin.Syslog) { return done() } const next = function (action) { - test.expect(1); test.isUndefined(action); - test.done(); - }; + done() + } this.plugin.syslog(next, this.logger, this.log); - }, - 'returns just next() if always_ok is false' : function (test) { + }) + + it('returns just next() if always_ok is false', function (done) { // local setup this.backup.configfile = this.configfile; this.configfile.general.always_ok = 'false'; - if (!this.plugin || !this.plugin.Syslog) { return test.done(); } + if (!this.plugin || !this.plugin.Syslog) { return done() } this.plugin.register(); - const next = function (action) { - test.expect(1); + this.plugin.syslog(function (action) { test.isUndefined(action); - test.done(); - }; + done() + }, this.logger, this.log); + }) - this.plugin.syslog(next, this.logger, this.log); - }, - 'returns next(OK) if always_ok is true' : function (test) { - if (!this.plugin || !this.plugin.Syslog) { return test.done(); } + it('returns next(OK) if always_ok is true', function (done) { + if (!this.plugin || !this.plugin.Syslog) { return done() } // local setup this.backup.configfile = this.configfile; this.configfile.general.always_ok = 'true'; this.plugin.register(); - const next = function (action) { - test.expect(1); - test.equals(action, constants.OK); - test.done(); - }; - - this.plugin.syslog(next, this.logger, this.log); + this.plugin.syslog(function (action) { + assert.equal(action, constants.OK); + done() + }, this.logger, this.log); // local teardown this.configfile = this.backup.configfile; - }, - 'returns just next() if always_ok is 0' : function (test) { - if (!this.plugin || !this.plugin.Syslog) { return test.done(); } + }) + + it('returns just next() if always_ok is 0', function (done) { + if (!this.plugin || !this.plugin.Syslog) { return done() } // local setup this.backup.configfile = this.configfile; this.configfile.general.always_ok = 0; this.plugin.register(); - const next = function (action) { - test.expect(1); + this.plugin.syslog(function (action) { test.isUndefined(action); - test.done(); - }; + done() + }, this.logger, this.log); + }) - this.plugin.syslog(next, this.logger, this.log); - }, - 'returns next(OK) if always_ok is 1' : function (test) { - if (!this.plugin || !this.plugin.Syslog) { return test.done(); } + it('returns next(OK) if always_ok is 1', function (done) { + if (!this.plugin || !this.plugin.Syslog) { return done() } // local setup this.backup.configfile = this.configfile; this.configfile.general.always_ok = 1; this.plugin.register(); - const next = function (action) { - test.expect(1); - test.equals(action, constants.OK); - test.done(); - }; - - this.plugin.syslog(next, this.logger, this.log); + this.plugin.syslog(function (action) { + assert.equal(action, constants.OK); + done() + }, this.logger, this.log); // local teardown this.configfile = this.backup.configfile; - }, - 'returns next() if always_ok is random' : function (test) { - if (!this.plugin || !this.plugin.Syslog) { return test.done(); } + }) + + it('returns next() if always_ok is random', function (done) { + if (!this.plugin || !this.plugin.Syslog) { return done() } // local setup this.backup.configfile = this.configfile; this.configfile.general.always_ok = 'random'; this.plugin.register(); - const next = function (action) { - test.expect(1); + this.plugin.syslog(function (action) { test.isUndefined(action); - test.done(); - }; - - this.plugin.syslog(next, this.logger, this.log); + done() + }, this.logger, this.log); // local teardown this.configfile = this.backup.configfile; - }, -}; + }) +}) + +describe('log', function () { + beforeEach(_set_up) -exports.log = { - setUp : _set_up, - 'syslog hook logs correct thing' : function (test) { + it('syslog hook logs correct thing', function (done) { const plugin = this.plugin; - if (!plugin || !plugin.Syslog) return test.done(); + if (!plugin || !plugin.Syslog) return done() // local setup const next = stub(); @@ -232,13 +225,12 @@ exports.log = { plugin.Syslog.log = stub(); plugin.syslog(next, this.logger, this.log); - test.expect(3); - test.ok(plugin.Syslog.log.called); - test.equals(plugin.Syslog.log.args[0], plugin.Syslog.LOG_INFO); - test.equals(plugin.Syslog.log.args[1], this.log.data); - test.done(); + assert.ok(plugin.Syslog.log.called); + assert.equal(plugin.Syslog.log.args[0], plugin.Syslog.LOG_INFO); + assert.equal(plugin.Syslog.log.args[1], this.log.data); + done() // local teardown plugin.Syslog.log = this.backup.plugin.Syslog.log; - } -}; + }) +})