stefanzweifel / git-auto-commit-action

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.
MIT License
1.98k stars 227 forks source link

Update Shebang to point to /bin/sh #167

Closed stefanzweifel closed 3 years ago

stefanzweifel commented 3 years ago

Update shebang of entrypoint.sh to use /bin/sh instead of /bin/bash. This change allows users to use the Action in different environments (eg. when they use an alpine-container for a job)

Refs #166.

AnthonyPoschen commented 3 years ago

error still exists https://github.com/zanven42/workflow-debugger/runs/3042348923?check_suite_focus=true

AnthonyPoschen commented 3 years ago

suggest modifying this line to use sh not bash https://github.com/stefanzweifel/git-auto-commit-action/blob/053f35677462851d5d2eec5a9f6f052698c81d92/index.js#L27

stefanzweifel commented 3 years ago

Hm, seems it's still broken (?). Will take a closer look throughout the day.

stefanzweifel commented 3 years ago

Ok. I think I understand the problem now:

  1. /bin/sh and /bin/bash are not the same
  2. sh is a specification
  3. bash is an implementation of sh
  4. bash is like sh but has more features and a better syntax. some commands work differently though.

Sources on Stackoverflow


The error happens due do this line:

INPUT_COMMIT_OPTIONS_ARRAY=( $INPUT_COMMIT_OPTIONS );

sh doesn't support (?) expanding a string into an array by using ( $var ). My knowledge for writing scripts so far has been based on bash and not on sh. I couldn't figure online out what the real differences between bash and sh are. So porting entrypoint.sh to sh proper is quite difficult.

The errors im getting

Started: sh /home/runner/work/_actions/stefanzweifel/git-auto-commit-action/issue-166/entrypoint.sh
/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/issue-166/entrypoint.sh: 78: Syntax error: "(" unexpected (expecting "}")
Error: Invalid status code: 2
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/issue-166/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  code: 2
}

bash is available on all supported platforms of GitHub Actions (Linux, Windows and macOS). sh is only available on Linux and macOS. As I would like to support all platforms and not just the unix ones, switching to /bin/sh is counter productive (?).

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell


As I assume that most users are just using the out-of-the-box environment of GitHub Actions and not their own Docker Container/Images I think the effort to update the script to use no bash is currently not justified. I'm closing this PR for now.

If somebody with better knowledge about the differences between sh and bash wants to pick this up: Feel free to submit a new Pull Request.