fix!: fallback to sh if bash does not exist #177

Merged
earl-warren merged 2 commits from earl-warren/act:wip-sh-fallback into main 2025-07-13 15:59:34 +00:00
Contributor

It is a breaking change because it changes how the shell is determined.

Before, if jobs.<job_id>.container.image is set and the shell is not specified, it defaults to sh instead of bash.

After, regardless of jobs.<job_id>.container.image, if the shell is not specified, it defaults to bash if available, otherwise it defaults to sh.

Tests run at https://code.forgejo.org/forgejo/act/actions/runs/963/jobs/1#jobstep-4-2333

Closes forgejo/runner#150

It is a breaking change because it changes how the shell is determined. Before, if `jobs.<job_id>.container.image` is set and the shell is not specified, it defaults to `sh` instead of `bash`. After, regardless of `jobs.<job_id>.container.image`, if the shell is not specified, it defaults to `bash` if available, otherwise it defaults to `sh`. Tests run at https://code.forgejo.org/forgejo/act/actions/runs/963/jobs/1#jobstep-4-2333 Closes forgejo/runner#150
earl-warren force-pushed wip-sh-fallback from 39f64b89a7
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 2m4s
checks / integration (pull_request) Successful in 1m6s
to 84cff685c8
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 1m59s
checks / integration (pull_request) Successful in 59s
2025-07-12 06:26:02 +00:00
Compare
earl-warren force-pushed wip-sh-fallback from 84cff685c8
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 1m59s
checks / integration (pull_request) Successful in 59s
to 6019db7381
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 2m1s
checks / integration (pull_request) Successful in 1m20s
2025-07-12 06:26:51 +00:00
Compare
earl-warren force-pushed wip-sh-fallback from 6019db7381
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 2m1s
checks / integration (pull_request) Successful in 1m20s
to 4b7f0e93e9
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 1m21s
checks / integration (pull_request) Successful in 2m9s
2025-07-12 09:06:36 +00:00
Compare
earl-warren changed title from WIP: fix!: fallback to sh if bash does not exist [skip cascade] to fix!: fallback to sh if bash does not exist [skip cascade] 2025-07-12 09:11:15 +00:00
@ -199,1 +197,3 @@
step.Shell = "sh"
} else {
shell_fallback := `
if which bash >/dev/null 2>/dev/null; then

which is probably good enough, though the POSIX way would be command -v

`which` is probably good enough, though the POSIX way would be `command -v`
Author
Contributor

I confess I did not know about this:

       command [-pVv] command [arg ...]
              Run  command  with  args  suppressing  the normal shell function
              lookup.  Only builtin commands or commands found in the PATH are
              executed.  If the -p option is given, the search for command  is
              performed  using  a default value for PATH that is guaranteed to
              find all of the standard utilities.  If either the -V or -v  op‐
              tion  is  supplied, a description of command is printed.  The -v
              option causes a single word indicating the command  or  filename
              used to invoke command to be displayed; the -V option produces a
              more  verbose  description.  If the -V or -v option is supplied,
              the exit status is 0 if command was found, and  1  if  not.   If
              neither option is supplied and an error occurred or command can‐
              not  be found, the exit status is 127.  Otherwise, the exit sta‐
              tus of the command builtin is the exit status of command.
I confess I did not know about this: ``` command [-pVv] command [arg ...] Run command with args suppressing the normal shell function lookup. Only builtin commands or commands found in the PATH are executed. If the -p option is given, the search for command is performed using a default value for PATH that is guaranteed to find all of the standard utilities. If either the -V or -v op‐ tion is supplied, a description of command is printed. The -v option causes a single word indicating the command or filename used to invoke command to be displayed; the -V option produces a more verbose description. If the -V or -v option is supplied, the exit status is 0 if command was found, and 1 if not. If neither option is supplied and an error occurred or command can‐ not be found, the exit status is 127. Otherwise, the exit sta‐ tus of the command builtin is the exit status of command. ```
Author
Contributor

You suggest replacing with if command -v bash; then?

You suggest replacing with `if command -v bash; then`?
Author
Contributor
https://code.forgejo.org/forgejo/act/compare/4e25206774496101b87eef3d49c359da8db9c9c0..bf530e002edd932e5a784e06a09b7d8475c94068
earl-warren marked this conversation as resolved
earl-warren force-pushed wip-sh-fallback from 4b7f0e93e9
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 1m21s
checks / integration (pull_request) Successful in 2m9s
to 4e25206774
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 2m4s
checks / integration (pull_request) Successful in 1m51s
2025-07-12 10:03:17 +00:00
Compare
earl-warren force-pushed wip-sh-fallback from 4e25206774
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 2m4s
checks / integration (pull_request) Successful in 1m51s
to bf530e002e
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 1m27s
checks / integration (pull_request) Successful in 1m31s
2025-07-12 10:11:14 +00:00
Compare
earl-warren changed title from fix!: fallback to sh if bash does not exist [skip cascade] to fix!: fallback to sh if bash does not exist 2025-07-12 10:33:24 +00:00
earl-warren force-pushed wip-sh-fallback from bf530e002e
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 1m27s
checks / integration (pull_request) Successful in 1m31s
to 9628be0a7a
All checks were successful
checks / unit (pull_request) Successful in 1m54s
checks / integration (pull_request) Successful in 2m8s
/ cascade (pull_request_target) Successful in 33m0s
2025-07-12 10:33:41 +00:00
Compare
Contributor

cascading-pr updated at forgejo/runner#692

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/692
@ -589,0 +599,4 @@
env[k] = v
}
name := "throwaway-script.sh"

Should use a randomly generated name, e.g. like os.CreateTemp does, to avoid avenues of code injection when someone knows the file name.
Would also allow multiple to run in parallel, if that ever came up.

Should use a randomly generated name, e.g. like `os.CreateTemp` does, to avoid avenues of code injection when someone knows the file name. Would also allow multiple to run in parallel, if that ever came up.

sounds like a good idea

sounds like a good idea
Author
Contributor
https://code.forgejo.org/forgejo/act/compare/0fe66981cd7793d6afeeecdb9c6202ffb9e5124f..b937bc1f750a4b963e298fd32ff4fdb63d48fcd0
earl-warren marked this conversation as resolved
viceice left a comment
Owner

worried about the removed pwsh tests, that hould be done in a seperate pr with a description why.

otherwise LGTM

worried about the removed pwsh tests, that hould be done in a seperate pr with a description why. otherwise LGTM
@ -1,25 +0,0 @@
on: push
env:
MY_SHELL: pwsh

why removing all pwsh tests? too slow?

why removing all pwsh tests? too slow?
Author
Contributor

They require proprietary software (well, a mix of MIT and proprietary really).

They require proprietary software (well, [a mix of MIT and proprietary really](https://en.wikipedia.org/wiki/PowerShell)).
Author
Contributor

Hum....

On August 18, 2016, Microsoft announced[22] that they had made PowerShell open-source and cross-platform with support for Windows, macOS, CentOS and Ubuntu.[6] The source code was published on GitHub.[23] The move to open source created a second incarnation of PowerShell called "PowerShell Core", which runs on .NET Core. It is distinct from "Windows PowerShell", which runs on the full .NET Framework.[24] Starting with version 5.1, PowerShell Core is bundled with Windows Server 2016 Nano Server.[25][26]

Hum.... > On August 18, 2016, Microsoft announced[22] that they had made PowerShell open-source and cross-platform with support for Windows, macOS, CentOS and Ubuntu.[6] The source code was published on GitHub.[23] The move to open source created a second incarnation of PowerShell called "PowerShell Core", which runs on .NET Core. It is distinct from "Windows PowerShell", which runs on the full .NET Framework.[24] Starting with version 5.1, PowerShell Core is bundled with Windows Server 2016 Nano Server.[25][26]
Author
Contributor

@Crown0815 I'm confused there. Is there a Free Software version of pwsh that can be downloaded from somewhere that does not include proprietary components?

$ apt-cache search powershell
golang-github-zyedidia-clipper-dev - Cross-platform clipboard access in Go (library)
libperlude-perl - shell and powershell pipes, haskell keywords mixed with the awesomeness of perl
librust-output-vt100-dev - activate escape codes in Windows' CMD and PowerShell - Rust source code
python3-dcos - DCOS Common Modules - Python 3.x
python3-winrm - Python 3 library for Windows Remote Management
$ apt-cache search pwsh
$
@Crown0815 I'm confused there. Is there a Free Software version of pwsh that can be downloaded from somewhere that does not include proprietary components? ```sh $ apt-cache search powershell golang-github-zyedidia-clipper-dev - Cross-platform clipboard access in Go (library) libperlude-perl - shell and powershell pipes, haskell keywords mixed with the awesomeness of perl librust-output-vt100-dev - activate escape codes in Windows' CMD and PowerShell - Rust source code python3-dcos - DCOS Common Modules - Python 3.x python3-winrm - Python 3 library for Windows Remote Management $ apt-cache search pwsh $ ```
Author
Contributor
I see https://github.com/PowerShell/PowerShell/releases/tag/v7.5.2 and there is a .deb there.
First-time contributor
@earl-warren wrote in https://code.forgejo.org/forgejo/act/pulls/177#issuecomment-46899: > I see https://github.com/PowerShell/PowerShell/releases/tag/v7.5.2 and there is a .deb there. Just wanted to send you the link. This is it.
Author
Contributor

I will add the tests back.

I will add the tests back.
Author
Contributor

@viceice @Crown0815 adding them to the general purpose image used for CI seems sensible right now. Do you concur?

forgejo/ci-image-builder#6

@viceice @Crown0815 adding them to the general purpose image used for CI seems sensible right now. Do you concur? forgejo/ci-image-builder#6
sure, here's how I do it on Ubuntu https://github.com/containerbase/base/blob/a7d11772ea66112eeaff8a0ccbfb946b77fb94e6/src/usr/local/containerbase/tools/v2/powershell.sh
Author
Contributor

Restored and simplified pwsh tests.

9628be0a7a..64666db7b0

Restored and simplified pwsh tests. https://code.forgejo.org/forgejo/act/compare/9628be0a7ae16c5b36dd5eef58a0eac42cd4d56f..64666db7b038f4891fa0fc0d0d6fc2297d12d480
earl-warren marked this conversation as resolved
earl-warren referenced this pull request from a commit 2025-07-12 14:58:08 +00:00
earl-warren changed title from fix!: fallback to sh if bash does not exist to fix!: fallback to sh if bash does not exist [skip cascade] 2025-07-12 16:22:19 +00:00
earl-warren force-pushed wip-sh-fallback from 9628be0a7a
All checks were successful
checks / unit (pull_request) Successful in 1m54s
checks / integration (pull_request) Successful in 2m8s
/ cascade (pull_request_target) Successful in 33m0s
to 64666db7b0
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 2m14s
checks / integration (pull_request) Successful in 2m44s
2025-07-12 16:27:21 +00:00
Compare
earl-warren changed title from fix!: fallback to sh if bash does not exist [skip cascade] to fix!: fallback to sh if bash does not exist 2025-07-12 16:37:35 +00:00
earl-warren changed title from fix!: fallback to sh if bash does not exist to fix!: fallback to sh if bash does not exist [skip cascade] 2025-07-12 16:39:30 +00:00
earl-warren force-pushed wip-sh-fallback from 64666db7b0
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 2m14s
checks / integration (pull_request) Successful in 2m44s
to 0fe66981cd
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 2m3s
checks / integration (pull_request) Successful in 2m8s
2025-07-12 16:56:51 +00:00
Compare
earl-warren force-pushed wip-sh-fallback from 0fe66981cd
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 2m3s
checks / integration (pull_request) Successful in 2m8s
to b937bc1f75
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 1m43s
checks / integration (pull_request) Successful in 2m43s
2025-07-12 16:58:38 +00:00
Compare
Author
Contributor

As there was no function to create a random name in ACT, I added one in a separate commit and used it where code as duplicated. This should also be reviewed.

!177 (commit 1f841f15bb)

As there was no function to create a random name in ACT, I added one in a separate commit and used it where code as duplicated. This should also be reviewed. https://code.forgejo.org/forgejo/act/pulls/177/commits/1f841f15bb32175b9629d4843f2ed1af3cc68483
earl-warren changed title from fix!: fallback to sh if bash does not exist [skip cascade] to fix!: fallback to sh if bash does not exist 2025-07-12 17:01:02 +00:00
earl-warren force-pushed wip-sh-fallback from b937bc1f75
All checks were successful
/ cascade (pull_request_target) Has been skipped
checks / unit (pull_request) Successful in 1m43s
checks / integration (pull_request) Successful in 2m43s
to 92219f9e8f
Some checks failed
checks / unit (pull_request) Successful in 2m22s
checks / integration (pull_request) Successful in 2m40s
/ cascade (pull_request_target) Failing after 33s
2025-07-12 17:01:19 +00:00
Compare
Contributor

cascading-pr updated at forgejo/runner#692

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/692
@ -229,4 +229,1 @@
{workdir, "shells/defaults", "push", "", platforms, secrets},
// TODO: figure out why it fails
// {workdir, "shells/custom", "push", "", map[string]string{"ubuntu-latest": "catthehacker/ubuntu:pwsh-latest"}, }, // custom image with pwsh
{workdir, "shells/pwsh", "push", "", map[string]string{"ubuntu-latest": "catthehacker/ubuntu:pwsh-latest"}, secrets}, // custom image with pwsh

should we use our CI Image for these tests or doesn't change it anything for code coverage?

should we use our CI Image for these tests or doesn't change it anything for code coverage?
Author
Contributor

It changes nothing in this context. I assume this image is just ubuntu + pwsh as the name suggests and I don't see that it would change anything in term of coverage.

It changes nothing in this context. I assume this image is just ubuntu + pwsh as the name suggests and I don't see that it would change anything in term of coverage.
viceice marked this conversation as resolved
viceice approved these changes 2025-07-13 15:38:34 +00:00
earl-warren deleted branch wip-sh-fallback 2025-07-13 15:59:34 +00:00
Commenting is not possible because the repository is archived.
No reviewers
No milestone
No project
No assignees
5 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
forgejo/act!177
No description provided.