From 100402d805b75bcf1be47039495c1f7e3e26ee13 Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Wed, 26 May 2021 19:51:43 +0800 Subject: [PATCH 1/3] Make eslint work in CI (#42) --- .github/workflows/main.yml | 2 ++ package.json | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f3d7f66..d0e4aeb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,8 @@ jobs: uses: actions/checkout@v2 - name: Download Internet run: npm install + - name: Run eslint + run: npm run lint - name: Enable Developer Command Prompt (amd64) uses: ./ with: diff --git a/package.json b/package.json index f110a2c..c2f7c22 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,7 @@ "description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++", "main": "index.js", "scripts": { - "lint": "eslint index.js", - "test": "eslint index.js" + "lint": "eslint index.js" }, "repository": { "type": "git", From c5426bf30a3434644ece5a1c84861f4a08bc5289 Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Wed, 26 May 2021 19:53:04 +0800 Subject: [PATCH 2/3] Separate output content from CMD with form feed (#40) The command "cls" will produce a '\f' (0x0c, page break or form feed) character. --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c87d7e0..08fd322 100644 --- a/index.js +++ b/index.js @@ -116,14 +116,18 @@ function main() { const vcvars = `"${findVcvarsall()}" ${args.join(' ')}` core.debug(`vcvars command-line: ${vcvars}`) - const old_environment = child_process.execSync(`set`, {shell: "cmd"}).toString().split('\r\n') - const new_environment = child_process.execSync(`${vcvars} && set`, {shell: "cmd"}).toString().split('\r\n') + const cmd_output_string = child_process.execSync(`set && cls && ${vcvars} && cls && set`, {shell: "cmd"}).toString() + const cmd_output_parts = cmd_output_string.split('\f') + + const old_environment = cmd_output_parts[0].split('\r\n') + const vcvars_output = cmd_output_parts[1].split('\r\n') + const new_environment = cmd_output_parts[2].split('\r\n') // If vsvars.bat is given an incorrect command line, it will print out // an error and *still* exit successfully. Parse out errors from output // which don't look like environment variables, and fail if appropriate. var failed = false - for (let line of new_environment) { + for (let line of vcvars_output) { if (line.match(/^\[ERROR.*\]/)) { failed = true // Don't print this particular line which will be confusing in output. From 985d494a0f059e129c6e2172efe0d86941ae3454 Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Wed, 26 May 2021 21:32:04 +0800 Subject: [PATCH 3/3] Print the error message from conf scripts at once (#41) Printing them line by line will generate a bunch of error messages on the summary page of GitHub Actions workflow. I think it's a bit annoying. Note that this change will also affect the format of the final output error message, but no information will be lost. --- index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 08fd322..a5f9bd8 100644 --- a/index.js +++ b/index.js @@ -126,19 +126,17 @@ function main() { // If vsvars.bat is given an incorrect command line, it will print out // an error and *still* exit successfully. Parse out errors from output // which don't look like environment variables, and fail if appropriate. - var failed = false - for (let line of vcvars_output) { + const error_messages = vcvars_output.filter((line) => { if (line.match(/^\[ERROR.*\]/)) { - failed = true // Don't print this particular line which will be confusing in output. - if (line.match(/Error in script usage. The correct usage is:$/)) { - continue + if (!line.match(/Error in script usage. The correct usage is:$/)) { + return true } - core.error(line) } - } - if (failed) { - throw new Error('invalid parameters') + return false + }) + if (error_messages.length > 0) { + throw new Error('invalid parameters' + '\r\n' + error_messages.join('\r\n')) } // Convert old environment lines into a dictionary for easier lookup.