Skip to content

Commit b70ab12

Browse files
authored
Merge pull request #15 from vvoland/ci
Add GHA lint
2 parents aac757c + 5c75067 commit b70ab12

5 files changed

Lines changed: 86 additions & 30 deletions

File tree

.github/workflows/ci.yml

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
77

88
jobs:
@@ -11,33 +11,41 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v6
14-
14+
1515
- name: Set up Go
1616
uses: actions/setup-go@v6
1717
with:
1818
go-version: '1.25.5'
1919
cache-dependency-path: go.sum
20-
20+
2121
- name: Run tests with coverage
2222
run: go test -coverprofile=coverage.out -covermode=atomic ./...
23-
23+
2424
- name: Generate coverage summary
2525
run: |
26-
echo "## Test Coverage Report" >> $GITHUB_STEP_SUMMARY
27-
echo "" >> $GITHUB_STEP_SUMMARY
28-
26+
{
27+
echo "## Test Coverage Report"
28+
echo ""
29+
} >> "$GITHUB_STEP_SUMMARY"
30+
2931
# Get overall coverage
30-
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}')
31-
echo "**Overall Coverage:** $COVERAGE" >> $GITHUB_STEP_SUMMARY
32-
echo "" >> $GITHUB_STEP_SUMMARY
33-
34-
# Add detailed coverage table
35-
echo "### Coverage by Package" >> $GITHUB_STEP_SUMMARY
36-
echo "" >> $GITHUB_STEP_SUMMARY
37-
echo "| Package | Coverage |" >> $GITHUB_STEP_SUMMARY
38-
echo "|---------|----------|" >> $GITHUB_STEP_SUMMARY
39-
go tool cover -func=coverage.out | grep -v "total:" | awk '{print "| " $1 " " $2 " | " $3 " |"}' >> $GITHUB_STEP_SUMMARY
40-
32+
COVERAGE=$(go tool cover -func=coverage.out | \
33+
grep total | \
34+
awk '{print $3}' \
35+
)
36+
{
37+
echo "**Overall Coverage:** $COVERAGE"
38+
echo ""
39+
40+
echo "### Coverage by Package"
41+
echo ""
42+
echo "| Package | Coverage |"
43+
echo "|---------|----------|"
44+
go tool cover -func=coverage.out | \
45+
grep -v "total:" | \
46+
awk '{print "| " $1 " " $2 " | " $3 " |"}'
47+
} >> "$GITHUB_STEP_SUMMARY"
48+
4149
- name: Upload coverage to artifacts
4250
uses: actions/upload-artifact@v6
4351
with:
@@ -49,13 +57,13 @@ jobs:
4957
runs-on: ubuntu-latest
5058
steps:
5159
- uses: actions/checkout@v6
52-
60+
5361
- name: Set up Go
5462
uses: actions/setup-go@v6
5563
with:
5664
go-version: '1.25.5'
5765
cache-dependency-path: go.sum
58-
66+
5967
- name: Run go vet
6068
run: go vet ./...
6169

@@ -64,18 +72,18 @@ jobs:
6472
runs-on: ubuntu-latest
6573
steps:
6674
- uses: actions/checkout@v6
67-
75+
6876
- name: Set up Go
6977
uses: actions/setup-go@v6
7078
with:
7179
go-version: '1.25.5'
7280
cache-dependency-path: go.sum
73-
81+
7482
- name: Install golangci-lint
7583
uses: golangci/golangci-lint-action@v9
7684
with:
7785
version: v2.7.2
78-
86+
7987
- name: Run golangci-lint
8088
run: golangci-lint run ./...
8189

@@ -84,26 +92,29 @@ jobs:
8492
runs-on: ubuntu-latest
8593
steps:
8694
- uses: actions/checkout@v6
87-
95+
8896
- name: Set up Go
8997
uses: actions/setup-go@v6
9098
with:
9199
go-version: '1.25.5'
92100
cache-dependency-path: go.sum
93-
101+
94102
- name: Run go mod tidy
95103
run: go mod tidy
96-
104+
97105
- name: Check for changes
98106
run: |
99-
git diff --exit-code go.mod go.sum || (echo "go.mod or go.sum has uncommitted changes after 'go mod tidy'" && exit 1)
107+
git diff --exit-code go.mod go.sum || (
108+
echo "go.mod or go.sum has uncommitted changes after 'go mod tidy'"
109+
exit 1
110+
)
100111
101112
build:
102113
name: Build Binary
103114
runs-on: ubuntu-latest
104115
steps:
105116
- uses: actions/checkout@v6
106-
117+
107118
- name: Build binary target
108119
run: |
109120
docker buildx build . \
@@ -129,4 +140,3 @@ jobs:
129140
exit 1
130141
fi
131142
echo "✅ CI passed"
132-

.github/workflows/lint.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Lint
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
lint:
7+
name: Lint GHA
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v6
11+
- run: make -f lint.Makefile lint

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
--set "*.platform=linux/${{ matrix.arch }}" \
4242
--set "*.cache-from=type=gha,scope=${NAME}" \
4343
--set "*.cache-to=type=gha,mode=max,scope=${NAME}"
44-
mv ./build/linkwinbt ./build/${NAME}
44+
mv ./build/linkwinbt "./build/${NAME}"
4545
set -x
4646
for file in ./build/*.json; do
4747
mv "$file" "./build/${NAME}.$(basename "$file")"

.yamllint.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rules:
2+
truthy:
3+
check-keys: false

lint.Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
VERSION_YAMLLINT := 1.37.1
2+
VERSION_ACTIONLINT := 1.7.9
3+
4+
RUN := docker run --network none --security-opt no-new-privileges -u 1000:1000 --rm -w /work
5+
6+
COLOR_INFO := \033[1;34m
7+
COLOR_RESET := \033[0m
8+
9+
.PHONY: lint
10+
lint: lint-yaml
11+
12+
.PHONY: lint-yaml
13+
lint-yaml: lint-yaml-style lint-yaml-gha
14+
15+
.PHONY: lint-yaml-style
16+
lint-yaml-style:
17+
@printf "$(COLOR_INFO)> %s$(COLOR_RESET)\n" "Linting yaml files"
18+
$(RUN) \
19+
-v "./.github/workflows:/work/.github/workflows:ro" \
20+
-v "./.yamllint.yaml:/work/.yamllint.yaml" \
21+
giantswarm/yamllint:$(VERSION_YAMLLINT) \
22+
-f $(if $(GITHUB_WORKFLOW),github,colored) \
23+
.github/workflows
24+
25+
.PHONY: lint-yaml-gha
26+
lint-yaml-gha:
27+
@printf "$(COLOR_INFO)> %s$(COLOR_RESET)\n" "Linting GHA yaml files"
28+
$(RUN) \
29+
-v "./.yamllint.yml:/work/.yamllint.yml:ro" \
30+
-v "./.github:/work/.github:ro" \
31+
-v "./.git:/work/.git:ro" \
32+
rhysd/actionlint:$(VERSION_ACTIONLINT) -color

0 commit comments

Comments
 (0)