diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..7cf0619 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,35 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x, 14.x, 15.x] + + steps: + - uses: actions/checkout@v2 + with: + # Need commit history test for cli-tests + fetch-depth: 0 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm run build --if-present + - run: npm run test-ci + env: + CI: true + - run: bash <(curl -s https://codecov.io/bash) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 91e55ad..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: node_js -node_js: - - "8" - - "10" - - "12" - - "13" -cache: npm -script: 'npm run test-ci' -after_script: 'bash <(curl -s https://codecov.io/bash)' diff --git a/bin/cmd.js b/bin/cmd.js index 81eccd3..de832e8 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -38,7 +38,6 @@ const usage = require('help')() if (parsed.help) { usage() - process.exit(0) } if (parsed.version) { @@ -47,18 +46,18 @@ if (parsed.version) { } const args = parsed.argv.remain -if (!args.length) { args.push('HEAD') } +if (!parsed.help && !args.length) { args.push('HEAD') } function load (sha, cb) { - const parsed = new URL(sha) - if (parsed.protocol) { + try { + const parsed = new URL(sha) return loadPatch(parsed, cb) + } catch (_) { + exec(`git show --quiet --format=medium ${sha}`, (err, stdout, stderr) => { + if (err) return cb(err) + cb(null, stdout.trim()) + }) } - - exec(`git show --quiet --format=medium ${sha}`, (err, stdout, stderr) => { - if (err) return cb(err) - cb(null, stdout.trim()) - }) } function loadPatch (uri, cb) { @@ -66,10 +65,10 @@ function loadPatch (uri, cb) { if (~uri.protocol.indexOf('https')) { h = https } - uri.headers = { + const headers = { 'user-agent': 'core-validate-commit' } - h.get(uri, (res) => { + h.get(uri, { headers }, (res) => { let buf = '' res.on('data', (chunk) => { buf += chunk diff --git a/lib/rules/subsystem.js b/lib/rules/subsystem.js index 2ac53aa..cabf159 100644 --- a/lib/rules/subsystem.js +++ b/lib/rules/subsystem.js @@ -19,7 +19,7 @@ const validSubsystems = [ 'meta', 'msi', 'node', - 'n-api', + 'node-api', 'perfctr', 'policy', 'src', diff --git a/package.json b/package.json index 58d63b6..06ea761 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "core-validate-commit", - "version": "3.13.1", + "version": "3.13.3", "description": "Validate the commit message for a particular commit in node core", "main": "index.js", "scripts": { diff --git a/test/cli-test.js b/test/cli-test.js index 04fc0bf..8729078 100644 --- a/test/cli-test.js +++ b/test/cli-test.js @@ -1,13 +1,14 @@ 'use strict' const { test } = require('tap') +const { readFileSync } = require('fs') const { spawn } = require('child_process') const subsystems = require('../lib/rules/subsystem') test('Test cli flags', (t) => { t.test('test list-subsystems', (tt) => { const ls = spawn('./bin/cmd.js', ['--list-subsystems'], { - env: { FORCE_COLOR: 0 } + env: { ...process.env, FORCE_COLOR: 0 } }) let compiledData = '' ls.stdout.on('data', (data) => { @@ -42,6 +43,64 @@ test('Test cli flags', (t) => { }) }) + t.test('test help output', (tt) => { + const usage = readFileSync('bin/usage.txt', { encoding: 'utf8' }) + const ls = spawn('./bin/cmd.js', ['--help']) + let compiledData = '' + ls.stdout.on('data', (data) => { + compiledData += data + }) + + ls.stderr.on('data', (data) => { + tt.fail('This should not happen') + }) + + ls.on('close', (code) => { + tt.equal(compiledData.trim(), + usage.trim(), + '--help output is as expected') + tt.end() + }) + }) + + t.test('test sha', (tt) => { + const ls = spawn('./bin/cmd.js', ['--no-validate-metadata', '2b98d02b52']) + let compiledData = '' + ls.stdout.on('data', (data) => { + compiledData += data + }) + + ls.stderr.on('data', (data) => { + tt.fail('This should not happen') + }) + + ls.on('close', (code) => { + tt.match(compiledData.trim(), + /2b98d02b52/, + 'output is as expected') + tt.end() + }) + }) + + t.test('test url', (tt) => { + const ls = spawn('./bin/cmd.js', ['--no-validate-metadata', 'https://api.github.com/repos/nodejs/core-validate-commit/commits/2b98d02b52']) + let compiledData = '' + ls.stdout.on('data', (data) => { + compiledData += data + }) + + ls.stderr.on('data', (data) => { + tt.fail('This should not happen') + }) + + ls.on('close', (code) => { + tt.match(compiledData.trim(), + /2b98d02b52/, + 'output is as expected') + tt.end() + }) + }) + t.test('test version flag', (tt) => { const ls = spawn('./bin/cmd.js', ['--version']) let compiledData = ''