-
Notifications
You must be signed in to change notification settings - Fork 308
53 lines (48 loc) · 1.4 KB
/
linter.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: Lint
on:
push:
branches:
- master
pull_request:
jobs:
py-black:
name: Python Formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
go-fmt:
name: Go Formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Read go version
id: go_version
run: |
# Read the variable from the file
GO_VERSION=$(grep '^go ' go.mod | awk '{print $2}')
# Set the variable as an output
echo "GO_VERSION=$GO_VERSION" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ steps.go_version.outputs.GO_VERSION }}
- name: Run go fmt
run: |
NON_COMPLIANT_FILES=$(gofmt -s -l $(find . -type f -name '*.go'| grep -v "/.template/"))
if [ -n "$NON_COMPLIANT_FILES" ]; then
echo "The following files are not formatted correctly:"
echo "$NON_COMPLIANT_FILES"
mkdir -p /tmp/gofmt
for file in $NON_COMPLIANT_FILES; do
mkdir -p /tmp/gofmt/$(dirname $file)
gofmt -s $file > /tmp/gofmt/$file
done
exit 1
fi
- name: Upload formatted files
if: failure()
uses: actions/upload-artifact@v4
with:
name: formatted-files
path: /tmp/gofmt