Skip to content

Commit 7f5c26d

Browse files
ekarlsozawachteekarlso
authored
Add and fix golangci issues (#41)
* Add GoLangCI and fix issues * fix tests * Fix release * Add needed cp label --------- Co-authored-by: zawachte <[email protected]> Co-authored-by: ekarlso <[email protected]>
1 parent 7dc6848 commit 7f5c26d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1327
-1923
lines changed

.github/workflows/pr.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Pull Request Validation
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
workflow_dispatch:
6+
7+
env:
8+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9+
10+
jobs:
11+
validate:
12+
name: "Validate ${{ matrix.target }}"
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
target: ["lint", "test-bootstrap", "test-controlplane"]
18+
19+
steps:
20+
- name: checkout
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
25+
- uses: actions/setup-go@v4
26+
with:
27+
go-version-file: "./go.mod"
28+
29+
- name: ${{ matrix.target }}
30+
run: make ${{ matrix.target }}

.github/workflows/release.yaml

+120-22
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,140 @@
1+
# workflow to release assets as part of the release
2+
name: Upload Release Asset
13
on:
24
push:
3-
# Sequence of patterns matched against refs/tags
45
tags:
5-
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
6-
7-
name: release
6+
- "v*"
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
GO_VERSION: '1.20'
811

912
jobs:
10-
build:
11-
name: tag release
13+
image:
14+
name: Build and push ${{ matrix.target }} image
1215
runs-on: ubuntu-latest
13-
steps:
14-
- name: Set env
15-
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
16+
strategy:
17+
matrix:
18+
target: [bootsrap, controlplane]
1619

17-
- name: checkout code
20+
steps:
21+
- name: Checkout code
1822
uses: actions/checkout@v3
23+
24+
- uses: actions/setup-go@v4
1925
with:
20-
fetch-depth: 0
26+
go-version: "${{ env.GO_VERSION }}"
27+
cache: true
28+
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v2
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v2
34+
35+
- name: Cache Docker layers
36+
uses: actions/cache@v3
37+
with:
38+
path: /tmp/.buildx-cache
39+
key: ${{ runner.os }}-buildx-${{ matrix.target }}-${{ github.sha }}
40+
restore-keys: |
41+
${{ runner.os }}-buildx-${{ matrix.target }}-
42+
${{ runner.os }}-buildx-
43+
44+
- name: Docker ${{ matrix.target }} metadata
45+
id: meta
46+
uses: docker/metadata-action@v4
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
images: ${{ env.REGISTRY }}/${{ matrix.target }}-${{ env.IMAGE_NAME }}
50+
flavor: latest=false
51+
tags: type=ref,event=tag
52+
53+
- name: Log in to the Container registry
54+
uses: docker/login-action@v2
55+
with:
56+
registry: ${{ env.REGISTRY }}
57+
username: ${{ github.actor }}
58+
password: ${{ secrets.GITHUB_TOKEN }}
59+
60+
- name: Setup Env
61+
run: |
62+
DOCKER_BUILD_LDFLAGS="$(hack/version.sh)"
63+
echo 'DOCKER_BUILD_LDFLAGS<<EOF' >> $GITHUB_ENV
64+
echo $DOCKER_BUILD_LDFLAGS >> $GITHUB_ENV
65+
echo 'EOF' >> $GITHUB_ENV
2166
22-
- name: Install go
23-
uses: actions/setup-go@v4.0.1
67+
- name: Build and push ${{ matrix.target }} image
68+
uses: docker/build-push-action@v4
2469
with:
25-
go-version: "^1.20"
70+
context: .
71+
push: true
72+
build-args: |
73+
LDFLAGS=${{ env.DOCKER_BUILD_LDFLAGS }}
74+
tags: ${{ steps.meta.outputs.tags }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
platforms: linux/amd64,linux/arm64
77+
cache-from: type=local,src=/tmp/.buildx-cache
78+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
2679

27-
- name: generate release artifacts
80+
- name: Move cache
81+
# Temp fix
82+
# https://github.com/docker/build-push-action/issues/252
83+
# https://github.com/moby/buildkit/issues/1896
2884
run: |
29-
make release
85+
rm -rf /tmp/.buildx-cache
86+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
87+
88+
release:
89+
name: Release
90+
runs-on: ubuntu-latest
91+
needs:
92+
- image
93+
steps:
94+
- uses: actions/checkout@v3
95+
96+
- uses: ./.github/actions/setup-go
97+
98+
- uses: actions/cache@v3
99+
with:
100+
path: hack/tools/bin
101+
key: ${{ runner.os }}-tools-bin-release-${{ hashFiles('Makefile') }}
102+
restore-keys: |
103+
${{ runner.os }}-tools-bin-release-
104+
${{ runner.os }}-tools-bin-
30105
31-
- name: generate release notes
106+
- name: Docker ${{ matrix.target }} metadata
107+
id: meta
108+
uses: docker/metadata-action@v4
109+
with:
110+
github-token: ${{ secrets.GITHUB_TOKEN }}
111+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
112+
flavor: latest=false
113+
tags: type=ref,event=tag
114+
115+
- name: manifest
116+
run: make release-${{ matrix.target }}
117+
env:
118+
TAG: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
119+
120+
- name: Generate Release Notes
32121
run: |
33-
make release-notes
122+
release_notes=$(gh api repos/{owner}/{repo}/releases/generate-notes -F tag_name=${{ github.ref }} --jq .body)
123+
echo 'RELEASE_NOTES<<EOF' >> $GITHUB_ENV
124+
echo "${release_notes}" >> $GITHUB_ENV
125+
echo 'EOF' >> $GITHUB_ENV
34126
env:
35127
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128+
OWNER: ${{ github.repository_owner }}
129+
REPO: ${{ github.event.repository.name }}
36130

37-
- name: Release
131+
- name: Create Release
132+
id: create_release
38133
uses: softprops/action-gh-release@v1
134+
env:
135+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39136
with:
40-
draft: true
41-
files: out/*
42-
body_path: _releasenotes/release-notes-${{ env.RELEASE_TAG }}.md
137+
files: out/release/*
138+
body: ${{ env.RELEASE_NOTES }}
139+
draft: false
140+
prerelease: false

.golangci.yml

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
run:
2+
skip-files:
3+
- ".*zz_generated.*\\.go"
4+
- "contrib/.*"
5+
timeout: 5m
6+
issue:
7+
max-same-issues: 0
8+
max-per-linter: 0
9+
issues:
10+
exclude-rules:
11+
- path: "test/e2e/*"
12+
linters:
13+
- gosec
14+
text: "G106:"
15+
- linters:
16+
- revive
17+
text: "dot-imports"
18+
path: ".*test.*"
19+
- linters:
20+
- stylecheck
21+
text: "ST1001"
22+
path: ".*test.*"
23+
24+
linters:
25+
fast: true
26+
disable-all: true
27+
enable:
28+
- asciicheck
29+
- bodyclose
30+
- depguard
31+
- dogsled
32+
- errcheck
33+
- exportloopref
34+
- gci
35+
- goconst
36+
- gocritic
37+
- gocyclo
38+
- godot
39+
- gofmt
40+
- goimports
41+
- goprintffuncname
42+
- gosec
43+
- gosimple
44+
- govet
45+
- importas
46+
- ineffassign
47+
- misspell
48+
- nakedret
49+
- nilerr
50+
- noctx
51+
- nolintlint
52+
- prealloc
53+
- predeclared
54+
- revive
55+
- rowserrcheck
56+
- staticcheck
57+
- stylecheck
58+
- thelper
59+
- typecheck
60+
- unconvert
61+
- unparam
62+
- unused
63+
- whitespace
64+
65+
linters-settings:
66+
depguard:
67+
rules:
68+
main:
69+
allow:
70+
- $gostd
71+
- github.com/go-logr/logr
72+
- github.com/coredns/corefile-migration/migration
73+
74+
- k8s.io/api
75+
- k8s.io/apimachinery/pkg
76+
- k8s.io/apiserver
77+
- k8s.io/client-go
78+
- k8s.io/klog/v2/klogr
79+
- k8s.io/utils/pointer
80+
81+
- github.com/onsi/ginkgo
82+
- github.com/onsi/gomega
83+
84+
- sigs.k8s.io/yaml
85+
- sigs.k8s.io/controller-runtime
86+
- sigs.k8s.io/cluster-api
87+
88+
- github.com/cluster-api-provider-k3s/cluster-api-k3s
89+
gci:
90+
sections:
91+
- standard
92+
- default
93+
- prefix(github.com/cluster-api-provider-k3s/cluster-api-k3s)
94+
gomoddirectives:
95+
# List of allowed `replace` directives.
96+
# Default: []
97+
replace-allow-list:
98+
- sigs.k8s.io/cluster-api
99+
goimports:
100+
# put imports beginning with prefix after 3rd-party packages;
101+
# it's a comma-separated list of prefixes
102+
local-prefixes: github.com/cluster-api-provider-k3s/cluster-api-k3s
103+
godot:
104+
# declarations - for top level declaration comments (default);
105+
# toplevel - for top level comments;
106+
# all - for all comments.
107+
scope: toplevel
108+
exclude:
109+
- '^ \+.*'
110+
- '^ ANCHOR.*'
111+
gosec:
112+
excludes:
113+
- G307 # Deferring unsafe method "Close" on type "\*os.File"
114+
- G108 # Profiling endpoint is automatically exposed on /debug/pprof
115+
importas:
116+
# Do not allow unaliased imports of aliased packages.
117+
# Default: false
118+
no-unaliased: true
119+
alias:
120+
# Kubernetes
121+
- pkg: k8s.io/api/core/v1
122+
alias: corev1
123+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
124+
alias: apiextensionsv1
125+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
126+
alias: metav1
127+
- pkg: k8s.io/apimachinery/pkg/api/errors
128+
alias: apierrors
129+
- pkg: k8s.io/apimachinery/pkg/util/errors
130+
alias: kerrors
131+
# Controller Runtime
132+
- pkg: sigs.k8s.io/controller-runtime
133+
alias: ctrl
134+
nolintlint:
135+
# Enable to require nolint directives to mention the specific linter being suppressed.
136+
# Default: false
137+
require-specific: true
138+
revive:
139+
rules:
140+
- name: exported
141+
arguments:
142+
- disableStutteringCheck
143+
- name: unused-parameter
144+
disabled: true
145+
staticcheck:
146+
go: "1.20"
147+
stylecheck:
148+
go: "1.20"
149+
tagliatelle:
150+
case:
151+
rules:
152+
# Any struct tag type can be used.
153+
# Support string case: `camel`, `pascal`, `kebab`, `snake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`, `header`
154+
json: goCamel
155+
unused:
156+
go: "1.20"

0 commit comments

Comments
 (0)