Skip to content

Conversation

@cognifloyd
Copy link
Member

@cognifloyd cognifloyd commented Mar 16, 2025

This PR is working towards doing packaging via pantsbuild. Eventually, I hope to archive and stop using st2-packages.git.

The inconsistent formatting makes it harder to compare deb vs rpm scripts. At first I reformatted manually, but that will get lost quickly as we all make improvements. So, I added shfmt to format deb maintainer scripts / rpm scriptlets. To enable it I added the shfmt backend to [GLOBAL].backend_packages in pants.toml.

st2/pants.toml

Line 29 in 08fd2ba

"pants.backend.shell.lint.shfmt",

I want to keep this PR focused on packaging, so I added skip_shfmt=True to all the BUILD metadata for shell scripts that would be reformatted (other than packaging/{rpm,deb}/scripts/*.sh. Someone else can remove those skip_shfmt parameters to enable formatting other shell scripts.

shfmt does not have a lot of options for formatting. I changed 2 of them:

st2/pants.toml

Lines 240 to 245 in 08fd2ba

[shfmt]
args = [
# https://github.com/mvdan/sh/blob/master/cmd/shfmt/shfmt.1.scd#printer-flags
"--indent=4", # default is 0 (use tabs)
"--case-indent",
]

Most of our shell scripts use spaces instead of tabs for indentation. Some have 2 spaces while others have 4. I went with 4 for now (--indent=4). We can change it later if that proves annoying. I just want consistency.

All of our shell scripts indent case statements (though the indent size is inconsistent), so I enabled the --case-indent option as well. The formatting is a little different than I normally use, but it is at least consistent.

disable it for all other scripts that would be reformatted.
Someone can reenable it and run it on files later.
@cognifloyd cognifloyd added this to the pants milestone Mar 16, 2025
@cognifloyd cognifloyd self-assigned this Mar 16, 2025
@pull-request-size pull-request-size bot added the size/L PR that changes 100-499 lines. Requires some effort to review. label Mar 16, 2025
@nzlosh
Copy link
Contributor

nzlosh commented Mar 16, 2025

Good initiative to formatting shell code. There are shell script that are all over the place at the moment. 👍

@cognifloyd cognifloyd marked this pull request as ready for review March 16, 2025 17:01
@cognifloyd cognifloyd requested review from a team, amanda11, guzzijones, rush-skills and winem March 16, 2025 17:01
@cognifloyd cognifloyd enabled auto-merge March 16, 2025 17:02
@cognifloyd cognifloyd merged commit df55287 into master Mar 18, 2025
119 of 122 checks passed
@cognifloyd cognifloyd deleted the packaging-scriptlets_fmt branch March 18, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance pantsbuild size/L PR that changes 100-499 lines. Requires some effort to review. st2-packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants