Skip to content

Commit 21545e6

Browse files
committed
ci: Style checks automation
1 parent 7dbbc99 commit 21545e6

20 files changed

Lines changed: 216 additions & 175 deletions

.devcontainer/devcontainer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"ENV": "dev"
1010
},
1111
"postCreateCommand": "cd ${containerWorkspaceFolder}; /usr/bin/env sh .devcontainer/postCreateCommand.sh",
12-
"features": {},
12+
"features": {
13+
// TODO add docker and docker-compose
14+
// TODO add yamllint
15+
},
1316
"customizations": {
1417
"vscode": {
1518
"settings": {
@@ -24,4 +27,4 @@
2427
}
2528
},
2629
"remoteUser": "vscode"
27-
}
30+
}

.github/workflows/code-check.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Check Code
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
env:
12+
GO_VERSION: 1.23
13+
14+
jobs:
15+
super-lint:
16+
runs-on: ubuntu-latest
17+
if: false
18+
permissions:
19+
contents: read
20+
packages: read
21+
statuses: write
22+
steps:
23+
- uses: actions/checkout@v5
24+
with:
25+
fetch-depth: 0
26+
persist-credentials: false
27+
- uses: super-linter/super-linter@v8
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
lint-golang:
31+
runs-on: ubuntu-latest
32+
timeout-minutes: 10
33+
permissions:
34+
contents: read
35+
steps:
36+
- uses: actions/checkout@v5
37+
- uses: actions/setup-go@v6
38+
with:
39+
go-version: ${{ env.GO_VERSION }}
40+
- uses: golangci/golangci-lint-action@v8
41+
with:
42+
version: v2.1
43+
lint-markdown:
44+
runs-on: ubuntu-latest
45+
timeout-minutes: 10
46+
permissions:
47+
contents: read
48+
steps:
49+
- uses: actions/checkout@v5
50+
- uses: DavidAnson/markdownlint-cli2-action@v20
51+
with:
52+
globs: '**/*.md'
53+
lint-yaml:
54+
runs-on: ubuntu-latest # comes with yamllint pre-installed
55+
timeout-minutes: 10
56+
permissions:
57+
contents: read
58+
steps:
59+
- uses: actions/checkout@v5
60+
- run: yamllint -f github .

.github/workflows/draft-release.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: Create Release Draft
22
run-name: Draft Release ${{ inputs.version || github.ref_name }}
33

