Skip to content

Commit 7f43940

Browse files
authored
Configure Linter & Improve Workflow (goharbor#294)
* configure linter Signed-off-by: bupd <[email protected]> * fix lint whitespace Signed-off-by: bupd <[email protected]> * update Signed-off-by: bupd <[email protected]> * add headers Signed-off-by: bupd <[email protected]> * update workflow Signed-off-by: bupd <[email protected]> * fix workflow Signed-off-by: bupd <[email protected]> * add debug in workflow Signed-off-by: bupd <[email protected]> * check lint Signed-off-by: bupd <[email protected]> * update actions summary Signed-off-by: bupd <[email protected]> * fix action Signed-off-by: bupd <[email protected]> * lint format github actions Signed-off-by: bupd <[email protected]> * stop upload result to github Signed-off-by: bupd <[email protected]> * upload lint report as html Signed-off-by: bupd <[email protected]> * check if html works Signed-off-by: bupd <[email protected]> * remove reviewdog and report in github actions format Signed-off-by: bupd <[email protected]> * fail lint Signed-off-by: bupd <[email protected]> * fix lint Signed-off-by: bupd <[email protected]> * fix lint Signed-off-by: bupd <[email protected]> --------- Signed-off-by: bupd <[email protected]>
1 parent 8dd8abb commit 7f43940

Some content is hidden

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

104 files changed

+1480
-134
lines changed

.github/workflows/default.yaml

+106-71
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ jobs:
3131

3232
- name: Check for changes
3333
run: |
34-
# Check if any untracked files exist
34+
# Check if any newly added docs exist
3535
untracked_files=$(git ls-files --others --exclude-standard)
3636
3737
# If there are untracked files, fail the workflow
3838
if [ -n "$untracked_files" ]; then
39-
echo "Untracked files found:"
39+
echo "New Untracked files found"
40+
echo "please check if docs were added for new commands"
4041
echo "$untracked_files"
4142
exit 1 # This will fail the workflow
4243
else
@@ -49,14 +50,25 @@ jobs:
4950
with:
5051
version: ${{ steps.dagger_version.outputs.version }}
5152
verb: call
52-
args: lint-report export --path=golangci-lint-report.sarif
53+
args: lint-report export --path=golangci-lint.report
5354

54-
- uses: reviewdog/action-setup@v1
55-
- name: Run Reviewdog
56-
env:
57-
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
- name: Generate lint summary
5856
run: |
59-
reviewdog -f=sarif -name="Golang Linter Report" -reporter=github-check -filter-mode nofilter -fail-level any -tee < golangci-lint-report.sarif
57+
echo "<h2> 📝 Lint results</h2>" >> $GITHUB_STEP_SUMMARY
58+
cat golangci-lint.report >> $GITHUB_STEP_SUMMARY
59+
# Check if the lint report contains any content (error or issues)
60+
if [ -s golangci-lint.report ]; then
61+
# If the file contains content, output an error message and exit with code 1
62+
echo "⚠️ Linting issues found!" >> $GITHUB_STEP_SUMMARY
63+
exit 1
64+
fi
65+
66+
# - uses: reviewdog/action-setup@v1
67+
# - name: Run Reviewdog
68+
# env:
69+
# REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
# run: |
71+
# reviewdog -f=sarif -name="Golang Linter Report" -reporter=github-check -filter-mode nofilter -fail-level any -tee < golangci-lint-report.sarif
6072

6173
test-code:
6274
runs-on: ubuntu-latest
@@ -71,7 +83,12 @@ jobs:
7183
with:
7284
version: ${{ steps.dagger_version.outputs.version }}
7385
verb: call
74-
args: test
86+
args: test-report export --path=TestReport.json
87+
88+
- name: Summarize Tests
89+
uses: robherley/[email protected]
90+
with:
91+
fromJSONFile: TestReport.json
7592

7693
- name: Build Binary
7794
uses: dagger/dagger-for-github@v7
@@ -81,67 +98,85 @@ jobs:
8198
args: build-dev --platform linux/amd64 export --path=./harbor-dev
8299

83100
push-latest-images:
84-
- name: Print GitHub ref for debugging
85-
run: echo "GitHub ref: $GITHUB_REF"
86-
87-
- name: Push images
88-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
89-
needs:
90-
- lint
91-
- test-code
92-
permissions:
93-
contents: read
94-
id-token: write
95-
runs-on: ubuntu-latest
96-
steps:
97-
- name: Checkout repo
98-
uses: actions/checkout@v4
99-
with:
100-
fetch-depth: 0
101-
102-
- name: Publish and Sign Snapshot Image
103-
uses: ./.github/actions/publish-and-sign
104-
with:
105-
IMAGE_TAGS: latest
106-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107-
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
108-
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
109-
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}
101+
needs:
102+
- lint
103+
- test-code
104+
permissions:
105+
contents: read
106+
id-token: write
107+
runs-on: ubuntu-latest
108+
steps:
109+
- name: Print GitHub ref for debugging
110+
run: |
111+
echo "GitHub ref: $GITHUB_REF"
112+
113+
- name: Push images
114+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
115+
run: |
116+
echo "Pushing images..."
117+
118+
- name: Checkout repo
119+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
120+
uses: actions/checkout@v4
121+
with:
122+
fetch-depth: 0
123+
124+
- name: Publish and Sign Snapshot Image
125+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
126+
uses: ./.github/actions/publish-and-sign
127+
with:
128+
IMAGE_TAGS: latest
129+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130+
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
131+
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
132+
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}
110133

