From 2b98d02b52a0abe98054eccb351e1e5c71c81bb0 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Mon, 8 Feb 2021 04:55:03 -0800 Subject: [PATCH 1/6] lib: rename n-api to node-api (#87) `n-api` shall no longer be accepted as a subsystem. Instead, the accepted name for it shall be `node-api`. Refs: https://github.com/nodejs/abi-stable-node/issues/420 --- lib/rules/subsystem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', From c80fb55f3da23a0ec565a70b73091fabcf9bddf0 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Mon, 8 Feb 2021 12:55:57 +0000 Subject: [PATCH 2/6] 3.13.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 58d63b6..c035f0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "core-validate-commit", - "version": "3.13.1", + "version": "3.13.2", "description": "Validate the commit message for a particular commit in node core", "main": "index.js", "scripts": { From e57575c24b84329ed24bdc73510d29fa8b546eec Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 9 Feb 2021 05:55:08 -0800 Subject: [PATCH 3/6] chore: move from Travis to GitHub Actions (#89) Travis isn't running because we're out of credits. Move to GitHub Actions. --- .github/workflows/node.js.yml | 32 ++++++++++++++++++++++++++++++++ .travis.yml | 9 --------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/node.js.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..8279e10 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,32 @@ +# 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 + - 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)' From 3dff15baed4f4922bf38702dee3a3ee5f73bb095 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Tue, 9 Feb 2021 12:03:06 +0000 Subject: [PATCH 4/6] bin: fix URL parsing `new URL()` throws an exception when failing to parse a URL. --- .github/workflows/node.js.yml | 3 +++ bin/cmd.js | 18 ++++++++--------- test/cli-test.js | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 8279e10..7cf0619 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -20,6 +20,9 @@ jobs: 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: diff --git a/bin/cmd.js b/bin/cmd.js index 81eccd3..1f3f701 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -50,15 +50,15 @@ const args = parsed.argv.remain if (!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 +66,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/test/cli-test.js b/test/cli-test.js index 04fc0bf..2a5f625 100644 --- a/test/cli-test.js +++ b/test/cli-test.js @@ -42,6 +42,44 @@ test('Test cli flags', (t) => { }) }) + 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 = '' From e9fe70e23015436fd47de321085556cc1894ac6e Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Tue, 9 Feb 2021 12:44:14 +0000 Subject: [PATCH 5/6] bin: wait for help output The `help` module asynchronously pipes output to streams. Do not explicitly `process.exit` to allow the asynchronous operation to complete. --- bin/cmd.js | 3 +-- test/cli-test.js | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index 1f3f701..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,7 +46,7 @@ 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) { try { diff --git a/test/cli-test.js b/test/cli-test.js index 2a5f625..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,26 @@ 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 = '' From 2572f49e0275637b3db72d761f0226eefb09e1b8 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Tue, 9 Feb 2021 16:43:07 +0000 Subject: [PATCH 6/6] 3.13.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c035f0f..06ea761 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "core-validate-commit", - "version": "3.13.2", + "version": "3.13.3", "description": "Validate the commit message for a particular commit in node core", "main": "index.js", "scripts": {