openwrt / gh-action-sdk

GitHub CI action to build packages via SDK
30 stars 48 forks source link

abort in initscripts shfmt check when no git repo #37

Open azrdev opened 4 months ago

azrdev commented 4 months ago

My CI runs abort due to git diff returning 128 (and printing its --help message) from the two invocations in https://github.com/openwrt/gh-action-sdk/blob/9c3ea37/entrypoint.sh#L141 GH action output:

[...]
  time: package/feeds/action/snapcast/check#0.01#0.00#0.02
  make[1]: Leaving directory '/builder'
find: ‘shfmt’: No such file or directory
find: ‘shfmt’: No such file or directory
warning: Not a git repository. Use --no-index to compare two paths outside a working tree
usage: git diff --no-index [<options>] <path> <path>
[...]
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
init script must be formatted. Please run through shfmt -w -sr -s
Error: Process completed with exit code 128.
Run sudo chown -R --reference=/home/runner/work/snapos/snapos/.. /home/runner/work/snapos/snapos

code at https://github.com/azrdev/snapos/tree/4dedda34e9e23f8134fe30ef8879d220f725a315

I think what happens is that the package download fetches a tarball from github instead of a git clone / local checkout, and thus git -C .../files diff cannot find a .git dir -- and exits.

To fix, maybe there already is a marker telling if the code was checked out from a repo, and only enable the checks relying on git diff if that's true.