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

ci: add shell linting workflow #50

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

grische
Copy link
Contributor

@grische grische commented Nov 17, 2023

A proposal to add some shell linting as there are quite some shell scripts in this repository.

@grische grische marked this pull request as ready for review November 18, 2023 18:06
Copy link
Member

@maurerle maurerle left a comment

Choose a reason for hiding this comment

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

As this affects more than the packages I am responsible off, I think at least someone else should be aware and approve this change?

I think it is quite good

@grische
Copy link
Contributor Author

grische commented Nov 19, 2023

Yeah, this will cause a considerable amount of warnings/errors the next time someone touches a shell script. I can go ahead and fix (most of) them if needed beforehand.

@herbetom
Copy link
Contributor

Is there a link where one can see which scripts (in which way) this will affect? I've got no idea wheter shellcheck is a fitting choice for this repo.

And yes, i think fixing those scripts should be done beforehand and not by the next person who finds themself in the unfortunate situation to trigger that workflow ;)

@grische
Copy link
Contributor Author

grische commented Nov 20, 2023

Shellcheck helped me identify a range of bugs in the ssid-changer script, so I do think that it is a helpful addition in general.

You can run this command locally, that roughly does what the action does:

shellcheck $(find . -type f -print0 | xargs -0 awk 'FNR==1 && /^#!.*sh/ { print FILENAME }')

@maurerle
Copy link
Member

I did run:

shellcheck -f diff $(find . -type f ! -path './.git/*' -print0 | xargs -0 awk 'FNR==1 && /^#!.*sh/ { sub(/^.{2}/, "", FILENAME); print FILENAME }') | git apply

to auto fix some issues - but most have to be solved manually.

There are still a lot here: shellcheck $(find . -type f -print0 | xargs -0 awk 'FNR==1 && /^#!.*sh/ { print FILENAME }')
I think some are quite verbose like
^-- SC3014 (warning): In POSIX sh, == in place of = is undefined.
SC1091 (info): Not following: /lib/gluon/autoupdater/lib.sh was not specified as input
^-------^ SC2034 (warning): USE_PROCD appears unused. Verify use (or export if used externally).

and the like.. I don't think that it is beneficial to have a lot of shellcheck workarounds though :D
Do you have a neat solution for this? @grische just ignore SC2034 for example?

@grische
Copy link
Contributor Author

grische commented Nov 20, 2023

Added exemplary PRs that fix the shellcheck issues in the ffac-ssid-changer package:

@grische
Copy link
Contributor Author

grische commented Nov 20, 2023

Regarding ^-- SC3014 (warning): In POSIX sh, == in place of = is undefined., this is a real warning, as this does not work across multiple shells:

ash

X=1
[ $X = 1 ]
[ $X == 1 ]
ash: 3: [: 1: unexpected operator

dash

X=1
[ $X = 1 ]
[ $X == 1 ]
dash: 3: [: 1: unexpected operator

ksh, bash or busybox sh

X=1
[ $X = 1 ]
[ $X == 1 ]

Shellcheck has support for full bash, ksh and dash, but not the full set for busybox sh. It interprets busybox sh as ash and ash in turn as dash:
https://www.shellcheck.net/wiki/SC1071

@grische
Copy link
Contributor Author

grische commented Nov 22, 2023

I opened an issue with shellcheck to see if it can be improved for our use-case here:
koalaman/shellcheck#2865

@grische
Copy link
Contributor Author

grische commented Nov 28, 2023

@maurerle @herbetom @neocturne except the #61, all shellcheck issues should be resolved now and the CI passes at least on my local machine.

@grische grische merged commit 96264b0 into freifunk-gluon:master Dec 15, 2023
1 check passed
@grische grische deleted the feature/shellcheck branch December 15, 2023 16:25
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