-
-
Notifications
You must be signed in to change notification settings - Fork 746
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
Use shellcheck (via pantsbuild) #5751
Conversation
1729d45
to
36de7b0
Compare
shell_sources( | ||
overrides={ | ||
"random2.sh": {"skip_shellcheck": True}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a very simple way I could show off the overrides
feature of pants.
random.sh
passes shellcheck, but random2.sh
does not. This way we skip running shellcheck on as few files as possible.
python_sources( | ||
sources=["*.py", "st2*", "!st2ctl", "!st2-self-check", "!st2-run-pack-tests"], | ||
) | ||
|
||
shell_sources( | ||
name="shell", | ||
sources=["st2ctl", "st2-self-check", "st2-run-pack-tests"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice how I've got the st2*
glob on python_sources
.
That would match the files from shell_sources
, so we exclude them from matching using !
.
36de7b0
to
81d053c
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Most of the shell_source(s) targets were created with `./pants tailor ::`. That missed a few of our scripts that do not have a `.sh` extension, as well as a few executable python scripts that did not have a `.py` extension, so we let pants know about them.
This excludes some scripts from shellcheck because they weren't linted previously. We can clean them up in one or more follow-up PRs and remove `skip_shellcheck=True` from the relevant BUILD targets to re-enable shellcheck for those files.
81d053c
to
beae45f
Compare
You can see the shellcheck run in CI here: https://github.com/StackStorm/st2/actions/runs/3211491875/jobs/5249698302 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment, just to check todo is still relevant. But if so, then ok from me to merge.
@@ -1 +1,3 @@ | |||
# TODO: what to do about st2-migrate-db-dict-field-values ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to be resolved in another PR? Just checking this TODO is still relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. The TODO is still relevant. I'm not sure how best to handle the symlink - so I'm punting. 🤷
Background
This is another part of introducing
pants
, as discussed in the TSC Meetings on 12 July 2022, 02 Aug 2022, 06 Sept 2022, and 04 Oct 2022. Pants has fine-grained per-file caching of results for lint, fmt (like black), test, etc. It also has lockfiles that work well for monorepos that have multiple python packages. With these lockfiles CI should not break when any of our dependencies or our transitive dependencies release new versions, because CI will continue to use the locked version until we explicitly relock with updates.To keep PRs as manageable/reviewable as possible, introducing pants will take a series of PRs. I do not know yet how many PRs; I will break this up into logical steps with these goals:
pants
to the st2 repo, andpants
step-by-step.Other pants PRs include:
pants_ignore
and bump pants to v2.14.0rc1 #5733BUILD
files with./pants tailor ::
#5738Overview of this PR
It is helpful to review each commit in this PR individually.
BUILD
files with./pants tailor ::
#5738, tailor added a lot of metadata, but it could not identify some of our extension-less scripts as shell or python.bin/
directories).*.sh
.[GLOBAL].backend_packages
).shell_sources
andshell_source
targets../pants lint ::
will run shellcheck on all files in thoseshell_source
/s
targets.scripts/ci/*.sh
,scripts/github/*.sh
, andscripts/*.sh
.overrides
: a fairly new--and awesome--feature in pants.Relevant Pants documentation
./pants lint
goalpython_source
shell_source
python_sources
overrides
fieldshell_sources
overrides
fieldoverrides
field in the linters/formatters docsThings you can do with pantsbuild
This is the first PR that adds a
lint
backend. So, now you can run./pants lint ::
(the same command that the new GHA Lint workflow runs).You could do something like
./pants lint scripts/*.sh
if you only want to lint some of our scripts.That looks like this:
To see the shellcheck errors for a skipped file--I'll use
st2common/bin/st2ctl
for example--I commented out theskip_shellcheck=True,
line in the BUILD file. That shows what output looks like for failures: