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

chore(#8557): add linting for shell scripts #9142

Merged
merged 6 commits into from
Jun 5, 2024
Merged

Conversation

nydr
Copy link
Contributor

@nydr nydr commented May 23, 2024

Description

Adds linting to shell script and update scripts to pass, there's some cases where this could change the functionality so pay extra attention to the sections of the script relying on unexpected behavior

per #8557

Affected bash scripts - please check off when you have confirmed they work with the additions in this PR:

  • .husky/pre-commit - just has #shellcheck comment
  • couchdb/docker-entrypoint.sh - just has #shellcheck comment
  • nginx/ssl-install.sh
  • nginx/tests/ssl-install.bats
  • scripts/add-local-ip-certs-to-docker-4.x.sh
  • scripts/build/blank-link-check.sh
  • scripts/ci/list-shellscripts.sh
  • scripts/compress_and_archive_docker_logs.sh
  • scripts/deploy/cht-deploy - just has #shellcheck comment
  • scripts/deploy/troubleshooting/describe-deployment
  • scripts/deploy/troubleshooting/list-all-resources
  • scripts/deploy/troubleshooting/list-deployments
  • scripts/deploy/troubleshooting/restart-deployment
  • scripts/deploy/troubleshooting/view-logs
  • scripts/docker-helper-4.x/cht-docker-compose.sh - fixed in a025cd9 74a9368 cd709da
  • scripts/docker-helper/cht-docker-compose.sh
  • scripts/docker-helper/docker-status.sh
  • tests/integration/haproxy/keep-alive-script/cmd.sh
  • tests/scalability/prepare-ec2.sh
  • tests/scalability/run_suite.sh
  • tests/scalability/start-ec2-cht.sh

Code review checklist

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

Compose URLs

If Build CI hasn't passed, these may 404:

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@nydr nydr changed the title feat(#8557) Add linting for shell scripts feat(#8557): Add linting for shell scripts May 23, 2024
@nydr nydr changed the title feat(#8557): Add linting for shell scripts feat(#8557): add linting for shell scripts May 23, 2024
pull_request:
paths:
- '**/*.bats'
- '**/*.sh'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not convinced conditional run is the right thing to do here as it only takes 30 sec including install step, but I'm hesitant to add another dependency on the main test since it's already fairly cluttered.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be part of the npm run lint command so devs just run one command and everything is linted, but it would be a shame to add more to the dev environment setup requirements. There is an npm package that might be useful to do the installation for us. Might be worth looking in to...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good suggestion, I'm also making use of shfmt to list all shell scripts which is needed for shellcheck to find and test those files. I can't use *.sh and *.bats since not all of them have those extensions, but something like

for f in $(git ls-files); do
    head -n1 $f | egrep -q '#!/bin/(ba)?sh' && echo $f;
done

might work as an alternative
(also need to consider scripts with /usr/bin/env bash and *.bats extensions so not exactly this script)

@garethbowen garethbowen changed the title feat(#8557): add linting for shell scripts chore(#8557): add linting for shell scripts May 23, 2024
@garethbowen
Copy link
Member

Changed the PR to "chore" not "feat" as it's not a feature from an end user perspective.

@nydr
Copy link
Contributor Author

nydr commented May 30, 2024

PR updated with adding shellcheck npm package dependency as suggested and replacing the usage of shfmt with a shell script for listing files to test, I considered using js, but didn't want start a project of manually parsing .gitignore or .git/objects with git worktrees at this point

Feel free to take over this PR if anyone has the bandwith as I'm unlikely be able to update in the foreseeable future. Keep in mind that it is technically changing the behaviour of ~22 scripts with low to no related tests even if most of these behaviour changes are unlikely to be hit and if they were the previous behaviour is most likely the undesired one

Copy link
Member

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

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

Thank you! This has been bugging me for some time.

I agree there are risks with existing scripts but we probably won't find any bugs until we merge so I vote we go for it.

@mrjones-plip I'll wait for you to you review too to make sure you concur!

@mrjones-plip
Copy link
Contributor

While I do concur - and think this is worthwhile effort - we're touching a LOT of scripts. I think we should smoke test each script that got updated - skipping any that will hit CI right away that might be hard to trigger locally.

I'll grab this next week!

Copy link
Contributor

@mrjones-plip mrjones-plip left a comment

Choose a reason for hiding this comment

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

after a careful review, and some fix-it commits since nydr isn't working on this anymore, this is good to go!

@mrjones-plip mrjones-plip merged commit 9879478 into master Jun 5, 2024
40 checks passed
@mrjones-plip mrjones-plip deleted the 8557-shellcheck branch June 5, 2024 23:35
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.

None yet

3 participants