Skip to content

Commit

Permalink
Configure Linter & Improve Workflow (#294)
Browse files Browse the repository at this point in the history
* configure linter

Signed-off-by: bupd <bupdprasanth@gmail.com>

* fix lint whitespace

Signed-off-by: bupd <bupdprasanth@gmail.com>

* update

Signed-off-by: bupd <bupdprasanth@gmail.com>

* add headers

Signed-off-by: bupd <bupdprasanth@gmail.com>

* update workflow

Signed-off-by: bupd <bupdprasanth@gmail.com>

* fix workflow

Signed-off-by: bupd <bupdprasanth@gmail.com>

* add debug in workflow

Signed-off-by: bupd <bupdprasanth@gmail.com>

* check lint

Signed-off-by: bupd <bupdprasanth@gmail.com>

* update actions summary

Signed-off-by: bupd <bupdprasanth@gmail.com>

* fix action

Signed-off-by: bupd <bupdprasanth@gmail.com>

* lint format github actions

Signed-off-by: bupd <bupdprasanth@gmail.com>

* stop upload result to github

Signed-off-by: bupd <bupdprasanth@gmail.com>

* upload lint report as html

Signed-off-by: bupd <bupdprasanth@gmail.com>

* check if html works

Signed-off-by: bupd <bupdprasanth@gmail.com>

* remove reviewdog and report in github actions format

Signed-off-by: bupd <bupdprasanth@gmail.com>

* fail lint

Signed-off-by: bupd <bupdprasanth@gmail.com>

* fix lint

Signed-off-by: bupd <bupdprasanth@gmail.com>

* fix lint

Signed-off-by: bupd <bupdprasanth@gmail.com>

---------

Signed-off-by: bupd <bupdprasanth@gmail.com>
  • Loading branch information
bupd authored Jan 10, 2025
1 parent 8dd8abb commit 7f43940
Show file tree
Hide file tree
Showing 104 changed files with 1,480 additions and 134 deletions.
177 changes: 106 additions & 71 deletions .github/workflows/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ jobs:

- name: Check for changes
run: |
# Check if any untracked files exist
# Check if any newly added docs exist
untracked_files=$(git ls-files --others --exclude-standard)
# If there are untracked files, fail the workflow
if [ -n "$untracked_files" ]; then
echo "Untracked files found:"
echo "New Untracked files found"
echo "please check if docs were added for new commands"
echo "$untracked_files"
exit 1 # This will fail the workflow
else
Expand All @@ -49,14 +50,25 @@ jobs:
with:
version: ${{ steps.dagger_version.outputs.version }}
verb: call
args: lint-report export --path=golangci-lint-report.sarif
args: lint-report export --path=golangci-lint.report

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

test-code:
runs-on: ubuntu-latest
Expand All @@ -71,7 +83,12 @@ jobs:
with:
version: ${{ steps.dagger_version.outputs.version }}
verb: call
args: test
args: test-report export --path=TestReport.json

- name: Summarize Tests
uses: robherley/go-test-action@v0.6.0
with:
fromJSONFile: TestReport.json

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

push-latest-images:
- name: Print GitHub ref for debugging
run: echo "GitHub ref: $GITHUB_REF"

- name: Push images
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
needs:
- lint
- test-code
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Publish and Sign Snapshot Image
uses: ./.github/actions/publish-and-sign
with:
IMAGE_TAGS: latest
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}
needs:
- lint
- test-code
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Print GitHub ref for debugging
run: |
echo "GitHub ref: $GITHUB_REF"
- name: Push images
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
run: |
echo "Pushing images..."
- name: Checkout repo
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Publish and Sign Snapshot Image
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
uses: ./.github/actions/publish-and-sign
with:
IMAGE_TAGS: latest
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}

publish-release:
- name: Print GitHub ref for debugging
run: echo "GitHub ref: $GITHUB_REF"

- name: Push images
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
needs:
- lint
- test-code
permissions:
contents: write
packages: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create Release
uses: dagger/dagger-for-github@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: "latest"
verb: call
args: "release --github-token=env:GITHUB_TOKEN"

- name: Publish and Sign Tagged Image
if: success()
uses: ./.github/actions/publish-and-sign
with:
IMAGE_TAGS: "latest, ${{ github.ref_name }}"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}
needs:
- lint
- test-code
permissions:
contents: write
packages: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Print GitHub ref for debugging
run: |
echo "GitHub ref: $GITHUB_REF"
- name: Push images
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
uses: ./.github/actions/publish-and-sign
with:
IMAGE_TAGS: latest, ${{ github.ref_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}

- name: Checkout repo
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create Release
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
uses: dagger/dagger-for-github@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: "latest"
verb: call
args: "release --github-token=env:GITHUB_TOKEN"

- name: Publish and Sign Tagged Image
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
uses: ./.github/actions/publish-and-sign
with:
IMAGE_TAGS: "latest, ${{ github.ref_name }}"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ linters:
- errcheck
- staticcheck
- dupl
- goheader
- misspell
- ineffassign
- whitespace
- bodyclose
- govet
- stylecheck
# - wrapcheck
# - gocritic
# - revive #, enable once current issues are resolved
Expand Down
13 changes: 13 additions & 0 deletions cmd/harbor/internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package version

import "runtime/debug"
Expand Down
13 changes: 13 additions & 0 deletions cmd/harbor/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main

import (
Expand Down
14 changes: 13 additions & 1 deletion cmd/harbor/root/artifact/cmd.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package artifact

import (
"github.com/spf13/cobra"
)

func Artifact() *cobra.Command {

cmd := &cobra.Command{
Use: "artifact",
Short: "Manage artifacts",
Expand Down
13 changes: 13 additions & 0 deletions cmd/harbor/root/artifact/delete.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package artifact

import (
Expand Down
13 changes: 13 additions & 0 deletions cmd/harbor/root/artifact/list.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package artifact

import (
Expand Down
13 changes: 13 additions & 0 deletions cmd/harbor/root/artifact/scan.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package artifact

import (
Expand Down
14 changes: 13 additions & 1 deletion cmd/harbor/root/artifact/tags.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package artifact

import (
Expand Down Expand Up @@ -92,7 +105,6 @@ func ListTagsCmd() *cobra.Command {
} else {
list.ListTags(tags.Payload)
}

},
}

Expand Down
15 changes: 13 additions & 2 deletions cmd/harbor/root/artifact/view.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package artifact

import (
Expand All @@ -12,7 +25,6 @@ import (
)

func ViewArtifactCommmand() *cobra.Command {

cmd := &cobra.Command{
Use: "view",
Short: "Get information of an artifact",
Expand Down Expand Up @@ -48,7 +60,6 @@ func ViewArtifactCommmand() *cobra.Command {
} else {
view.ViewArtifact(artifact.Payload)
}

},
}

Expand Down
Loading

0 comments on commit 7f43940

Please sign in to comment.