Skip to content

Commit c4e1a5e

Browse files
authored
Add GitHub workflow for checking code format (manatee-project#46)
This PR solves manatee-project#17 Add an Action to enforce Go code formatting using `gofmt` and block unformatted code. This PR intentionally excludes lint since it requires external dependencies. It also intentionally doesn't auto-commit formatted code on push, as preferences vary. #### Changes - **Workflow**: `lint.yaml` checks formatting using `gofmt`. Named "lint.yaml" instead of "check-format.yaml" because it's meant to be extended in the future. #### Future Improvements 1. Consider other lint options such as line length, typo, and case-consistency. 2. Consider auto-committing format/lint fixes after making a PR. #### Usage - **Locally**: - Run `bazelisk run @go_sdk//:bin/gofmt -- -w .` - **CI/CD**: - Runs on `pull_request`.
1 parent 07c8eef commit c4e1a5e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

.github/workflows/lint.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on:
2+
pull_request:
3+
branches: [main]
4+
jobs:
5+
format:
6+
name: Enforce Code Format
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Check out code
10+
uses: actions/checkout@v4
11+
- name: Set up Bazel
12+
uses: bazel-contrib/setup-bazel@0.9.0
13+
with:
14+
bazelisk-cache: true
15+
disk-cache: ${{ github.workflow }}
16+
repository-cache: true
17+
- name: Check code format
18+
run: |
19+
bazelisk run @go_sdk//:bin/gofmt -- -l . > gofmt_output.txt || true
20+
if [ -s gofmt_output.txt ]; then
21+
echo "Following files are not properly formatted:"
22+
cat gofmt_output.txt
23+
echo "Please run: bazelisk run @go_sdk//:bin/gofmt -- -w ."
24+
exit 1
25+
else
26+
echo "All files are properly formatted!"
27+
fi
28+

0 commit comments

Comments
 (0)