4-
on:
4+
on:
55
push:
66
tags:
7-
- "v*"
7+
- "v*"
88
workflow_dispatch:
99
inputs:
1010
version:
@@ -21,7 +21,7 @@ jobs:
2121
steps:
2222
- uses: actions/setup-node@v5
2323
with:
24-
node-version: '24' # github-script@v8 uses node 24
24+
node-version: '24' # github-script@v8 uses node 24
2525
- run: npm install semver
2626
- uses: actions/github-script@v8
2727
id: script
@@ -40,9 +40,13 @@ jobs:
4040
owner: context.repo.owner,
4141
repo: context.repo.repo,
4242
});
43-
data.forEach(({ name, tag_name }) => name !== tag_name && core.warning(`Release name and tag mismatch: ${name} != ${tag_name}`))
43+
data.forEach(
44+
({ name: n, tag_name: t }) => n !== t && core.warning(`Release name and tag mismatch: ${n} != ${t}`)
45+
)
4446
// TODO check if version is greater than latest release
45-
const releases = data.reduce((acc, { id, name, draft }) => Object.assign(acc, { [name.replace(/^v/, '')]: { id, name, draft } }), {});
47+
const releases = data.reduce((acc, { id, name, draft }) => Object.assign(acc, {
48+
[name.replace(/^v/, '')]: { id, name, draft }
49+
}), {});
4650
if (releases[version]) {
4751
if (!releases[version].draft) {
4852
return core.setFailed(`Release ${version} already exists and is published`);
@@ -80,7 +84,9 @@ jobs:
8084
prerelease: false,
8185
}
8286
if (process.env.RELEASE_ID) {
83-
await github.rest.repos.updateRelease(Object.assign(releaseInfo, { release_id: parseInt(process.env.RELEASE_ID, 10) }));
87+
await github.rest.repos.updateRelease(Object.assign(releaseInfo, {
88+
release_id: parseInt(process.env.RELEASE_ID, 10)
89+
}));
8490
core.notice(`Updated existing draft release ${process.env.VERSION}`);
8591
return;
8692
}

.github/workflows/release-artifacts.yml

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ run-name: Build Release ${{ github.ref_name }}
33

44
on:
55
release:
6-
types:
6+
types:
77
- published
88

99
env:
@@ -26,49 +26,49 @@ jobs:
2626
attestations: write
2727

2828
steps:
29-
- name: Checkout repository
30-
uses: actions/checkout@v5
29+
- name: Checkout repository
30+
uses: actions/checkout@v5
3131

32-
- name: Set up Docker Buildx
33-
uses: docker/setup-buildx-action@v3
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
3434

35-
- name: Log in to container registry
36-
uses: docker/login-action@v3
37-
with:
38-
registry: ${{ env.REGISTRY }}
39-
username: ${{ github.actor }}
40-
password: ${{ secrets.GITHUB_TOKEN }}
35+
- name: Log in to container registry
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ${{ env.REGISTRY }}
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
4141

42-
- name: Extract metadata
43-
id: meta
44-
uses: docker/metadata-action@v5
45-
with:
46-
images: ${{ env.IMAGE_NAME }}
47-
tags: |
48-
type=ref,event=tag
49-
type=semver,pattern=v{{version}}
50-
type=semver,pattern=v{{major}}.{{minor}}
51-
type=semver,pattern=v{{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
52-
type=raw,value=latest,enable={{is_default_branch}}
42+
- name: Extract metadata
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ env.IMAGE_NAME }}
47+
tags: |
48+
type=ref,event=tag
49+
type=semver,pattern=v{{version}}
50+
type=semver,pattern=v{{major}}.{{minor}}
51+
type=semver,pattern=v{{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
52+
type=raw,value=latest,enable={{is_default_branch}}
5353
54-
- name: Build and push Docker image
55-
uses: docker/build-push-action@v6
56-
id: build
57-
with:
58-
context: .
59-
platforms: ${{ env.PLATFORMS }}
60-
push: true
61-
sbom: true
62-
provenance: mode=max
63-
tags: ${{ steps.meta.outputs.tags }}
64-
labels: ${{ steps.meta.outputs.labels }}
65-
cache-from: type=gha
66-
cache-to: type=gha,mode=max
54+
- name: Build and push Docker image
55+
uses: docker/build-push-action@v6
56+
id: build
57+
with:
58+
context: .
59+
platforms: ${{ env.PLATFORMS }}
60+
push: true
61+
sbom: true
62+
provenance: mode=max
63+
tags: ${{ steps.meta.outputs.tags }}
64+
labels: ${{ steps.meta.outputs.labels }}
65+
cache-from: type=gha
66+
cache-to: type=gha,mode=max
6767

68-
- name: Generate artifact attestation
69-
uses: actions/attest-build-provenance@v3
70-
with:
71-
subject-name: ${{ env.IMAGE_NAME}}
72-
subject-digest: ${{ steps.build.outputs.digest }}
73-
# [ ] enable when requested, otherwise github packages UI shows broken example
74-
# push-to-registry: true
68+
- name: Generate artifact attestation
69+
uses: actions/attest-build-provenance@v3
70+
with:
71+
subject-name: ${{ env.IMAGE_NAME}}
72+
subject-digest: ${{ steps.build.outputs.digest }}
73+
# [ ] enable when requested, otherwise github packages UI shows broken example
74+
# push-to-registry: true

.github/workflows/semver-release.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Tag New Release
22

3-
on:
3+
on:
44
workflow_dispatch:
55
inputs:
66
# optional, will be determined from git history if not provided
@@ -57,7 +57,8 @@ jobs:
5757
repo: context.repo.repo,
5858
});
5959
if (latest && !gt(VERSION, latest.replace(/^v/, ''))) {
60-
return core.setFailed(`Version ${VERSION} is not greater than latest release ${latest}`);
60+
core.setFailed(`Version ${VERSION} is not greater than latest release ${latest}`);
61+
return;
6162
}
6263
core.notice(`Releasing version ${VERSION}`);
6364
return VERSION
@@ -85,7 +86,9 @@ jobs:
8586
if (sectionHeaderRE(sectionLevel, VERSION).test(content)) {
8687
return core.setFailed(`CHANGELOG.md already contains section for version ${VERSION}`);
8788
}
88-
const unreleasedSection = content.split(unreleasedHeaderRE)[unreleasedHeaderValue.length].split(sectionHeaderRE(sectionLevel))[0];
89+
const unreleasedSection = content
90+
.split(unreleasedHeaderRE)[unreleasedHeaderValue.length]
91+
.split(sectionHeaderRE(sectionLevel))[0];
8992
if (!unreleasedSection.replace(/\s+/g, '')) {
9093
return core.setFailed('[Unreleased] section is empty, nothing to release');
9194
}
@@ -116,7 +119,7 @@ jobs:
116119
runs-on: ubuntu-latest
117120
permissions:
118121
contents: write
119-
needs:
122+
needs:
120123
- version
121124
- release-notes
122125
env:
@@ -152,11 +155,11 @@ jobs:
152155
- uses: actions/github-script@v8
153156
with:
154157
script: |
155-
const { REF, VERSION: version } = process.env;
158+
const { REF, VERSION: version } = process.env;
156159
github.rest.actions.createWorkflowDispatch({
157160
owner: context.repo.owner,
158161
repo: context.repo.repo,
159162
ref: REF,
160163
workflow_id: 'draft-release.yml',
161164
inputs: { version }
162-
})
165+
})

