Skip to content

Commit a924326

Browse files
Add formatting check to CI/CD (#2601)
## Changes <!-- Brief summary of your changes that is easy to understand --> 1. Add new steps to CI/CD workflow to check formatting issues 2. Introduce a new make target: fmtcheck, which allows to check formatting without writing changes to disk 3. Run auto formatter on existing files to make the check pass ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> With the migration to golangci-lint v2.x, we lost automatic checks of code formatters configured with it in `.golangci.yaml`. This PR restores these checks. ## Tests <!-- How have you tested the changes? --> Lint step is passing <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. --> --------- Co-authored-by: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com>
1 parent 7d97dbf commit a924326

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

.github/workflows/push.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,23 @@ jobs:
9696
run: |
9797
# Exit with status code 1 if there are differences (i.e. unformatted files)
9898
git diff --exit-code
99-
- name: golangci-lint
99+
- name: Run Go lint checks (does not include formatting checks)
100100
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
101101
with:
102102
version: v2.0.2
103103
args: --timeout=15m
104-
- name: Run ruff
104+
- name: Run ruff (Python linter and formatter)
105105
uses: astral-sh/ruff-action@f14634c415d3e63ffd4d550a22f037df4c734a60 # v3.1.0
106106
with:
107107
version: "0.9.1"
108108
args: "format --check"
109+
- name: Run formatting (does not include linting checks)
110+
run: |
111+
make fmt
112+
- name: Fail on formatting differences
113+
run: |
114+
# Exit with status code 1 if there are differences (i.e. unformatted files)
115+
git diff --exit-code
109116
- name: Run whitespace check
110117
run: python tools/validate_whitespace.py
111118

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ tidy:
1616
lintcheck:
1717
golangci-lint run ./...
1818

19-
# Note 'make lint' will do formatting as well. However, if there are compilation errors,
20-
# formatting/goimports will not be applied by 'make lint'. However, it will be applied by 'make fmt'.
21-
# If you need to ensure that formatting & imports are always fixed, do "make fmt lint"
2219
fmt:
2320
ruff format -qn
2421
golangci-lint fmt

bundle/internal/tf/codegen/schema/generate.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func (s *Schema) writeTerraformBlock(_ context.Context) error {
18-
var body = map[string]any{
18+
body := map[string]any{
1919
"terraform": map[string]any{
2020
"required_providers": map[string]any{
2121
"databricks": map[string]any{
@@ -31,12 +31,12 @@ func (s *Schema) writeTerraformBlock(_ context.Context) error {
3131
return err
3232
}
3333

34-
return os.WriteFile(filepath.Join(s.WorkingDir, "main.tf.json"), buf, 0644)
34+
return os.WriteFile(filepath.Join(s.WorkingDir, "main.tf.json"), buf, 0o644)
3535
}
3636

3737
func (s *Schema) installTerraform(ctx context.Context) (path string, err error) {
3838
installDir := filepath.Join(s.WorkingDir, "bin")
39-
err = os.MkdirAll(installDir, 0755)
39+
err = os.MkdirAll(installDir, 0o755)
4040
if err != nil {
4141
return
4242
}
@@ -82,7 +82,7 @@ func (s *Schema) generateSchema(ctx context.Context, execPath string) error {
8282
return err
8383
}
8484

85-
return os.WriteFile(s.ProviderSchemaFile, buf, 0644)
85+
return os.WriteFile(s.ProviderSchemaFile, buf, 0o644)
8686
}
8787

8888
func (s *Schema) Generate(ctx context.Context) error {

bundle/internal/tf/codegen/schema/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func New() (*Schema, error) {
2525
}
2626

2727
tmpdir := filepath.Join(wd, "./tmp")
28-
err = os.MkdirAll(tmpdir, 0755)
28+
err = os.MkdirAll(tmpdir, 0o755)
2929
if err != nil {
3030
return nil, err
3131
}

0 commit comments

Comments
 (0)