Skip to content

Inline scripts executed via bash or sh #2896

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

Merged
merged 20 commits into from
Jun 13, 2025
Merged

Inline scripts executed via bash or sh #2896

merged 20 commits into from
Jun 13, 2025

Conversation

shreyas-goenka
Copy link
Contributor

@shreyas-goenka shreyas-goenka commented May 16, 2025

Changes

This PR inlines the script content using the -c flag in bash and sh instead of passing them in via -e <file>.

Why

Based on discussion in #2862 (comment). Getting rid of the temp file means we no longer have to clean up the temporary file created.

Tests

Tests that were added in: #2884

@shreyas-goenka shreyas-goenka changed the base branch from main to add-shell-test May 16, 2025 13:01
@shreyas-goenka shreyas-goenka changed the title inline script sh Inline scripts executed via bash or sh May 16, 2025
@shreyas-goenka shreyas-goenka marked this pull request as ready for review May 16, 2025 13:05
@shreyas-goenka shreyas-goenka marked this pull request as draft May 16, 2025 13:11
@shreyas-goenka shreyas-goenka changed the base branch from add-shell-test to main May 22, 2025 13:00
@shreyas-goenka shreyas-goenka marked this pull request as ready for review May 23, 2025 06:37
@shreyas-goenka shreyas-goenka changed the base branch from main to add-shell-test May 23, 2025 06:40
@shreyas-goenka shreyas-goenka marked this pull request as draft May 23, 2025 06:40
Base automatically changed from add-shell-test to main June 6, 2025 14:30
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestShellExecvOpts(t *testing.T) {
newOpts, err := shellExecvOpts("echo hello", "/a/b/c", []string{"key1=value1", "key2=value2"})
opts, err := shellExecvOpts("echo hello", "/a/b/c", []string{"key1=value1", "key2=value2"})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo fix, newOpts -> opts

@@ -117,7 +117,11 @@ func TestExecutorNoShellFound(t *testing.T) {
}

func TestExecutorCleanupsTempFiles(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only cmd.exe cleans up temp files. Other shells now do not create temp files.

@shreyas-goenka shreyas-goenka marked this pull request as ready for review June 12, 2025 14:32
@shreyas-goenka shreyas-goenka added this pull request to the merge queue Jun 13, 2025
Merged via the queue into main with commit b98ab5a Jun 13, 2025
10 checks passed
@shreyas-goenka shreyas-goenka deleted the inline-script-sh branch June 13, 2025 09:45
@pietern
Copy link
Contributor

pietern commented Jun 16, 2025

@shreyas-goenka Are there functional or behavioral differences between these execution modes that you know of?

@shreyas-goenka
Copy link
Contributor Author

@pietern There is only one minor difference I found. Positional arguments (like $0) work for bash <file> but do not work for `bash -c "". This is not a concern for us since it's only used in the experimental scripts section and for artifact build commands where you can't provide positional arguments to the command (and which are expected to be simple scripts anyways).

I did not find any differences in the execution environment itself though. We also have coverage for some common patterns in #2884.

Thanks for flagging, I just noticed a mistake I made. Since we stopped setting the -e flag the command will not exit at the first error. I'll send a PR to fix this.

@pietern
Copy link
Contributor

pietern commented Jun 16, 2025

@shreyas-goenka Thanks. Our docs don't mention anything specifically about how the build command is executed, but it does mention the double ampersand (&&) to run multiple commands here.

That can be updated to include line-separation, correct?

@shreyas-goenka
Copy link
Contributor Author

shreyas-goenka commented Jun 16, 2025

That can be updated to include line-separation, correct?

@pietern yes. We have coverage for multiline commands in: #2884

github-merge-queue bot pushed a commit that referenced this pull request Jun 17, 2025
## Changes
This PR fixes a regression introduced in
#2896 where we stopped passing the
`-e` flag to the shell, which makes both sh and bash bail out at the
first command with a non-zero exit code.

## Why
Adding back `-e` keeps the behaviour consistent with the one before
#2896 was introduced.

## Tests
Newly added regression tests
@pietern
Copy link
Contributor

pietern commented Jun 17, 2025

@shreyas-goenka I mean they can be updated in the docs. They mention && for composing commands here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants