Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Output and environment variables in the post step #8

Merged
merged 6 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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