This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-infrastructure.git


The following commit(s) were added to refs/heads/main by this push:
     new 31ab54e  Use getExecOutput instead of exec when stdout is needed
31ab54e is described below

commit 31ab54e89b0e9cf50e70c62f503d85c9e402a8c2
Author: Steve Lawrence <[email protected]>
AuthorDate: Thu Nov 13 13:08:33 2025 -0500

    Use getExecOutput instead of exec when stdout is needed
    
    When we need to capture the stdout of a command, we currently call exec
    with a custom stdout handler that copies stdout to a mutable variable.
    But getExecOutput already does this, returning an object that contains
    stdout (and stderr and the exit code which we don't need).
    
    This switches out exec calls to getExecOutput when we need stdout, which
    simplifies the code and removes a number of mutable variables.
    
    DAFFODIL-3055
---
 actions/release-candidate/dist/main/index.js | 36 ++++++++--------------------
 actions/release-candidate/dist/post/index.js | 24 ++++++-------------
 actions/release-candidate/src/main.js        | 36 ++++++++--------------------
 actions/release-candidate/src/post.js        | 24 ++++++-------------
 4 files changed, 34 insertions(+), 86 deletions(-)

diff --git a/actions/release-candidate/dist/main/index.js 
b/actions/release-candidate/dist/main/index.js
index 162d695..a2866b3 100644
--- a/actions/release-candidate/dist/main/index.js
+++ b/actions/release-candidate/dist/main/index.js
@@ -31848,7 +31848,7 @@ const fs = __nccwpck_require__(9896);
 const os = __nccwpck_require__(857);
 const core = __nccwpck_require__(7484);
 const github = __nccwpck_require__(3228);
-const { exec } = __nccwpck_require__(5236);
+const { exec, getExecOutput } = __nccwpck_require__(5236);
 const crypto = __nccwpck_require__(6982);
 
 async function run() {
@@ -31896,21 +31896,15 @@ async function run() {
                }
 
                // Capture the key id of the most recent generated/imported key
-               let gpg_list_secret_keys_stdout = "";
-               await exec("gpg", ["--list-secret-keys", "--with-colons"], {
-                       silent: true,
-                       listeners: {
-                               stdout: (data) => {
-                                       gpg_list_secret_keys_stdout += 
data.toString();
-                               }
-                       }
+               const gpg_list_output = await getExecOutput("gpg", 
["--list-secret-keys", "--with-colons"], {
+                       silent: true
                });
-               const gpg_signing_key_id = gpg_list_secret_keys_stdout
+               const gpg_signing_key_id = gpg_list_output.stdout
                        .split('\n')
                        .findLast(l => l.startsWith("fpr"))
                        .split(':')[9];
 
-               console.info("Using gpgp key id: " + gpg_signing_key_id);
+               console.info("Using gpg key id: " + gpg_signing_key_id);
 
                // figure out the release version. This should follow the 
pattern
                // 'v<VERSION>-rcX', where <VERSION> is the value from the 
VERSION file
@@ -31932,17 +31926,11 @@ async function run() {
                        if (do_publish) {
                                // if publishing, tags must be signed with a 
committers key, download and import committer
                                // keys for verification
-                               let committer_keys = "";
-                               await exec("curl", 
[`https://downloads.apache.org/${tlp_dir}/KEYS`], {
-                                       silent: true,
-                                       listeners: {
-                                               stdout: (data) => {
-                                                       committer_keys += 
data.toString();
-                                               }
-                                       }
+                               const curl_output = await getExecOutput("curl", 
[`https://downloads.apache.org/${tlp_dir}/KEYS`], {
+                                       silent: true
                                });
                                await exec("gpg", ["--batch", "--import"], {
-                                       input: Buffer.from(committer_keys)
+                                       input: Buffer.from(curl_output.stdout)
                                });
 
                                // make sure the tag is signed by a committer 
in the KEYS file, this
@@ -32056,12 +32044,8 @@ async function run() {
                await exec("git", ["archive", "--format=zip", `--prefix=${ 
src_artifact_name }/`, "--output", `${ src_artifact_dir }/${ src_artifact_name 
}.zip`, "HEAD"]);
 
                // get the reproducible build epoch
-               let source_date_epoch = "";
-               await exec("git", ["show", "--no-patch", "--format=%ct", 
"HEAD"], {
-                       listeners: {
-                               stdout: (data) => { source_date_epoch += 
data.toString().trim(); }
-                       }
-               });
+               const git_show_output = await getExecOutput("git", ["show", 
"--no-patch", "--format=%ct", "HEAD"]);
+               const source_date_epoch = git_show_output.stdout.trim()
 
                // we are done with all the filesystem setup, we now export 
environment
                // variables, output variables, and state needed by the post 
script
diff --git a/actions/release-candidate/dist/post/index.js 
b/actions/release-candidate/dist/post/index.js
index 84cb73c..b48c00f 100644
--- a/actions/release-candidate/dist/post/index.js
+++ b/actions/release-candidate/dist/post/index.js
@@ -125512,7 +125512,7 @@ const fs = __nccwpck_require__(79896);
 const os = __nccwpck_require__(70857);
 const core = __nccwpck_require__(37484);
 const { DefaultArtifactClient } = __nccwpck_require__(76846)
-const { exec } = __nccwpck_require__(95236);
+const { exec, getExecOutput } = __nccwpck_require__(95236);
 
 // Sign and publish all release artifacts. If publishing is disabled, we just
 // upload all the release candidate artifacts as GitHub workflow artifacts.
@@ -125535,14 +125535,10 @@ async function run() {
                                if (artifact.name.endsWith(".rpm")) {
                                        await exec("rpmsign", ["--define", 
`_gpg_name ${ gpg_signing_key_id }`, "--define", "_binary_filedigest_algorithm 
10", "--addsign", `${ artifact.parentPath }/${ artifact.name }`]);
                                }
-                               let checksum = "";
-                               await exec("sha512sum", ["--binary", 
artifact.name], {
-                                       cwd: artifact.parentPath,
-                                       listeners: {
-                                               stdout: (data) => { checksum += 
data.toString(); }
-                                       }
+                               const shasum_output = await 
getExecOutput("sha512sum", ["--binary", artifact.name], {
+                                       cwd: artifact.parentPath
                                });
-                               fs.appendFileSync(`${ artifact.parentPath }/${ 
artifact.name }.sha512`, checksum);
+                               fs.appendFileSync(`${ artifact.parentPath }/${ 
artifact.name }.sha512`, shasum_output.stdout);
                                await exec("gpg", ["--default-key", 
gpg_signing_key_id, "--batch", "--yes", "--detach-sign", "--armor", "--output", 
`${ artifact.name }.asc`, artifact.name], {
                                        cwd: artifact.parentPath
                                });
@@ -125563,16 +125559,10 @@ async function run() {
                        const public_key_file = `${ release_dir 
}/public-key.asc`;
                        // if publishing is disabled, store public key as 
artifact so it can be downloaded
                        // by the post step for verification
-                       let public_key = "";
-                       await exec("gpg", ["--armor", "--export", 
gpg_signing_key_id], {
-                               silent: true,
-                               listeners: {
-                                       stdout: (data) => {
-                                               public_key +=  data.toString();
-                                       }
-                               }
+                       const gpg_export_output = await getExecOutput("gpg", 
["--armor", "--export", gpg_signing_key_id], {
+                               silent: true
                        });
-                       fs.appendFileSync(`${ public_key_file }`, public_key);
+                       fs.appendFileSync(`${ public_key_file }`, 
gpg_export_output.stdout);
 
                        const svn_artifacts = fs.readdirSync(artifact_dir, { 
recursive: true, withFileTypes: true });
                        const maven_artifacts = fs.readdirSync(`${ release_dir 
}/maven-local`, { recursive: true, withFileTypes: true });
diff --git a/actions/release-candidate/src/main.js 
b/actions/release-candidate/src/main.js
index 4747f42..5d25507 100644
--- a/actions/release-candidate/src/main.js
+++ b/actions/release-candidate/src/main.js
@@ -19,7 +19,7 @@ const fs = require("fs");
 const os = require("os");
 const core = require("@actions/core");
 const github = require("@actions/github");
-const { exec } = require('@actions/exec');
+const { exec, getExecOutput } = require('@actions/exec');
 const crypto = require("crypto");
 
 async function run() {
@@ -67,21 +67,15 @@ async function run() {
                }
 
                // Capture the key id of the most recent generated/imported key
-               let gpg_list_secret_keys_stdout = "";
-               await exec("gpg", ["--list-secret-keys", "--with-colons"], {
-                       silent: true,
-                       listeners: {
-                               stdout: (data) => {
-                                       gpg_list_secret_keys_stdout += 
data.toString();
-                               }
-                       }
+               const gpg_list_output = await getExecOutput("gpg", 
["--list-secret-keys", "--with-colons"], {
+                       silent: true
                });
-               const gpg_signing_key_id = gpg_list_secret_keys_stdout
+               const gpg_signing_key_id = gpg_list_output.stdout
                        .split('\n')
                        .findLast(l => l.startsWith("fpr"))
                        .split(':')[9];
 
-               console.info("Using gpgp key id: " + gpg_signing_key_id);
+               console.info("Using gpg key id: " + gpg_signing_key_id);
 
                // figure out the release version. This should follow the 
pattern
                // 'v<VERSION>-rcX', where <VERSION> is the value from the 
VERSION file
@@ -103,17 +97,11 @@ async function run() {
                        if (do_publish) {
                                // if publishing, tags must be signed with a 
committers key, download and import committer
                                // keys for verification
-                               let committer_keys = "";
-                               await exec("curl", 
[`https://downloads.apache.org/${tlp_dir}/KEYS`], {
-                                       silent: true,
-                                       listeners: {
-                                               stdout: (data) => {
-                                                       committer_keys += 
data.toString();
-                                               }
-                                       }
+                               const curl_output = await getExecOutput("curl", 
[`https://downloads.apache.org/${tlp_dir}/KEYS`], {
+                                       silent: true
                                });
                                await exec("gpg", ["--batch", "--import"], {
-                                       input: Buffer.from(committer_keys)
+                                       input: Buffer.from(curl_output.stdout)
                                });
 
                                // make sure the tag is signed by a committer 
in the KEYS file, this
@@ -227,12 +215,8 @@ async function run() {
                await exec("git", ["archive", "--format=zip", `--prefix=${ 
src_artifact_name }/`, "--output", `${ src_artifact_dir }/${ src_artifact_name 
}.zip`, "HEAD"]);
 
                // get the reproducible build epoch
-               let source_date_epoch = "";
-               await exec("git", ["show", "--no-patch", "--format=%ct", 
"HEAD"], {
-                       listeners: {
-                               stdout: (data) => { source_date_epoch += 
data.toString().trim(); }
-                       }
-               });
+               const git_show_output = await getExecOutput("git", ["show", 
"--no-patch", "--format=%ct", "HEAD"]);
+               const source_date_epoch = git_show_output.stdout.trim()
 
                // we are done with all the filesystem setup, we now export 
environment
                // variables, output variables, and state needed by the post 
script
diff --git a/actions/release-candidate/src/post.js 
b/actions/release-candidate/src/post.js
index 45663b8..60055e2 100644
--- a/actions/release-candidate/src/post.js
+++ b/actions/release-candidate/src/post.js
@@ -19,7 +19,7 @@ const fs = require("fs");
 const os = require("os");
 const core = require("@actions/core");
 const { DefaultArtifactClient } = require('@actions/artifact')
-const { exec } = require('@actions/exec');
+const { exec, getExecOutput } = require('@actions/exec');
 
 // Sign and publish all release artifacts. If publishing is disabled, we just
 // upload all the release candidate artifacts as GitHub workflow artifacts.
@@ -42,14 +42,10 @@ async function run() {
                                if (artifact.name.endsWith(".rpm")) {
                                        await exec("rpmsign", ["--define", 
`_gpg_name ${ gpg_signing_key_id }`, "--define", "_binary_filedigest_algorithm 
10", "--addsign", `${ artifact.parentPath }/${ artifact.name }`]);
                                }
-                               let checksum = "";
-                               await exec("sha512sum", ["--binary", 
artifact.name], {
-                                       cwd: artifact.parentPath,
-                                       listeners: {
-                                               stdout: (data) => { checksum += 
data.toString(); }
-                                       }
+                               const shasum_output = await 
getExecOutput("sha512sum", ["--binary", artifact.name], {
+                                       cwd: artifact.parentPath
                                });
-                               fs.appendFileSync(`${ artifact.parentPath }/${ 
artifact.name }.sha512`, checksum);
+                               fs.appendFileSync(`${ artifact.parentPath }/${ 
artifact.name }.sha512`, shasum_output.stdout);
                                await exec("gpg", ["--default-key", 
gpg_signing_key_id, "--batch", "--yes", "--detach-sign", "--armor", "--output", 
`${ artifact.name }.asc`, artifact.name], {
                                        cwd: artifact.parentPath
                                });
@@ -70,16 +66,10 @@ async function run() {
                        const public_key_file = `${ release_dir 
}/public-key.asc`;
                        // if publishing is disabled, store public key as 
artifact so it can be downloaded
                        // by the post step for verification
-                       let public_key = "";
-                       await exec("gpg", ["--armor", "--export", 
gpg_signing_key_id], {
-                               silent: true,
-                               listeners: {
-                                       stdout: (data) => {
-                                               public_key +=  data.toString();
-                                       }
-                               }
+                       const gpg_export_output = await getExecOutput("gpg", 
["--armor", "--export", gpg_signing_key_id], {
+                               silent: true
                        });
-                       fs.appendFileSync(`${ public_key_file }`, public_key);
+                       fs.appendFileSync(`${ public_key_file }`, 
gpg_export_output.stdout);
 
                        const svn_artifacts = fs.readdirSync(artifact_dir, { 
recursive: true, withFileTypes: true });
                        const maven_artifacts = fs.readdirSync(`${ release_dir 
}/maven-local`, { recursive: true, withFileTypes: true });

Reply via email to