.golangci.yml

Lines changed: 5 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,22 @@
11
version: "2"
22

3-
# options for analysis running
43
run:
5-
# default concurrency is a available CPU number
64
concurrency: 4
7-
8-
# timeout for analysis, e.g. 30s, 5m, default is 1m
9-
timeout: 3m
10-
11-
# exit code when at least one issue was found, default is 1
5+
timeout: 5m
6+
relative-path-mode: gomod
127
issues-exit-code: 1
13-
14-
# include test files or not, default is true
158
tests: true
16-
17-
# skip-dirs:
18-
# - src/external_libs
19-
# - autogenerated_by_my_lib
20-
21-
# default is true. Enables skipping of directories:
22-
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
23-
skip-dirs-use-default: true
24-
25-
# skip-files:
26-
# - ".*\\.my\\.go$"
27-
# - lib/bad.go
28-
29-
# Allow multiple parallel golangci-lint instances running.
30-
# If false (default) - golangci-lint acquires file lock on start.
31-
allow-parallel-runners: false
32-
33-
# output configuration options
9+
allow-parallel-runners: true
3410
output:
35-
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
36-
# default is "colored-line-number"
37-
format: colored-line-number
38-
39-
# print lines of code with issue, default is true
40-
print-issued-lines: true
41-
42-
# print linter name in the end of issue text, default is true
43-
print-linter-name: true
44-
45-
# make issues output unique by line, default is true
46-
uniq-by-line: true
47-
48-
# add a prefix to the output file references; default is no prefix
4911
path-prefix: ''
5012

51-
# sorts results by: filepath, line and column
52-
sort-results: false
53-
5413
linters:
55-
disable-all: true
56-
# https://golangci-lint.run/usage/linters/
57-
enable:
58-
- errcheck
59-
- gocyclo
60-
- gofmt
61-
- gosimple
62-
- govet
63-
- lll
64-
- staticcheck
65-
- stylecheck
66-
- typecheck
67-
- unused
68-
- nilerr # finds code which returns nil even though it checks that error is not nil.
69-
- whitespace # to remove extra whitespace or new line
70-
- testpackage # to use a separate `_test` package.
71-
- godot # to add period after comment ends.
72-
enable-all: false
73-
fast: false
14+
default: standard
7415

7516
issues:
76-
# Excluding configuration per-path, per-linter, per-text and per-source
77-
exclude-rules:
78-
# Exclude some linters from running on tests files.
79-
- path: _test\.go
80-
linters:
81-
- errcheck
82-
- path: pkg
83-
linters:
84-
- wrapcheck
85-
# Exclude some staticcheck messages
86-
- linters:
87-
- staticcheck
88-
text: 'SA9003:'
89-
90-
- linters:
91-
- stylecheck
92-
text: 'ST1000:|ST1003:'
93-
94-
exclude-use-default: false
95-
96-
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
9717
max-issues-per-linter: 0
98-
99-
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
10018
max-same-issues: 0
101-
102-
# Fix found issues (if it is supported by the linter)
10319
fix: false
10420

10521
severity:
106-
default-severity: error
107-
case-sensitive: false
22+
default: error

.markdownlint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MD013:
2+
line_length: 100

0 commit comments

Comments
 (0)