From 00fafbc04ec52ae3a3cddddc41d14fbe242c15b2 Mon Sep 17 00:00:00 2001 From: Johan de Jager Date: Mon, 14 Oct 2019 20:33:23 +0200 Subject: [PATCH 1/8] Log environment --- .gitignore | 2 ++ lib/request.js | 10 +++++----- lib/run.js | 30 ++++++++++++++++-------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index ad46b308..1649e6a0 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,5 @@ typings/ # next.js build output .next + +.idea/ diff --git a/lib/request.js b/lib/request.js index 777ad6ae..cb372897 100644 --- a/lib/request.js +++ b/lib/request.js @@ -4,15 +4,15 @@ module.exports = (url, options) => { return new Promise((resolve, reject) => { const req = https .request(url, options, res => { - let data = '' + let data = ''; res.on('data', chunk => { data += chunk - }) + }); res.on('end', () => { if (res.statusCode >= 400) { - const err = new Error(`Received status code ${res.statusCode}`) - err.response = res - err.data = data + const err = new Error(`Received status code ${res.statusCode}`); + err.response = res; + err.data = data; reject(err) } else { resolve({ res, data: JSON.parse(data) }) diff --git a/lib/run.js b/lib/run.js index 6dd57b7b..8d165385 100644 --- a/lib/run.js +++ b/lib/run.js @@ -1,21 +1,23 @@ const request = require('./request') +console.log(process.env); + const { GITHUB_SHA, GITHUB_EVENT_PATH, GITHUB_TOKEN, GITHUB_WORKSPACE } = process.env const event = require(GITHUB_EVENT_PATH) -const { repository } = event +const { repository } = event; const { owner: { login: owner } -} = repository -const { name: repo } = repository +} = repository; +const { name: repo } = repository; -const checkName = 'ESLint check' +const checkName = 'ESLint check'; const headers = { 'Content-Type': 'application/json', Accept: 'application/vnd.github.antiope-preview+json', Authorization: `Bearer ${GITHUB_TOKEN}`, 'User-Agent': 'eslint-action' -} +}; async function createCheck() { const body = { @@ -23,28 +25,28 @@ async function createCheck() { head_sha: GITHUB_SHA, status: 'in_progress', started_at: new Date() - } + }; const { data } = await request(`https://api.github.com/repos/${owner}/${repo}/check-runs`, { method: 'POST', headers, body - }) - const { id } = data + }); + const { id } = data; return id } function eslint() { - const eslint = require('eslint') + const eslint = require('eslint'); - const cli = new eslint.CLIEngine() - const report = cli.executeOnFiles(['.']) + const cli = new eslint.CLIEngine(); + const report = cli.executeOnFiles(['.']); // fixableErrorCount, fixableWarningCount are available too - const { results, errorCount, warningCount } = report + const { results, errorCount, warningCount } = report; - const levels = ['', 'warning', 'failure'] + const levels = ['', 'warning', 'failure']; - const annotations = [] + const annotations = []; for (const result of results) { const { filePath, messages } = result const path = filePath.substring(GITHUB_WORKSPACE.length + 1) From b4d9085b85a56bc2dd4a9a50be494c4aeaf1cd74 Mon Sep 17 00:00:00 2001 From: Johan de Jager Date: Mon, 14 Oct 2019 20:58:00 +0200 Subject: [PATCH 2/8] Fixed stuff --- lib/entrypoint.sh | 5 +++++ lib/run.js | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index c67a33f1..d6a15d8f 100755 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -1,6 +1,11 @@ #!/bin/sh set -e +env +cd admin-frontend + +ls +env npm install diff --git a/lib/run.js b/lib/run.js index 8d165385..11516180 100644 --- a/lib/run.js +++ b/lib/run.js @@ -1,9 +1,8 @@ -const request = require('./request') +const request = require('./request'); -console.log(process.env); const { GITHUB_SHA, GITHUB_EVENT_PATH, GITHUB_TOKEN, GITHUB_WORKSPACE } = process.env -const event = require(GITHUB_EVENT_PATH) +const event = require(GITHUB_EVENT_PATH); const { repository } = event; const { owner: { login: owner } From 12d127eb68858418ac22676943e301f2afbc4e70 Mon Sep 17 00:00:00 2001 From: Johan de Jager Date: Mon, 14 Oct 2019 21:01:05 +0200 Subject: [PATCH 3/8] huh --- lib/entrypoint.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index d6a15d8f..705718d6 100755 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -2,10 +2,7 @@ set -e env -cd admin-frontend - ls -env npm install From d2b528a9bd870635849674f1d4de0b56f984a59a Mon Sep 17 00:00:00 2001 From: Johan de Jager Date: Mon, 14 Oct 2019 21:04:12 +0200 Subject: [PATCH 4/8] heh --- lib/entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index 705718d6..c5ff2acb 100755 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -3,7 +3,8 @@ set -e env ls - +cd admin-frontend +ls npm install NODE_PATH=node_modules node /action/lib/run.js From 4aaffe4d6818d0473cdc242302429904cb6dfc51 Mon Sep 17 00:00:00 2001 From: Johan de Jager Date: Mon, 14 Oct 2019 21:14:59 +0200 Subject: [PATCH 5/8] Fixed issues --- lib/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/run.js b/lib/run.js index 11516180..376a1e51 100644 --- a/lib/run.js +++ b/lib/run.js @@ -39,7 +39,7 @@ function eslint() { const eslint = require('eslint'); const cli = new eslint.CLIEngine(); - const report = cli.executeOnFiles(['.']); + const report = cli.executeOnFiles(['./src/**/*.{ts,tsx}']); // fixableErrorCount, fixableWarningCount are available too const { results, errorCount, warningCount } = report; From d9c41a17798988dea84d067259c3e4171affdbb1 Mon Sep 17 00:00:00 2001 From: Johan de Jager Date: Mon, 14 Oct 2019 21:46:07 +0200 Subject: [PATCH 6/8] Customize project directory and file pattern --- lib/entrypoint.sh | 10 ++++++---- lib/run.js | 36 +++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index c5ff2acb..7969865b 100755 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -1,10 +1,12 @@ #!/bin/sh set -e -env -ls -cd admin-frontend -ls + +if [ -z "$PROJECT_DIRECTORY" ] +then + cd $PROJECT_DIRECTORY +fi + npm install NODE_PATH=node_modules node /action/lib/run.js diff --git a/lib/run.js b/lib/run.js index 376a1e51..8e73127e 100644 --- a/lib/run.js +++ b/lib/run.js @@ -1,22 +1,21 @@ -const request = require('./request'); - +const request = require('./request') const { GITHUB_SHA, GITHUB_EVENT_PATH, GITHUB_TOKEN, GITHUB_WORKSPACE } = process.env -const event = require(GITHUB_EVENT_PATH); -const { repository } = event; +const event = require(GITHUB_EVENT_PATH) +const { repository } = event const { owner: { login: owner } -} = repository; -const { name: repo } = repository; +} = repository +const { name: repo } = repository -const checkName = 'ESLint check'; +const checkName = 'ESLint check' const headers = { 'Content-Type': 'application/json', Accept: 'application/vnd.github.antiope-preview+json', Authorization: `Bearer ${GITHUB_TOKEN}`, 'User-Agent': 'eslint-action' -}; +} async function createCheck() { const body = { @@ -24,28 +23,31 @@ async function createCheck() { head_sha: GITHUB_SHA, status: 'in_progress', started_at: new Date() - }; + } const { data } = await request(`https://api.github.com/repos/${owner}/${repo}/check-runs`, { method: 'POST', headers, body - }); - const { id } = data; + }) + const { id } = data return id } function eslint() { - const eslint = require('eslint'); + const eslint = require('eslint') + + const cli = new eslint.CLIEngine() + + const filePattern = process.env.FILE_PATTERN || '.'; - const cli = new eslint.CLIEngine(); - const report = cli.executeOnFiles(['./src/**/*.{ts,tsx}']); + const report = cli.executeOnFiles([filePattern]) // fixableErrorCount, fixableWarningCount are available too - const { results, errorCount, warningCount } = report; + const { results, errorCount, warningCount } = report - const levels = ['', 'warning', 'failure']; + const levels = ['', 'warning', 'failure'] - const annotations = []; + const annotations = [] for (const result of results) { const { filePath, messages } = result const path = filePath.substring(GITHUB_WORKSPACE.length + 1) From ca201bfcc1d58c70938c900b39542ce9b17d73c0 Mon Sep 17 00:00:00 2001 From: Johan de Jager Date: Mon, 14 Oct 2019 21:51:31 +0200 Subject: [PATCH 7/8] Removed semi colons to be in line with existing codestyle --- lib/request.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/request.js b/lib/request.js index cb372897..777ad6ae 100644 --- a/lib/request.js +++ b/lib/request.js @@ -4,15 +4,15 @@ module.exports = (url, options) => { return new Promise((resolve, reject) => { const req = https .request(url, options, res => { - let data = ''; + let data = '' res.on('data', chunk => { data += chunk - }); + }) res.on('end', () => { if (res.statusCode >= 400) { - const err = new Error(`Received status code ${res.statusCode}`); - err.response = res; - err.data = data; + const err = new Error(`Received status code ${res.statusCode}`) + err.response = res + err.data = data reject(err) } else { resolve({ res, data: JSON.parse(data) }) From fc7682bbcfd93f1812ce63f4e93fade33e0313c9 Mon Sep 17 00:00:00 2001 From: Johan de Jager Date: Mon, 14 Oct 2019 22:05:44 +0200 Subject: [PATCH 8/8] Fixed entrypoint --- lib/entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index 7969865b..8e33652f 100755 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -4,9 +4,10 @@ set -e if [ -z "$PROJECT_DIRECTORY" ] then - cd $PROJECT_DIRECTORY + PROJECT_DIRECTORY="." fi +cd $PROJECT_DIRECTORY npm install NODE_PATH=node_modules node /action/lib/run.js