Skip to content

Commit

Permalink
Add MAN PAGES Documentation script (goharbor#75)
Browse files Browse the repository at this point in the history
* add: auto man documentation generate scripts

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

add: auto documentation generate scripts

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

* remove md_doc generation & add man docs

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

* update dagger for generating man pages

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

* update github workflow

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

* update man doc generation

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

* add cli and man docs

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

* update workflow

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

* move man pages to man1

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

---------

Signed-off-by: bupd <bupdprasanth@gmail.com>
  • Loading branch information
bupd authored Dec 30, 2024
1 parent 8a7a5a6 commit e23da81
Show file tree
Hide file tree
Showing 68 changed files with 2,900 additions and 141 deletions.
136 changes: 82 additions & 54 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,6 +22,28 @@ jobs:
- name: Dagger Version
uses: sagikazarmark/dagger-version-action@v0.0.1

- 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 untracked files 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 "$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:
Expand Down Expand Up @@ -59,61 +81,67 @@ 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
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Print GitHub ref for debugging
run: echo "GitHub ref: $GITHUB_REF"

- 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 }}
- 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 }}

publish-release:
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: Print GitHub ref for debugging
run: echo "GitHub ref: $GITHUB_REF"

- 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 }}
- 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 }}
20 changes: 20 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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
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{
2 changes: 1 addition & 1 deletion cmd/harbor/root/registry/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func UpdateRegistryCommand() *cobra.Command {
flags.BoolVarP(&opts.Insecure, "insecure", "i", false, "Whether or not the certificate will be verified when Harbor tries to access the server")
flags.StringVarP(&opts.Credential.AccessKey, "credential-access-key", "k", "", "Access key, e.g. user name when credential type is 'basic'")
flags.StringVarP(&opts.Credential.AccessSecret, "credential-access-secret", "s", "", "Access secret, e.g. password when credential type is 'basic'")
flags.StringVarP(&opts.Credential.Type, "credential-type", "c", "", "Credential type, such as 'basic', 'oauth'")
flags.StringVarP(&opts.Credential.Type, "credential-type", "", "", "Credential type, such as 'basic', 'oauth'")

return cmd
}
4 changes: 2 additions & 2 deletions dagger.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "harbor-cli",
"engineVersion": "v0.14.0",
"sdk": "go",
"dependencies": [
{
Expand All @@ -8,6 +9,5 @@
"pin": "8359122a7b90f2c8c6f3165570fdcbec6e923023"
}
],
"source": "dagger",
"engineVersion": "v0.14.0"
"source": "dagger"
}
22 changes: 11 additions & 11 deletions dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ func (m *HarborCli) BuildDev(
ctx context.Context,
platform string,
) *dagger.File {

fmt.Println("🛠️ Building Harbor-Cli with Dagger...")
// Define the path for the binary output
os, arch, err := parsePlatform(platform)

if err != nil {
log.Fatalf("Error parsing platform: %v", err)
}
Expand Down Expand Up @@ -97,9 +95,11 @@ func (m *HarborCli) build(
// LintReport Executes the Linter and writes the linting results to a file golangci-lint-report.sarif
func (m *HarborCli) LintReport(ctx context.Context) *dagger.File {
report := "golangci-lint-report.sarif"
return m.lint(ctx).WithExec([]string{"golangci-lint", "run",
return m.lint(ctx).WithExec([]string{
"golangci-lint", "run",
"--out-format", "sarif:" + report,
"--issues-exit-code", "0"}).File(report)
"--issues-exit-code", "1",
}).File(report)
}

// Lint Run the linter golangci-lint
Expand All @@ -125,7 +125,8 @@ func (m *HarborCli) PublishImage(
// +optional
// +default=["latest"]
imageTags []string,
registryPassword *dagger.Secret) []string {
registryPassword *dagger.Secret,
) []string {
builders := m.build(ctx)
releaseImages := []*dagger.Container{}

Expand Down Expand Up @@ -159,7 +160,6 @@ func (m *HarborCli) PublishImage(
fmt.Sprintf("%s/%s/harbor-cli:%s", registry, "harbor-cli", imageTag),
dagger.ContainerPublishOpts{PlatformVariants: releaseImages},
)

if err != nil {
panic(err)
}
Expand Down Expand Up @@ -207,10 +207,9 @@ func (m *HarborCli) goreleaserContainer() *dagger.Container {
WithMountedDirectory("/src", m.Source).
WithWorkdir("/src").
WithEnvVariable("TINI_SUBREAPER", "true")

}

// RunDoc Generate CLI Documentation with doc.go and return the directory containing the generated files
// Generate CLI Documentation and return the directory containing the generated files
func (m *HarborCli) RunDoc(ctx context.Context) *dagger.Directory {
return dag.Container().
From("golang:"+GO_VERSION+"-alpine").
Expand All @@ -220,7 +219,8 @@ func (m *HarborCli) RunDoc(ctx context.Context) *dagger.Directory {
WithEnvVariable("GOCACHE", "/go/build-cache").
WithMountedDirectory("/src", m.Source).
WithWorkdir("/src/doc").
WithExec([]string{"go", "run", "doc.go"}).
WithExec([]string{"go", "run", "_doc.go"}).
WithExec([]string{"go", "run", "_man_doc.go"}).
WithWorkdir("/src").Directory("/src/doc")
}

Expand Down Expand Up @@ -261,7 +261,6 @@ func (m *HarborCli) PublishImageAndSign(
// +optional
actionsIdTokenRequestUrl string,
) (string, error) {

imageAddrs := m.PublishImage(ctx, registry, registryUsername, imageTags, registryPassword)
_, err := m.Sign(
ctx,
Expand Down Expand Up @@ -309,7 +308,8 @@ func (m *HarborCli) Sign(ctx context.Context,

return cosing_ctr.WithSecretVariable("REGISTRY_PASSWORD", registryPassword).
WithExec([]string{"cosign", "env"}).
WithExec([]string{"cosign", "sign", "--yes", "--recursive",
WithExec([]string{
"cosign", "sign", "--yes", "--recursive",
"--registry-username", registryUsername,
"--registry-password", registryPasswordPlain,
imageAddr,
Expand Down
File renamed without changes.
Loading

0 comments on commit e23da81

Please sign in to comment.