Skip to content

Commit

Permalink
fix: Output and environment variables in the post step (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarampampam committed May 24, 2023
1 parent 84d3909 commit c762f8b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this package will be documented in this file.

The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].

## v1.2.1

### Fixed

- Commands execution output is now streamed to the action output, instead of being buffered and printed at the end of the action [#8]

[#8]:https://github.com/gacts/run-and-post-run/pull/8

## v1.2.0

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/post/index.js

Large diffs are not rendered by default.

32 changes: 14 additions & 18 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,27 @@ function joinMultilineCommands(commands) {
*/
async function runCommands(commands) {
/** @type {import('@actions/exec/lib/interfaces').ExecOptions} */
const options = {cwd: input.workingDirectory, env: process.env, silent: true}
const options = {
cwd: input.workingDirectory,
env: process.env,
silent: true,
listeners: {
stdline: (data) => core.info(data),
errline: (data) => core.info(data),
},
}

return (async () => {
for (const command of commands) {
if (command !== "") {
core.info(`\x1b[1m$ ${command}\x1b[0m`)

let output = input.shell === ""
? await exec.getExecOutput(command, [], options)
: await exec.getExecOutput(input.shell, ['-c', command], options)

output.stdout = output.stdout.trim()

if (output.stdout !== "") {
core.info(output.stdout)
}

output.stderr = output.stderr.trim()

if (output.stderr !== "") {
core.info(output.stderr)
}
let exitCode = input.shell === ""
? await exec.exec(command, [], options)
: await exec.exec(input.shell, ['-c', command], options)

if (output.exitCode !== 0) {
core.setFailed(`Command failed with exit code ${output.exitCode}`)
if (exitCode !== 0) {
core.setFailed(`Command failed with exit code ${exitCode}`)
}
}
}
Expand Down

0 comments on commit c762f8b

Please sign in to comment.