Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User subcommand #289

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 74 additions & 14 deletions .github/workflows/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- "v*.*.*"
pull_request:
paths-ignore:
- '*.md'
- 'assets/**'
- "*.md"
- "assets/**"

jobs:
lint:
Expand All @@ -22,19 +22,53 @@ jobs:
- name: Dagger Version
uses: sagikazarmark/[email protected]

- name: Generate Document
uses: dagger/dagger-for-github@v7
with:
version: ${{ steps.dagger_version.outputs.version }}
verb: call
args: run-doc export --path=doc

- name: Check for changes
run: |
# 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 "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
echo "No untracked files found."
fi
continue-on-error: false

- name: Run Dagger golangci-lint
uses: dagger/dagger-for-github@v7
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 @@ -49,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/[email protected]
with:
fromJSONFile: TestReport.json

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

push-latest-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
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Print GitHub ref for debugging
run: |
echo "GitHub ref: $GITHUB_REF"

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

- name: Publish and Sign Snapshot Image
if: github.event_name == 'push' && (github.ref == 'refs/heads/main')
uses: ./.github/actions/publish-and-sign
with:
IMAGE_TAGS: latest
Expand All @@ -82,9 +127,7 @@ jobs:
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }}


publish-release:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
needs:
- lint
- test-code
Expand All @@ -93,12 +136,30 @@ jobs:
packages: write
id-token: write
runs-on: ubuntu-latest
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/'))
steps:
- name: Print GitHub ref for debugging
run: |
echo "GitHub ref: $GITHUB_REF"

- name: Push images
if: github.event_name == 'push' && (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' && (startsWith(github.ref, 'refs/tags/'))
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create Release
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/'))
uses: dagger/dagger-for-github@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -108,12 +169,11 @@ jobs:
args: "release --github-token=env:GITHUB_TOKEN"

- name: Publish and Sign Tagged Image
if: success()
if: github.event_name == 'push' && (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 }}

27 changes: 27 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
run:
timeout: 3m
linters-settings:
gofmt:
# Simplify code: gofmt with `-s` option.
# Default: true
simplify: false
misspell:
locale: US,UK
stylecheck:
checks: [
"ST1019", # Importing the same package multiple times.
]
goheader:
template-path: copyright.tmpl

linters:
enable:
# Default linters are already enabled, these are the additional ones
- gosimple
- typecheck
- gofmt
- goimports
- gosec
- nilnil
- unused
- errcheck
- staticcheck
- dupl
- goheader
- misspell
- ineffassign
- whitespace
- bodyclose
- govet
- stylecheck
# - wrapcheck
# - gocritic
# - revive #, enable once current issues are resolved
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ dagger call build-dev --platform darwin/arm64 export --path=./harbor-cli
If golang is installed in your system, you can also build the project using the following commands:

```bash
git clone https://github.com/goharbor/harbor-cli.git
git clone https://github.com/goharbor/harbor-cli.git && cd harbor-cli
go build -o harbor-cli cmd/harbor/main.go
```

Expand Down
79 changes: 79 additions & 0 deletions changes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
diff --git a/.golangci.yaml b/.golangci.yaml
index b9a4d4f27..fb281a936 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -1,12 +1,32 @@
run:
timeout: 3m
+linters-settings:
+ gofmt:
+ # Simplify code: gofmt with `-s` option.
+ # Default: true
+ simplify: false
+ misspell:
+ locale: US,UK
+ stylecheck:
+ checks: [
+ "ST1019", # Importing the same package multiple times.
+ ]
+ goheader:
+ template-path: copyright.tmpl
+
linters:
enable:
# Default linters are already enabled, these are the additional ones
+ - gosimple
- typecheck
- gofmt
+ - goimports
- gosec
- nilnil
+ - unused
+ - errcheck
+ - staticcheck
+ - dupl
# - wrapcheck
# - gocritic
# - revive #, enable once current issues are resolved
diff --git a/pkg/views/artifact/list/view.go b/pkg/views/artifact/list/view.go
index 3b851aeeb..62901de74 100644
--- a/pkg/views/artifact/list/view.go
+++ b/pkg/views/artifact/list/view.go
@@ -2,13 +2,14 @@ package list

import (
"fmt"
+ "os"
+ "strconv"
+
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/goharbor/harbor-cli/pkg/views/base/tablelist"
- "os"
- "strconv"
)

var columns = []table.Column{
diff --git a/pkg/views/artifact/view/view.go b/pkg/views/artifact/view/view.go
index 0ab46ae7f..13288d17b 100644
--- a/pkg/views/artifact/view/view.go
+++ b/pkg/views/artifact/view/view.go
@@ -2,13 +2,14 @@ package view

import (
"fmt"
+ "os"
+ "strconv"
+
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/goharbor/harbor-cli/pkg/views/base/tablelist"
- "os"
- "strconv"
)

var columns = []table.Column{
32 changes: 32 additions & 0 deletions cli-docs/harbor-artifact-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: harbor artifact delete
weight: 15
---
## harbor artifact delete

### Description

##### delete an artifact

```sh
harbor artifact delete [flags]
```

### Options

```sh
-h, --help help for delete
```

### Options inherited from parent commands

```sh
-c, --config string config file (default is $HOME/.config/harbor-cli/config.yaml)
-o, --output-format string Output format. One of: json|yaml
-v, --verbose verbose output
```

### SEE ALSO

* [harbor artifact](harbor-artifact.md) - Manage artifacts

36 changes: 36 additions & 0 deletions cli-docs/harbor-artifact-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: harbor artifact list
weight: 80
---
## harbor artifact list

### Description

##### list artifacts within a repository

```sh
harbor artifact list [flags]
```

### Options

```sh
-h, --help help for list
-p, --page int Page number (default 1)
-n, --page-size int Size of per page (default 10)
-q, --query string Query string to query resources
-s, --sort string Sort the resource list in ascending or descending order
```

### Options inherited from parent commands

```sh
-c, --config string config file (default is $HOME/.config/harbor-cli/config.yaml)
-o, --output-format string Output format. One of: json|yaml
-v, --verbose verbose output
```

### SEE ALSO

* [harbor artifact](harbor-artifact.md) - Manage artifacts

Loading