Skip to content

Commit ad877de

Browse files
committed
changes:
- ci runs on linux, macos and windows - ci runs on a pr to all version branches as well as main - ci formats and commits code
1 parent 301c715 commit ad877de

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ name: Go Build, Test, and Format
22

33
on:
44
push:
5-
branches: [main]
5+
branches:
6+
- main
7+
- 'v[0-9]+.[0-9]+.[0-9]+'
68
pull_request:
7-
branches: [main]
9+
branches:
10+
- main
11+
- 'v[0-9]+.[0-9]+.[0-9]+'
812

913
jobs:
10-
build-test-format:
11-
runs-on: ubuntu-latest
14+
build-test:
15+
name: Build and Test on ${{ matrix.os }}
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
matrix:
19+
os: [ubuntu-latest, macos-latest, windows-latest]
1220

1321
steps:
1422
- name: Checkout code
@@ -25,11 +33,30 @@ jobs:
2533
- name: Run Tests
2634
run: go test ./...
2735

28-
- name: Check gofmt
36+
format:
37+
name: Format on Linux
38+
runs-on: ubuntu-latest
39+
if: github.event_name == 'push' # only format on push events (not PRs from forks)
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Set up Go
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version: '1.24.4'
49+
50+
- name: Auto-format code with gofmt and commit changes
2951
run: |
30-
UNFORMATTED=$(gofmt -l .)
31-
if [ -n "$UNFORMATTED" ]; then
32-
echo "The following files need to be formatted:"
33-
echo "$UNFORMATTED"
34-
exit 1
52+
gofmt -w .
53+
if [ -n "$(git status --porcelain)" ]; then
54+
echo "Code was not formatted. Applying gofmt and committing changes..."
55+
git config user.name "github-actions"
56+
git config user.email "github-actions@github.com"
57+
git add .
58+
git commit -m "chore: auto-format Go code via gofmt"
59+
git push
60+
else
61+
echo "Code already properly formatted."
3562
fi

0 commit comments

Comments
 (0)