Skip to content

Commit c730863

Browse files
chore(go-ci): create pipeline
1 parent 63d1843 commit c730863

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

.github/workflows/go-ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Go CI Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
jobs:
13+
go-ci:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: Set up Go environment
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: "1.18"
24+
25+
- name: Install golangci-lint
26+
run: |
27+
curl -sSf https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.46.2
28+
29+
- name: Run gofmt, golangci-lint, and staticcheck
30+
run: |
31+
chmod +x ./scripts/lint-go.sh
32+
./scripts/lint-go.sh
33+
34+
- name: Commit and push fixes
35+
run: |
36+
# Check if there are any changes after gofmt or golangci-lint
37+
git diff --exit-code || (
38+
echo "There are changes, committing the fixes..." &&
39+
git config user.name "github-actions" &&
40+
git config user.email "github-actions@github.com" &&
41+
git add . &&
42+
git commit -m "Apply gofmt and golangci-lint fixes" &&
43+
git push
44+
)

scripts/lint-go.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Run gofmt to see if there are any formatting changes to be made
4+
if [ $(gofmt -s -l . | wc -l) -gt 0 ]; then
5+
echo "Running gofmt to fix the code..."
6+
gofmt -s -w .
7+
else
8+
echo "The code is already properly formatted with gofmt."
9+
fi
10+
11+
# Run golangci-lint to fix any issues automatically where applicable
12+
echo "Running golangci-lint to apply automatic fixes..."
13+
golangci-lint run --fix
14+
15+
# Now run staticcheck to analyze the code
16+
echo "Running staticcheck..."
17+
staticcheck ./...

0 commit comments

Comments
 (0)