111134
publish-release:
112-
- name: Print GitHub ref for debugging
113-
run: echo "GitHub ref: $GITHUB_REF"
114-
115-
- name: Push images
116-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
117-
needs:
118-
- lint
119-
- test-code
120-
permissions:
121-
contents: write
122-
packages: write
123-
id-token: write
124-
runs-on: ubuntu-latest
125-
steps:
126-
- name: Checkout repo
127-
uses: actions/checkout@v4
128-
with:
129-
fetch-depth: 0
130-
- name: Create Release
131-
uses: dagger/dagger-for-github@v7
132-
env:
133-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134-
with:
135-
version: "latest"
136-
verb: call
137-
args: "release --github-token=env:GITHUB_TOKEN"
138-
139-
- name: Publish and Sign Tagged Image
140-
if: success()
141-
uses: ./.github/actions/publish-and-sign
142-
with:
143-
IMAGE_TAGS: "latest, ${{ github.ref_name }}"
144-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
145-
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
146-
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
147-
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}
135+
needs:
136+
- lint
137+
- test-code
138+
permissions:
139+
contents: write
140+
packages: write
141+
id-token: write
142+
runs-on: ubuntu-latest
143+
steps:
144+
- name: Print GitHub ref for debugging
145+
run: |
146+
echo "GitHub ref: $GITHUB_REF"
147+
148+
- name: Push images
149+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
150+
uses: ./.github/actions/publish-and-sign
151+
with:
152+
IMAGE_TAGS: latest, ${{ github.ref_name }}
153+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
154+
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
155+
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
156+
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}
157+
158+
- name: Checkout repo
159+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
160+
uses: actions/checkout@v4
161+
with:
162+
fetch-depth: 0
163+
164+
- name: Create Release
165+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
166+
uses: dagger/dagger-for-github@v7
167+
env:
168+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
169+
with:
170+
version: "latest"
171+
verb: call
172+
args: "release --github-token=env:GITHUB_TOKEN"
173+
174+
- name: Publish and Sign Tagged Image
175+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
176+
uses: ./.github/actions/publish-and-sign
177+
with:
178+
IMAGE_TAGS: "latest, ${{ github.ref_name }}"
179+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
180+
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
181+
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
182+
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}

.golangci.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ linters:
2727
- errcheck
2828
- staticcheck
2929
- dupl
30+
- goheader
31+
- misspell
32+
- ineffassign
33+
- whitespace
34+
- bodyclose
35+
- govet
36+
- stylecheck
3037
# - wrapcheck
3138
# - gocritic
3239
# - revive #, enable once current issues are resolved

cmd/harbor/internal/version/version.go

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
114
package version
215

316
import "runtime/debug"

cmd/harbor/main.go

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
114
package main
215

316
import (

cmd/harbor/root/artifact/cmd.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
114
package artifact
215

316
import (
417
"github.com/spf13/cobra"
518
)
619

720
func Artifact() *cobra.Command {
8-
921
cmd := &cobra.Command{
1022
Use: "artifact",
1123
Short: "Manage artifacts",

cmd/harbor/root/artifact/delete.go

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
114
package artifact
215

316
import (

cmd/harbor/root/artifact/list.go

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
114
package artifact
215

316
import (

cmd/harbor/root/artifact/scan.go

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
114
package artifact
215

316
import (

cmd/harbor/root/artifact/tags.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
114
package artifact
215

316
import (
@@ -92,7 +105,6 @@ func ListTagsCmd() *cobra.Command {
92105
} else {
93106
list.ListTags(tags.Payload)
94107
}
95-
96108
},
97109
}
98110

cmd/harbor/root/artifact/view.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
114
package artifact
215

316
import (
@@ -12,7 +25,6 @@ import (
1225
)
1326

1427
func ViewArtifactCommmand() *cobra.Command {
15-
1628
cmd := &cobra.Command{
1729
Use: "view",
1830
Short: "Get information of an artifact",
@@ -48,7 +60,6 @@ func ViewArtifactCommmand() *cobra.Command {
4860
} else {
4961
view.ViewArtifact(artifact.Payload)
5062
}
51-
5263
},
5364
}
5465

0 commit comments

Comments
 (0)